Skip to content

Commit aeb067c

Browse files
committed
corefud.Delete - delete coreference annotation and optionally also empty nodes
1 parent a43cd21 commit aeb067c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

udapi/block/corefud/delete.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Delete coreference annotation (Entity|Bridge|SplitAnte) and optionally also empty nodes."""
2+
3+
from udapi.core.block import Block
4+
import udapi.core.coref
5+
import logging
6+
7+
class Delete(Block):
8+
9+
def __init__(self, empty=False, **kwargs):
10+
super().__init__(**kwargs)
11+
self.empty = empty
12+
13+
def process_document(self, doc):
14+
# This block should work both with coreference loaded (deserialized) and not.
15+
doc._eid_to_entity = None
16+
for root in doc.trees:
17+
if self.empty:
18+
root.empty_nodes = []
19+
for node in root.descendants:
20+
if node.raw_deps != '_':
21+
node.raw_deps = '|'.join(d for d in node.raw_deps.split('|') if not '.' in d)
22+
if node.raw_deps == '':
23+
node.raw_deps = '0:root'
24+
if '.' in node.misc['Functor']:
25+
del node.misc['Functor']
26+
27+
for node in root.descendants + root.empty_nodes:
28+
node._mentions = []
29+
for attr in ('Entity', 'Bridge', 'SplitAnte'):
30+
del node.misc[attr]

0 commit comments

Comments
 (0)