Annotates the tokens with lemmata for plural nouns and conjugated verbs, where each token is a [word, part-of-speech] list.
(tokens)
| 105 | replacements = dict((k+"'", k+"' ") for k in replacements) |
| 106 | |
| 107 | def find_lemmata(tokens): |
| 108 | """ Annotates the tokens with lemmata for plural nouns and conjugated verbs, |
| 109 | where each token is a [word, part-of-speech] list. |
| 110 | """ |
| 111 | for token in tokens: |
| 112 | word, pos, lemma = token[0], token[1], token[0] |
| 113 | if pos.startswith(("DT",)): |
| 114 | lemma = singularize(word, pos="DT") |
| 115 | if pos.startswith("JJ"): |
| 116 | lemma = predicative(word) |
| 117 | if pos == "NNS": |
| 118 | lemma = singularize(word) |
| 119 | if pos.startswith(("VB", "MD")): |
| 120 | lemma = conjugate(word, INFINITIVE) or word |
| 121 | token.append(lemma.lower()) |
| 122 | return tokens |
| 123 | |
| 124 | class Parser(_Parser): |
| 125 |
no test coverage detected
searching dependent graphs…