Skip to content

Commit b38e7e4

Browse files
committed
CorefMention(words=[w1,w2]) should create backlinks from w1 and w2
The only case when we don't want these backlinks is "fake mentions" needed for serialization of discontinuous mentions, but that should be solved with a special parameter in `__init__`. Fixes #101
1 parent 81a65bf commit b38e7e4

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

udapi/core/coref.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,23 @@ class CorefMention(object):
109109
"""Class for representing a mention (instance of an entity)."""
110110
__slots__ = ['_head', '_cluster', '_bridging', '_words', '_other']
111111

112-
def __init__(self, words, head=None, cluster=None):
112+
def __init__(self, words, head=None, cluster=None, add_word_backlinks=True):
113113
if not words:
114114
raise ValueError("mention.words must be non-empty")
115-
self._words = words
116115
self._head = head if head else words[0]
117116
self._cluster = cluster
118117
if cluster is not None:
119118
cluster._mentions.append(self)
120119
self._bridging = None
121120
self._other = None
121+
self._words = words
122+
if add_word_backlinks:
123+
for new_word in words:
124+
if not new_word._mentions or not cluster or self > new_word._mentions[-1]:
125+
new_word._mentions.append(self)
126+
else:
127+
new_word._mentions.append(self)
128+
new_word._mentions.sort()
122129

123130
def __lt__(self, another):
124131
"""Does this mention precedes (word-order wise) `another` mention?
@@ -692,7 +699,7 @@ def store_coref_to_misc(doc):
692699
subspan_eid = f'{cluster.cluster_id}[{idx}/{len(subspans)}]'
693700
subspan_words = span_to_nodes(root, subspan)
694701
fake_cluster = CorefCluster(subspan_eid, cluster.cluster_type)
695-
fake_mention = CorefMention(subspan_words, head_str, fake_cluster)
702+
fake_mention = CorefMention(subspan_words, head_str, fake_cluster, add_word_backlinks=False)
696703
if mention._other:
697704
fake_mention._other = mention._other
698705
if mention._bridging and idx == 1:

0 commit comments

Comments
 (0)