diff --git a/syntax_dag.py b/syntax_dag.py index 6586703..927b92a 100644 --- a/syntax_dag.py +++ b/syntax_dag.py @@ -118,7 +118,8 @@ class Encoder: or any(token.dep_ in {"neg", "aux", "conj"} for token in sentence) or not any(child.dep_ == "nsubj" for child in sentence.root.children) or not any(child.dep_ == "nsubj" for child in verb.children) - or {token.i for token in verb.subtree} != set(range(marker.i, end)) + or {token.i for token in verb.subtree if not token.is_punct} + != set(range(marker.i, end)) ): return None return marker, end diff --git a/test_syntax_dag.py b/test_syntax_dag.py index 499a8d5..38089c1 100644 --- a/test_syntax_dag.py +++ b/test_syntax_dag.py @@ -21,6 +21,10 @@ class SyntaxDAGTest(unittest.TestCase): def test_causal_commit(self): text = "The road flooded because it rained. They waited." graph = self.encoder.encode(text) + self.assertEqual(len(graph.proposals), 1, [ + (token.text, token.head.text, token.dep_, token.pos_, token.tag_) + for token in self.encoder.nlp(text) + ]) proposal, = graph.proposals self.assertTrue(any( len({edge.source for edge in graph.edges if edge.target == node}) > 1