From 2c8b1246151e87eb10779d48499f9971d613eec8 Mon Sep 17 00:00:00 2001 From: aryeht Date: Fri, 12 May 2023 07:13:21 +0300 Subject: [PATCH 1/2] fixes --- pybart/converter.py | 2 +- pybart/graph_token.py | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pybart/converter.py b/pybart/converter.py index f21f588..7d46904 100644 --- a/pybart/converter.py +++ b/pybart/converter.py @@ -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( diff --git a/pybart/graph_token.py b/pybart/graph_token.py index 96df62e..41a4f8a 100644 --- a/pybart/graph_token.py +++ b/pybart/graph_token.py @@ -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): @@ -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()] @@ -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: @@ -113,7 +117,7 @@ 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]: @@ -121,14 +125,14 @@ def remove_edge(self, rel, head): 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') From 617c8f9deb52a752a466ae5023849b8cf0a349bb Mon Sep 17 00:00:00 2001 From: aryeht Date: Fri, 12 May 2023 07:13:43 +0300 Subject: [PATCH 2/2] update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6458b05..efeb043 100644 --- a/setup.py +++ b/setup.py @@ -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",