Skip to content

Commit

Permalink
Merge pull request #62 from allenai/fix-61-again
Browse files Browse the repository at this point in the history
Fix 61 again
  • Loading branch information
aryehgigi authored May 12, 2023
2 parents f20f43a + 617c8f9 commit a4c6d66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pybart/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def extra_compound_propagation(sentence, matches, converter):
compound = cur_match.token("compound")
middle_man = cur_match.token("middle_man")
for rel in cur_match.edge(middle_man, gov):
sentence[compound].add_edge(Label(f"{rel}c", src="compound", src_type="NULL", uncertain=True), sentence[gov])
sentence[compound].add_edge(Label(rel, src="compound", src_type="NULL", uncertain=True), sentence[gov])

# here we add a subject relation for each amod relation (but in the opposite direction)
extra_amod_propagation_constraint = Full(
Expand Down
28 changes: 16 additions & 12 deletions pybart/graph_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def to_str(self, remove_enhanced_extra_info, remove_bart_extra_info):
dep_args = ", ".join(x for x in filter(None, [self.src_type, self.phrase, "UNC" if self.uncertain else None]))
bart = "@" + self.src + "(" + dep_args + ")" + iid_str

return self.base + eud + bart
# special cases for altering the base label
base = self.base
if self.src == "compound" and self.src_type == "NULL":
base += "c"
return base + eud + bart

# operator overloading: less than
def __lt__(self, other):
Expand All @@ -66,16 +70,16 @@ def copy(self, new_id=None, form=None, lemma=None, upos=None, xpos=None, feats=N
deprel if deprel else deprel_copy,
deps if deps else deps_copy,
misc if misc else misc_copy)

def add_child(self, child):
self._children_list.append(child)

def remove_child(self, child):
self._children_list.remove(child)

def get_children(self):
return self._children_list

def get_children_with_rels(self):
return [(child, list(child.get_new_relations(self))[0][1]) for child in self.get_children()]

Expand All @@ -85,16 +89,16 @@ def get_conllu_string(self, remove_enhanced_extra_info, remove_bart_extra_info):
sorted_ = sorted((h, sorted(rels)) for h, rels in self.get_new_relations())
self._conllu_info["deps"] = "|".join([str(a.get_conllu_field('id')) + ":" + bb.to_str(remove_enhanced_extra_info, remove_bart_extra_info) for (a, b) in sorted_ for bb in b])
return "\t".join([str(v) for v in self._conllu_info.values()])

def set_conllu_field(self, field, val):
self._conllu_info[field] = val

def get_conllu_field(self, field):
return self._conllu_info[field]

def get_parents(self):
return self._new_deps.keys()

def get_new_relations(self, given_head=None):
if given_head:
if given_head in self._new_deps:
Expand All @@ -113,22 +117,22 @@ def add_edge(self, rel, head):
else:
self._new_deps[head] = [rel]
head.add_child(self)

def remove_edge(self, rel, head):
assert isinstance(rel, Label)
if head in self._new_deps and rel in self._new_deps[head]:
self._new_deps[head].remove(rel)
if not self._new_deps[head]:
self._new_deps.pop(head)
head.remove_child(self)

def remove_all_edges(self):
_ = [self.remove_edge(edge, head) for head, edges in list(self.get_new_relations()) for edge in edges]

def replace_edge(self, old_rel, new_rel, old_head, new_head):
self.remove_edge(old_rel, old_head)
self.add_edge(new_rel, new_head)

# operator overloading: less than
def __lt__(self, other):
return self.get_conllu_field('id') < other.get_conllu_field('id')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pybart-nlp",
version="3.4.2",
version="3.4.3",
author="Aryeh Tiktinsky",
author_email="aryehgigi@gmail.com",
description="python converter from UD-tree to BART-graph representations",
Expand Down

0 comments on commit a4c6d66

Please sign in to comment.