Skip to content

Commit 8472038

Browse files
committed
corefud.SingleParent: keep only the highest enhanced parent of empty nodes
for the purpose of training the predictor of zeros (by Milan Straka) for the CRAC24 shared task.
1 parent ea33c78 commit 8472038

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""If an empty node has multiple (enhanced-deps) parents, only the highest one is kept."""
2+
from udapi.core.block import Block
3+
from collections import Counter
4+
from udapi.core.node import find_minimal_common_treelet
5+
import logging
6+
7+
class SingleParent(Block):
8+
9+
def __init__(self, **kwargs):
10+
super().__init__(**kwargs)
11+
self._reasons = Counter()
12+
13+
def process_tree(self, tree):
14+
for empty in tree.empty_nodes:
15+
self._reasons['_empty'] += 1
16+
if len(empty.deps) > 1:
17+
self._reasons['_more-parents'] += 1
18+
parents = [d['parent'] for d in empty.deps]
19+
nonempty_parents = [p for p in parents if not p.is_empty()]
20+
if len(nonempty_parents) != len(parents):
21+
self._reasons['empty-parent'] += 1
22+
#empty.misc['Mark'] = f"empty-parent:{empty.deps}"
23+
logging.warning(f"Empty node {empty} has an empty parent.")
24+
if not nonempty_parents:
25+
empty.deps = []
26+
self._reasons['no-nonempty-parent'] += 1
27+
continue
28+
(highest, added_nodes) = find_minimal_common_treelet(*nonempty_parents)
29+
if highest in nonempty_parents:
30+
self._reasons['one-governs'] += 1
31+
empty.deps = [d for d in empty.deps if d['parent'] is highest]
32+
continue
33+
nonempty_parents.sort(key=lambda n:n._get_attr('depth'))
34+
if len(nonempty_parents)>1 and nonempty_parents[0]._get_attr('depth') == nonempty_parents[0]._get_attr('depth'):
35+
self._reasons['same-depth'] += 1
36+
#empty.misc['Mark'] = f"same-depth:{empty.deps}"
37+
else:
38+
self._reasons['one-highest'] += 1
39+
#empty.misc['Mark'] = f"one-highest:{empty.deps}"
40+
empty.deps = [d for d in empty.deps if d['parent'] is nonempty_parents[0]]
41+
42+
def after_process_document(self, document):
43+
message = "\n"
44+
for k, v in self._reasons.most_common():
45+
message += f"{k}={v}\n"
46+
#document.meta["bugs"] = message
47+
logging.info(message)

0 commit comments

Comments
 (0)