mirror of
https://github.com/nexus-stc/hyperboria
synced 2025-01-11 19:25:53 +01:00
dd23846059
- [nexus] Switch bot - [bot] Added extra receivers functionality GitOrigin-RevId: 68fc32d3e79ff411758f54f435fe8680fc42dead
30 lines
845 B
Python
30 lines
845 B
Python
import lemminflect # noqa
|
|
import spacy
|
|
|
|
|
|
class EnglishMorphology:
|
|
VERBS = {'VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ'}
|
|
ADJS = {'JJ', 'JJR', 'JJS'}
|
|
NOUNS = {'NN', 'NNP', 'NNPS', 'NNS'}
|
|
ADVERBS = {'RB', 'RBR', 'RBS'}
|
|
|
|
WORD_KINDS = [VERBS, ADJS, NOUNS, ADVERBS]
|
|
|
|
def __init__(self, name):
|
|
self.nlp = spacy.load(name)
|
|
|
|
def derive_forms(self, word):
|
|
forms = set()
|
|
word = self.nlp(word)[0]
|
|
inflected = False
|
|
for kind in self.WORD_KINDS:
|
|
if word.tag_ in kind:
|
|
for w in kind:
|
|
inflection = word._.inflect(w)
|
|
if inflection:
|
|
inflected = True
|
|
forms.add(word._.inflect(w))
|
|
if not inflected and word:
|
|
forms.add(str(word))
|
|
return list(sorted(forms))
|