def test_find_wrong_pattern(self): with self.assertRaises(PatternSyntaxException): match_tree(_sentence, "*//[]")
def test_match_with_lists(self): self.assertTrue(match_tree(_sentence, "VBD/prep/IN/*/[NNP,DT]")) self.assertTrue(match_tree(_sentence, "VBD/prep/IN/[pobj,prep,*]/NNP"))
def test_not_match_with_lists(self): self.assertFalse(match_tree(_sentence, "VBD/prep/IN/pobj/[IN,DT]")) self.assertFalse(match_tree(_sentence, "VBD/**/IN/[pobj,prep]/DT"))
def test_not_match_pattern_with_stars(self): self.assertFalse(match_tree(_sentence, "VBD/*/DT/pobj/*")) self.assertFalse(match_tree(_sentence, "VBD/**/DT/pobj/*"))
def test_match_pattern_with_stars(self): self.assertTrue(match_tree(_sentence, "VBD/prep/IN/pobj/*")) self.assertTrue(match_tree(_sentence, "VBD/prep/*/pobj/NNP")) self.assertTrue(match_tree(_sentence, "VBD/**/DT")) self.assertTrue(match_tree(_sentence, "VBD/**/*"))
def test_not_match_simple_patterns(self): self.assertFalse(match_tree(_sentence, "VBD/prep/IN/pobj/VBD"))
def test_match_simple_patterns(self): self.assertTrue(match_tree(_sentence, "VBD/prep/IN/pobj/NNP"))
def process(self, context, passed_tokens=None): return \ find_tokens(context.current_sent(), self._pattern) \ if not self._precondition or match_tree(context.current_sent(), self._precondition) else []