MCPcopy Index your code
hub / github.com/clips/pattern / test_match

Method test_match

test/test_search.py:216–247  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

214 print "pattern.search.Constraint.fromstring"
215
216 def test_match(self):
217 # Assert Constraint-Word matching.
218 R = search.Constraint.fromstring
219 S = lambda s: Sentence(parse(s, relations=True, lemmata=True))
220 W = lambda s, tag=None, index=0: search.Word(None, s, tag, index)
221 for constraint, tests in (
222 (R("cat|dog"), [(W("cat"), 1), (W("dog"), 1), (W("fish"), 0)]),
223 (R("cat*"), [(W("cats"), 1)]),
224 (R("*cat"), [(W("tomcat"), 1)]),
225 (R("c*t|d*g"), [(W("cat"), 1), (W("cut"), 1), (W("dog"), 1), (W("dig"), 1)]),
226 (R("cats|NN*"), [(W("cats", "NNS"), 1), (W("cats"), 0)]),
227 (R("^cat"), [(W("cat", "NN", index=0), 1),(W("cat", "NN", index=1), 0)]),
228 (R("*|!cat"), [(W("cat"), 0), (W("dog"), 1), (W("fish"), 1)]),
229 (R("my cat"), [(W("cat"), 0)]),
230 (R("my cat"), [(S("my cat").words[1], 1)]), # "my cat" is an overspecification of "cat"
231 (R("my_cat"), [(S("my cat").words[1], 1)]),
232 (R("cat|NP"), [(S("my cat").words[1], 1)]),
233 (R("dog|VP"), [(S("my dog").words[1], 0)]),
234 (R("cat|SBJ"), [(S("the cat is sleeping").words[1], 1)]),
235 (R("dog"), [(S("MY DOGS").words[1], 1)]), # lemma matches
236 (R("dog"), [(S("MY DOG").words[1], 1)])): # case-insensitive
237 for test, b in tests:
238 self.assertEqual(constraint.match(test), bool(b))
239 # Assert Constraint-Taxa matching.
240 t = search.Taxonomy()
241 t.append("Tweety", type="bird")
242 t.append("Steven", type="bird")
243 v = search.Constraint.fromstring("BIRD", taxonomy=t)
244 self.assertTrue(v.match(W("bird")))
245 self.assertTrue(v.match(S("tweeties")[0]))
246 self.assertTrue(v.match(W("Steven")))
247 print "pattern.search.Constraint.match()"
248
249 def test_string(self):
250 # Assert Constraint.string.

Callers

nothing calls this directly

Calls 5

appendMethod · 0.95
parseFunction · 0.90
SentenceClass · 0.50
matchMethod · 0.45
fromstringMethod · 0.45

Tested by

no test coverage detected