6
6
class MoveHead (Block ):
7
7
"""Block corefud.MoveHead moves the head to the highest node in each mention."""
8
8
9
- def __init__ (self , nontreelet = 'fix ' , ** kwargs ):
9
+ def __init__ (self , bugs = 'warn ' , ** kwargs ):
10
10
self .counter = Counter ()
11
- self .nontreelet = nontreelet
11
+ self .bugs = bugs
12
12
super ().__init__ (** kwargs )
13
13
14
14
def find_head (self , mention ):
@@ -19,25 +19,34 @@ def find_head(self, mention):
19
19
self .counter ['with_empty' ] += 1
20
20
for empty_node in empty_nodes :
21
21
parents = [d ['parent' ] for d in empty_node .deps if not d ['parent' ].is_empty ()]
22
- if parents and parents [0 ] not in non_empty :
23
- non_empty .append (parents [0 ])
22
+ if parents :
23
+ if parents [0 ] not in non_empty :
24
+ non_empty .append (parents [0 ])
24
25
else :
25
26
# TODO we should climb up, but preventing cycles
26
27
# We could also introduce empty_node.nonempty_ancestor
27
- logging .warning (f"could not find non-empty parent of { empty_node } for mention { mention .head } " )
28
+ if 'warn' in self .bugs :
29
+ logging .warning (f"could not find non-empty parent of { empty_node } for mention { mention .head } " )
30
+ if 'mark' in self .bugs :
31
+ node .misc ['Bug' ] = 'no-parent-of-empty'
28
32
non_empty .sort ()
29
33
30
34
(highest , added_nodes ) = find_minimal_common_treelet (* non_empty )
31
35
if highest in mention .words :
32
36
return highest , 'treelet'
33
37
34
- if 'warn' in self .nontreelet :
38
+ if 'warn' in self .bugs :
35
39
logging .warning (f"Non-treelet mention in { mention .head } (nearest common antecedent={ highest } )" )
36
- if 'mark' in self .nontreelet :
37
- node . misc ['Mark ' ] = 'non-treelet-mention'
40
+ if 'mark' in self .bugs :
41
+ mention . head . misc ['Bug ' ] = 'non-treelet-mention'
38
42
for word in mention .words :
39
43
if not word .is_empty () and word .parent not in non_empty :
40
44
return word , 'nontreelet'
45
+
46
+ if 'warn' in self .bugs :
47
+ logging .warning (f"Strange mention { mention .head } (nearest common antecedent={ highest } )" )
48
+ if 'mark' in self .bugs :
49
+ mention .head .misc ['Bug' ] = 'strange-mention'
41
50
return mention .head , 'bug'
42
51
43
52
def process_document (self , doc ):
0 commit comments