Sadık
Sadık

Reputation: 4419

Get grammatical conjugation with GermaNLTK

What I can see in the documentation of GermaNLTK (an integration of NLTK and GermaNet) is the possibility to lemmatize German words correctly.

>>> gwl.lemmatize('geht')
'gehen'

or

>>> gwl.lemmatize('kann')
'können'

It's good to know the infinitive, but I want more. What I actually want is to get the information about grammatical conjugation. For example something like this:

>>> gwl.grammatical_conjugation('geht')
{'gehen':'3. Person Singular'}

or

>>> gwl.grammatical_conjugation('kann')
{'können': ['1. Person Singular', '3. Person Singular']}

How would you get the information about the grammatical conjugation?

Upvotes: 1

Views: 1240

Answers (1)

Sadık
Sadık

Reputation: 4419

I think GermaNLTK can't do this. Instead I'd suggest to make use of the python module pattern

pip install pattern

Here you can see the check if a word is 1. person singular (1sg) or 3. person singular (3sg)

>>> from pattern.de import conjugate
>>> wort1 = "bin"
>>> wort2 = "kann"
>>> wort3 = "geht"
>>>
>>> wort1 == conjugate(wort1, "1sg")
True
>>> wort1 == conjugate(wort1, "3sg")
False
>>> wort2 == conjugate(wort2, "1sg")
True
>>> wort2 == conjugate(wort2, "3sg")
True
>>> wort3 == conjugate(wort3, "1sg")
False
>>> wort3 == conjugate(wort3, "3sg")
True

powerful and efficient.

Upvotes: 1

Related Questions