| 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 | |
| 197 | class TestStatistics(unittest.TestCase): |
| 198 | |