Russian morphological analysis with pymorphy
pymorphy is a nice Python library from morphological analysis of Russian. Unfortunately, its documentation has verry little information in English. Here is a guide for non-Russian speakers.
1. Install pymorphy
pip install pymorphy
2. Download dictionaries
wget https://bitbucket.org/kmike/pymorphy/downloads/ru.sqlite-json.zip
unzip ru.sqlite-json.zip -d ru-dict
3. Analyze words
For each of the possible analyses of the word "прочим", we print its lemma, its part-of-speech class and its morphological information:
import pymorphy
morph = pymorphy.get_morph('ru-dict')
for analysis in morph.get_graminfo(u'ПРОЧИМ'):
print analysis['norm'], analysis['class'], analysis['info']
ПРОЧЕЕ МС ср,ед,тв
ПРОЧИЙ МС мн,дт
ПРОЧИТЬ Г дст,нст,1л,мн
...
Queries have to be unicode uppercase strings.
If you only want to obtain the set of possible lemmas for a word, use:
morph.normalize(u'ПРОЧИМ') == set([u'ПРОЧЕЕ', u'ПРОЧИТЬ', u'ПРОЧИЙ'])
You can also run the reverse operation:
morph.inflect_ru(u'ПРОЧЕЕ', u'ср,ед,тв') == u'ПРОЧИМ'
or obtain the full set of possible realizations of a given lemma with:
for form in morph.decline(u'ГОВОРИТЬ'):
print form['word'], form['class'], form['info']
ГОВОРИТЬ ИНФИНИТИВ дст
ГОВОРЮ Г дст,нст,1л,ед
ГОВОРИШЬ Г дст,нст,2л,ед
...
4. Using the analyses
The documentation in Russian contains a description of the part-of-speech tags (части речи) and morphological markers (граммемы) used.
| Part of speech | Example | Description | Russian name |
|---|---|---|---|
| C | мама | name | существительное |
| П | красный | adjective | прилагательное |
| МС | он | personal pronoun | местоим.-сущ. |
| Г | идет | verb (personal form) | глагол |
| ПРИЧАСТИЕ | идущий | participle | причастие |
| ДЕЕПРИЧАСТИЕ | идя | gerund | деепричастие |
| ИНФИНИТИВ | идти | infinitive | инфинитив |
| МС-ПРЕДК | нечего | predicative pronoun | местоим.-предикатив |
| МС-П | всякий | adjective pronoun | местоим. прил. |
| ЧИСЛ | восемь | cardinal number | количественное числ. |
| ЧИСЛ-П | восьмой | ordinal number | порядковое числ. |
| Н | круто | adverb | наречие |
| ПРЕДК | интересно | predicative | предикатив |
| ПРЕДЛ | под | preposition | предлог |
| СОЮЗ | и | conjunction | союз |
| МЕЖД | ой | interjection | междометие |
| ЧАСТ | же, бы | particle | частица |
| ВВОДН | конечно | introductory word | вводное слово |
| КР_ПРИЛ | красива | short adjective | краткое прил. |
| КР_ПРИЧАСТИЕ | построена | short participle | краткое прич. |
Tagset conversion utilities have been written by the authors of pymorphy, and it is also possible to obtained simplified morphological information by using the standard=True argument when calling get_graminfo:
for analysis in morph.get_graminfo(u'ПРОЧИМ', standard=True):
print analysis['norm'], analysis['class'], analysis['info']
ПРОЧЕЕ - n,ins,sg
ПРОЧИЙ - pl,dat
ПРОЧИТЬ V 1p,pres,pl
...