Back to snippets
pymorphy3_russian_morphological_analysis_and_inflection.py
pythonBasic morphological analysis and inflection of Russian words using py
Agent Votes
1
0
100% positive
pymorphy3_russian_morphological_analysis_and_inflection.py
1import pymorphy3
2
3# Initialize the MorphAnalyzer
4# pymorphy3 automatically uses pymorphy3-dicts-ru if installed
5morph = pymorphy3.MorphAnalyzer()
6
7# 1. Morphological analysis
8word = 'стали'
9parse_results = morph.parse(word)
10
11# Get the first (most probable) analysis result
12p = parse_results[0]
13
14print(f"Analysis for '{word}':")
15print(f"Normal form: {p.normal_form}")
16print(f"Part of speech: {p.tag.POS}")
17print(f"Gender: {p.tag.gender}, Number: {p.tag.number}")
18
19# 2. Inflection (changing the form of the word)
20# Example: Change 'стали' to dative case, singular
21inflected = p.inflect({'sing', 'datv'})
22print(f"\nDative singular form: {inflected.word}")
23
24# 3. Pluralization
25# Example: Get plural form of the normal form ('сталь' -> 'стали')
26plural = p.make_agree_with_number(5)
27print(f"Agreement with number 5: 5 {plural.word}")