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

Method test_parse

test/test_nl.py:188–218  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

186 print "pattern.nl.parser.find_lemmata()"
187
188 def test_parse(self):
189 # Assert parsed output with Penn Treebank II tags (slash-formatted).
190 # 1) "de zwarte kat" is a noun phrase, "op de mat" is a prepositional noun phrase.
191 v = nl.parser.parse("De zwarte kat zat op de mat.")
192 self.assertEqual(v,
193 "De/DT/B-NP/O zwarte/JJ/I-NP/O kat/NN/I-NP/O " + \
194 "zat/VBD/B-VP/O " + \
195 "op/IN/B-PP/B-PNP de/DT/B-NP/I-PNP mat/NN/I-NP/I-PNP ././O/O"
196 )
197 # 2) "jaagt" and "vogels" lemmata are "jagen" and "vogel".
198 v = nl.parser.parse("De zwarte kat jaagt op vogels.", lemmata=True)
199 self.assertEqual(v,
200 "De/DT/B-NP/O/de zwarte/JJ/I-NP/O/zwart kat/NN/I-NP/O/kat " + \
201 "jaagt/VBZ/B-VP/O/jagen " + \
202 "op/IN/B-PP/B-PNP/op vogels/NNS/B-NP/I-PNP/vogel ././O/O/."
203 )
204 # Assert the accuracy of the Dutch tagger.
205 i, n = 0, 0
206 for sentence in open(os.path.join(PATH, "corpora", "tagged-nl-twnc.txt")).readlines():
207 sentence = sentence.decode("utf-8").strip()
208 s1 = [w.split("/") for w in sentence.split(" ")]
209 s1 = [nl.wotan2penntreebank(w, tag) for w, tag in s1]
210 s2 = [[w for w, pos in s1]]
211 s2 = nl.parse(s2, tokenize=False)
212 s2 = [w.split("/") for w in s2.split(" ")]
213 for j in range(len(s1)):
214 if s1[j][1] == s2[j][1]:
215 i += 1
216 n += 1
217 self.assertTrue(float(i) / n > 0.90)
218 print "pattern.nl.parser.parse()"
219
220 def test_tag(self):
221 # Assert [("zwarte", "JJ"), ("panters", "NNS")].

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
stripMethod · 0.80
parseMethod · 0.45
decodeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected