@@ -9,7 +9,7 @@ class MarkDiff(Block):
99 """Mark differences between parallel trees."""
1010
1111 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 ):
1313 """Create the Mark block object.
1414 Params:
1515 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
2626 self .gold_zone = gold_zone
2727 self .attrs = attributes .split (',' )
2828 self .mark = mark
29+ self .mark_attr = mark_attr
2930 self .add = add
3031 self .print_stats = print_stats
3132 self .ignore_parent = ignore_parent
@@ -37,15 +38,15 @@ def process_tree(self, tree):
3738 return
3839 if not self .add :
3940 for node in tree .descendants + gold_tree .descendants :
40- del node .misc ['Mark' ]
41+ del node .misc [self . mark_attr ]
4142 del node .misc ['ToDo' ]
4243 del node .misc ['Bug' ]
4344
4445 pred_nodes , gold_nodes = tree .descendants , gold_tree .descendants
4546 # Make sure both pred and gold trees are marked, even if one has just deleted nodes.
4647 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 } ' )
4950 pred_tokens = ['_' .join (n .get_attrs (self .attrs )) for n in pred_nodes ]
5051 gold_tokens = ['_' .join (n .get_attrs (self .attrs )) for n in gold_nodes ]
5152 matcher = difflib .SequenceMatcher (None , pred_tokens , gold_tokens , autojunk = False )
@@ -63,12 +64,12 @@ def process_tree(self, tree):
6364 if edit == 'equal' :
6465 for p_node , g_node in zip (pred_nodes [pred_lo :pred_hi ], gold_nodes [gold_lo :gold_hi ]):
6566 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
6869 self .stats ['ONLY-PARENT-CHANGED' ] += 1
6970 else :
7071 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
7273 if self .print_stats :
7374 if edit == 'replace' :
7475 # first n nodes are treated as aligned, the rest is treated as ADDED/DELETED
0 commit comments