Skip to content

Commit c8fbca0

Browse files
committed
add language param for AddCommas, add RemoveCommas
1 parent d536e6f commit c8fbca0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

udapi/block/tutorial/addcommas.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
"""tutorial.AddCommas block template."""
22
from udapi.core.block import Block
33

4+
# nickname = xy123
5+
# TODO: make up a unique nickname and edit the previous line
6+
# if you want your results to be listed on the NPFL070 web (under that nickname).
7+
# Delete the line if you don't want to listed on the web.
48

59
class AddCommas(Block):
610
"""Heuristically insert nodes for missing commas."""
711

12+
def __init__(self, language='en', **kwargs):
13+
"""Create the AddCommas block object.
14+
15+
Args:
16+
`language`: which language-specific rules to use ('en' or 'cs')
17+
"""
18+
super().__init__(**kwargs)
19+
self.language = language
20+
821
def process_node(self, node):
922
if self.should_add_comma_before(node):
1023
comma = node.create_child(form=',', deprel='punct', upos='PUNCT')
@@ -15,7 +28,7 @@ def should_add_comma_before(self, node):
1528
prev_node = node.prev_node
1629
if prev_node is None:
1730
return False
18-
if prev_node.lemma == 'however':
31+
if self.language == 'en' and node.lemma == 'however':
1932
return True
2033
if any(n.deprel == 'appos' for n in prev_node.children):
2134
return True
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""tutorial.RemoveCommas helper block."""
2+
from udapi.core.block import Block
3+
4+
5+
class RemoveCommas(Block):
6+
"""Delete all comma nodes and edit SpaceAfter and text accordingly."""
7+
8+
def process_tree(self, root):
9+
for node in root.descendants:
10+
if node.form == ",":
11+
node.remove(children="rehang")
12+
del node.prev_node.misc['SpaceAfter']
13+
root.text = root.compute_text()

0 commit comments

Comments
 (0)