@@ -9,7 +9,7 @@ class MarkDiff(Block):
9
9
"""Mark differences between parallel trees."""
10
10
11
11
def __init__ (self , gold_zone , attributes = 'form,lemma,upos,xpos,deprel,feats,misc' ,
12
- mark = 1 , add = False , print_stats = 0 , ignore_parent = False , ** kwargs ):
12
+ mark = 1 , mark_attr = "Mark" , add = False , print_stats = 0 , ignore_parent = False , ** kwargs ):
13
13
"""Create the Mark block object.
14
14
Params:
15
15
gold_zone: Which of the zones should be treated as gold?
@@ -26,6 +26,7 @@ def __init__(self, gold_zone, attributes='form,lemma,upos,xpos,deprel,feats,misc
26
26
self .gold_zone = gold_zone
27
27
self .attrs = attributes .split (',' )
28
28
self .mark = mark
29
+ self .mark_attr = mark_attr
29
30
self .add = add
30
31
self .print_stats = print_stats
31
32
self .ignore_parent = ignore_parent
@@ -37,15 +38,15 @@ def process_tree(self, tree):
37
38
return
38
39
if not self .add :
39
40
for node in tree .descendants + gold_tree .descendants :
40
- del node .misc ['Mark' ]
41
+ del node .misc [self . mark_attr ]
41
42
del node .misc ['ToDo' ]
42
43
del node .misc ['Bug' ]
43
44
44
45
pred_nodes , gold_nodes = tree .descendants , gold_tree .descendants
45
46
# Make sure both pred and gold trees are marked, even if one has just deleted nodes.
46
47
if len (pred_nodes ) != len (gold_nodes ):
47
- tree .add_comment ('Mark = %s' % self .mark )
48
- gold_tree .add_comment ('Mark = %s' % self .mark )
48
+ tree .add_comment (f' { self . mark_attr } = { self .mark } ' )
49
+ gold_tree .add_comment (f' { self . mark_attr } = { self .mark } ' )
49
50
pred_tokens = ['_' .join (n .get_attrs (self .attrs )) for n in pred_nodes ]
50
51
gold_tokens = ['_' .join (n .get_attrs (self .attrs )) for n in gold_nodes ]
51
52
matcher = difflib .SequenceMatcher (None , pred_tokens , gold_tokens , autojunk = False )
@@ -63,12 +64,12 @@ def process_tree(self, tree):
63
64
if edit == 'equal' :
64
65
for p_node , g_node in zip (pred_nodes [pred_lo :pred_hi ], gold_nodes [gold_lo :gold_hi ]):
65
66
if not self .ignore_parent and alignment .get (p_node .parent .ord - 1 ) != g_node .parent .ord - 1 :
66
- p_node .misc ['Mark' ] = self .mark
67
- g_node .misc ['Mark' ] = self .mark
67
+ p_node .misc [self . mark_attr ] = self .mark
68
+ g_node .misc [self . mark_attr ] = self .mark
68
69
self .stats ['ONLY-PARENT-CHANGED' ] += 1
69
70
else :
70
71
for node in pred_nodes [pred_lo :pred_hi ] + gold_nodes [gold_lo :gold_hi ]:
71
- node .misc ['Mark' ] = self .mark
72
+ node .misc [self . mark_attr ] = self .mark
72
73
if self .print_stats :
73
74
if edit == 'replace' :
74
75
# first n nodes are treated as aligned, the rest is treated as ADDED/DELETED
0 commit comments