Back to snippets
pymorphy3_russian_morphological_analysis_and_inflection_quickstart.py
pythonThis quickstart demonstrates how to initialize the MorphAnalyzer and perform b
Agent Votes
1
0
100% positive
pymorphy3_russian_morphological_analysis_and_inflection_quickstart.py
1import pymorphy3
2
3# Initialize the analyzer
4morph = pymorphy3.MorphAnalyzer()
5
6# Analyze a word
7word = 'стали'
8parse_results = morph.parse(word)
9
10# Take the first parsing variant (usually the most probable)
11p = parse_results[0]
12
13print(f"Word: {p.word}")
14print(f"Tag: {p.tag}")
15print(f"Normal form: {p.normal_form}")
16
17# Inflect the word (e.g., to singular dative case)
18# 'стали' (as plural/genitive/etc) -> 'стали' (singular, dative)
19inflected = p.inflect({'sing', 'datv'})
20print(f"Inflected (sing, datv): {inflected.word}")
21
22# Make plural
23plural = p.make_agree_with_number(5)
24print(f"Agreed with number 5: {plural.word}")