(self)
| 448 | pass |
| 449 | |
| 450 | def test_match(self): |
| 451 | # Assert Match properties. |
| 452 | s = Sentence(parse("Death awaits you all with nasty, big, pointy teeth.")) |
| 453 | p = search.Pattern(sequence=[ |
| 454 | search.Constraint(tags=["JJ"], optional=True), |
| 455 | search.Constraint(tags=["NN*"])]) |
| 456 | m = p.search(s) |
| 457 | self.assertTrue(isinstance(m, list)) |
| 458 | self.assertEqual(m[0].pattern, p) |
| 459 | self.assertEqual(m[1].pattern, p) |
| 460 | self.assertEqual(m[0].words, [s.words[0]]) |
| 461 | self.assertEqual(m[1].words, [s.words[-3], s.words[-2]]) |
| 462 | # Assert contraint "NN*" links to "Death" and "teeth", and "JJ" to "pointy". |
| 463 | self.assertEqual(m[0].constraint(s.words[ 0]), p[1]) |
| 464 | self.assertEqual(m[1].constraint(s.words[-3]), p[0]) |
| 465 | self.assertEqual(m[1].constraint(s.words[-2]), p[1]) |
| 466 | # Assert constraints "JJ NN*" links to chunk "pointy teeth". |
| 467 | self.assertEqual(m[1].constraints(s.chunks[6]), [p[0], p[1]]) |
| 468 | # Assert Match.constituents() by constraint, constraint index and list of indices. |
| 469 | self.assertEqual(m[1].constituents(), [s.chunks[6]]) |
| 470 | self.assertEqual(m[1].constituents(constraint=p[0]), [s.words[-3]]) |
| 471 | self.assertEqual(m[1].constituents(constraint=1), [s.words[-2]]) |
| 472 | self.assertEqual(m[1].constituents(constraint=(0,1)), [s.chunks[6]]) |
| 473 | # Assert Match.string. |
| 474 | self.assertEqual(m[1].string, "pointy teeth") |
| 475 | print "pattern.search.Match" |
| 476 | |
| 477 | def test_group(self): |
| 478 | # Assert Match groups. |
nothing calls this directly
no test coverage detected