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

Method test_cooccurrence

test/test_metrics.py:182–195  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

180 print "pattern.metrics.isplit()"
181
182 def test_cooccurrence(self):
183 s = "The black cat sat on the mat."
184 v = metrics.cooccurrence(metrics.isplit(s), window=(-1,1),
185 match = lambda w: w in ("cat",),
186 normalize = lambda w: w.lower().strip(".:;,!?()[]'\""))
187 self.assertEqual(sorted(v.keys()), ["cat"])
188 self.assertEqual(sorted(v["cat"].keys()), ["black", "cat", "sat"])
189 self.assertEqual(sorted(v["cat"].values()), [1, 1, 1])
190 s = [("The","DT"), ("black","JJ"), ("cat","NN"), ("sat","VB"), ("on","IN"), ("the","DT"), ("mat","NN")]
191 v = metrics.co_occurrence(s, window=(-2,-1),
192 match = lambda token: token[1].startswith("NN"),
193 filter = lambda token: token[1].startswith("JJ"))
194 self.assertEqual(v, {("cat", "NN"): {("black", "JJ"): 1}})
195 print "pattern.metrics.cooccurrence()"
196
197class TestStatistics(unittest.TestCase):
198

Callers

nothing calls this directly

Calls 3

stripMethod · 0.80
keysMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected