Annotates the tokens with lemmata for plural nouns and conjugated verbs, where each token is a [word, part-of-speech] list.
(tokens)
| 109 | replacements.update(((k.upper(), v.upper()) for k, v in replacements.items())) |
| 110 | |
| 111 | def find_lemmata(tokens): |
| 112 | """ Annotates the tokens with lemmata for plural nouns and conjugated verbs, |
| 113 | where each token is a [word, part-of-speech] list. |
| 114 | """ |
| 115 | for token in tokens: |
| 116 | word, pos, lemma = token[0], token[1], token[0] |
| 117 | if pos.startswith(("DT", "PR", "WP")): |
| 118 | lemma = singularize(word, pos=pos) |
| 119 | if pos.startswith(("RB", "IN")) and (word.endswith(("'", u"’")) or word == "du"): |
| 120 | lemma = singularize(word, pos=pos) |
| 121 | if pos.startswith(("JJ",)): |
| 122 | lemma = predicative(word) |
| 123 | if pos == "NNS": |
| 124 | lemma = singularize(word) |
| 125 | if pos.startswith(("VB", "MD")): |
| 126 | lemma = conjugate(word, INFINITIVE) or word |
| 127 | token.append(lemma.lower()) |
| 128 | return tokens |
| 129 | |
| 130 | class Parser(_Parser): |
| 131 |
no test coverage detected
searching dependent graphs…