Skip to content

Commit caf8fb9

Browse files
committed
util.Mark mark_attr
1 parent 732a885 commit caf8fb9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

udapi/block/util/mark.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Mark(Block):
1515
udapy -TM util.Mark node='node.is_nonprojective()' < in | less -R
1616
"""
1717

18-
def __init__(self, node, mark=1, add=True, **kwargs):
18+
def __init__(self, node, mark=1, mark_attr="Mark", add=True, print_stats=False, **kwargs):
1919
"""Create the Mark block object.
2020
2121
Args:
@@ -24,17 +24,27 @@ def __init__(self, node, mark=1, add=True, **kwargs):
2424
2525
`mark`: the node will be marked with `Mark=<mark>` in `node.misc`. Default=1.
2626
27+
`mark_attr`: use this MISC attribute name instead of "Mark".
28+
2729
`add`: should we keep existing Mark|ToDo|Bug? Default=True.
2830
"""
2931
super().__init__(**kwargs)
3032
self.mark = mark
33+
self.mark_attr = mark_attr
3134
self.node = node
3235
self.add = add
36+
self.print_stats = print_stats
37+
self._marked = 0
3338

3439
def process_node(self, node):
3540
if eval(self.node):
36-
node.misc['Mark'] = self.mark
41+
node.misc[self.mark_attr] = self.mark
42+
self._marked += 1
3743
elif not self.add:
38-
del node.misc['Mark']
44+
del node.misc[self.mark_attr]
3945
del node.misc['ToDo']
4046
del node.misc['Bug']
47+
48+
def process_end(self):
49+
if self.print_stats:
50+
print(f'util.Mark marked {self._marked} nodes')

udapi/block/util/markdiff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, gold_zone, attributes='form,lemma,upos,xpos,deprel,feats,misc
1717
attributes: Which node attributes should be considered when searching for diffs?
1818
The tree topology, i.e. node parent is always considered.
1919
mark: What value should be used in `node.misc['Mark']` of the differing nodes?
20+
mark_attr: use this MISC attribute name instead of "Mark".
2021
add: If False, node.misc attributes Mark, ToDo and Bug will be deleted before running this block,
2122
so that the marked_only option (e.g. via `udapy -TM`) prints only nodes marked by this block.
2223
print_stats: How many lines of statistics should be printed? -1 means all.

0 commit comments

Comments
 (0)