| 215 | print "pattern.it.parser.find_lemmata()" |
| 216 | |
| 217 | def test_parse(self): |
| 218 | # Assert parsed output with Penn Treebank II tags (slash-formatted). |
| 219 | # "il gatto nero" is a noun phrase, "sulla stuoia" is a prepositional noun phrase. |
| 220 | v = it.parser.parse(u"Il gatto nero seduto sulla stuoia.") |
| 221 | self.assertEqual(v, |
| 222 | u"Il/DT/B-NP/O gatto/NN/I-NP/O nero/JJ/I-NP/O " + |
| 223 | u"seduto/VB/B-VP/O " + \ |
| 224 | u"sulla/IN/B-PP/B-PNP stuoia/NN/B-NP/I-PNP ././O/O" |
| 225 | ) |
| 226 | |
| 227 | # Assert the accuracy of the Italian tagger. |
| 228 | i, n = 0, 0 |
| 229 | for sentence in open(os.path.join(PATH, "corpora", "tagged-it-wacky.txt")).readlines(): |
| 230 | sentence = sentence.decode("utf-8").strip() |
| 231 | s1 = [w.split("/") for w in sentence.split(" ")] |
| 232 | s2 = [[w for w, pos in s1]] |
| 233 | s2 = it.parse(s2, tokenize=False) |
| 234 | s2 = [w.split("/") for w in s2.split(" ")] |
| 235 | for j in range(len(s1)): |
| 236 | t1 = s1[j][1] |
| 237 | t2 = s2[j][1] |
| 238 | # WaCKy test set tags plural nouns as "NN", pattern.it as "NNS". |
| 239 | # Some punctuation marks are also tagged differently, |
| 240 | # but these are not necessarily errors. |
| 241 | if t1 == t2 or (t1 == "NN" and t2 == "NNS") or s1[j][0] in "\":;)-": |
| 242 | i += 1 |
| 243 | n += 1 |
| 244 | self.assertTrue(float(i) / n > 0.92) |
| 245 | print "pattern.it.parser.parse()" |
| 246 | |
| 247 | def test_tag(self): |
| 248 | # Assert [("il", "DT"), ("gatto", "NN"), ("nero", "JJ")]. |