def test_not_match_with_lists(self): self.assertListEqual([], [ x.orth_ for x in find_tokens(_sentence, "VBD/prep/IN/pobj/[IN,DT]") ]) self.assertListEqual([], [ x.orth_ for x in find_tokens(_sentence, "VBD/**/IN/[pobj,prep]/DT") ])
def test_match_with_lists(self): self.assertListEqual(["School"], [ x.orth_ for x in find_tokens(_sentence, "VBD/prep/IN/*/[NNP,DT]") ]) self.assertListEqual(["School"], [ x.orth_ for x in find_tokens(_sentence, "VBD/prep/IN/[pobj,prep,*]/NNP") ])
def test_find_pattern_with_stars(self): self.assertListEqual( ["School", "1980"], [x.orth_ for x in find_tokens(_sentence, "VBD/prep/IN/pobj/*")]) self.assertListEqual( ["School"], [x.orth_ for x in find_tokens(_sentence, "VBD/prep/*/pobj/NNP")]) self.assertListEqual( ["the", "the"], [x.orth_ for x in find_tokens(_sentence, "VBD/**/DT")]) self.assertListEqual([ "Robinson", "Mrs.", "from", "School", "the", "Wharton", "of", "University", "the", "of", "Pennsylvania", "in", "1980", "." ], [x.orth_ for x in find_tokens(_sentence, "VBD/**/*")])
def test_not_match_pattern_with_stars(self): self.assertListEqual( [], [x.orth_ for x in find_tokens(_sentence, "VBD/*/DT/pobj/*")]) self.assertListEqual( [], [x.orth_ for x in find_tokens(_sentence, "VBD/**/DT/pobj/*")])
def test_not_find_simple_patterns(self): self.assertListEqual( [], [x.orth_ for x in find_tokens(_sentence, "VBD/prep/IN/pobj/VBD")])
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 []