| 242 | print "pattern.vector.count()" |
| 243 | |
| 244 | def test_document(self): |
| 245 | # Assert Document properties. |
| 246 | # Test with different input types. |
| 247 | for constructor, w in ( |
| 248 | (vector.Document, "The cats sat on the mat."), |
| 249 | (vector.Document, ["The", "cats", "sat", "on", "the", "mat"]), |
| 250 | (vector.Document, {"cat":1, "sat":1, "mat":1}), |
| 251 | (vector.Document, Text(parse("The cats sat on the mat."))), |
| 252 | (vector.Document, Sentence(parse("The cats sat on the mat.")))): |
| 253 | # Test copy. |
| 254 | v = constructor(w, stemmer=vector.LEMMA, stopwords=False, name="Cat", type="CAT") |
| 255 | v = v.copy() |
| 256 | # Test properties. |
| 257 | self.assertEqual(v.name, "Cat") |
| 258 | self.assertEqual(v.type, "CAT") |
| 259 | self.assertEqual(v.count, 3) |
| 260 | self.assertEqual(v.terms, {"cat":1, "sat":1, "mat":1}) |
| 261 | # Test iterator decoration. |
| 262 | self.assertEqual(sorted(v.features), ["cat", "mat", "sat"]) |
| 263 | self.assertEqual(sorted(v), ["cat", "mat", "sat"]) |
| 264 | self.assertEqual(len(v), 3) |
| 265 | self.assertEqual(v["cat"], 1) |
| 266 | self.assertEqual("cat" in v, True) |
| 267 | print "pattern.vector.Document" |
| 268 | |
| 269 | def test_document_load(self): |
| 270 | # Assert save + load document integrity. |