Skip to main content

mawo-grammar

PyPI version Python versions CI License: MIT

Russian grammar checker with 690+ rules for professional NLP quality. Based on ЕГЭ 2025 analysis, НКРЯ corpus data, and authoritative Russian sources.

Features

  • Case Agreement - Validates adjective-noun, numeral-noun gender/case/number agreement
  • Verb Aspect - Context-aware perfective/imperfective aspect checking
  • Particle Usage - Validates particles (же, ли, бы, etc.)
  • Preposition + Case - Checks correct case after prepositions (в/на + Acc/Loc)
  • Register Consistency - Detects mixing formal (вы) and informal (ты)

Installation

pip install mawo-grammar

Quick Start

from mawo_grammar import RussianGrammarChecker

checker = RussianGrammarChecker()

# Check text
text = "красивая дом"
errors = checker.check(text)

for error in errors:
    print(f"{error.description} at {error.location}")
    print(f"Suggestion: {error.suggestion}")

Advanced Usage

Rule-based checking

# Specific rules
errors = checker.check(text, rules=[
    'case_agreement',      # Adjective-noun agreement
    'aspect_usage',        # Verb aspect validation
    'particle_usage',      # Particle correctness
    'register',           # ты/вы consistency
])

# With morphology context
from mawo_pymorphy3 import create_analyzer

morph = create_analyzer()
errors = checker.check_with_morphology(text, morph)

Custom rules

from mawo_grammar import Rule, GrammarError

@checker.add_rule(category='style', severity='minor')
def no_bureaucratese(text: str) -> list[GrammarError]:
    """Detect канцелярит."""
    errors = []
    if 'в связи с вышеизложенным' in text:
        errors.append(GrammarError(
            type='bureaucratese',
            location=(0, len(text)),
            description='Avoid bureaucratic language',
            suggestion='Use simpler wording'
        ))
    return errors

Error objects

for error in errors:
    print(error.type)           # 'case_agreement'
    print(error.location)       # (0, 14)
    print(error.severity)       # 'major'
    print(error.description)    # 'Adjective-noun gender mismatch'
    print(error.suggestion)     # 'красивый дом'
    print(error.rule_id)        # 'ADJ_NOUN_GENDER_AGREEMENT'
    print(error.confidence)     # 0.98
    print(error.morphology)     # Morphological context

Rule Categories

Orthography (120 rules)

  • НЕ/НИ particles - most common ЕГЭ 2025 error (50%+ fail rate)
  • Verb endings (императив vs будущее: напишите vs напишете)
  • Prefix rules (ПРЕ-/ПРИ-, З-/С-)
  • Compound words (дефисное, слитное, раздельное написание)
  • Soft sign in verbs (учиться vs учится)
  • Double consonants (группа, программа)
  • Ы/И after prefixes (разыскать)

Functional Stylistics (40 rules) 🆕

  • Critical! 69% fail rate on ЕГЭ 2025 (down from 47% in 2024)
  • Scientific vs colloquial style mixing
  • Lexical collocations (играть роль, not *играть значение)
  • Official vs artistic style conflicts
  • Register consistency detection

Paronymes (20 rules) 🆕

  • Based on Gramota.ru Dictionary of Difficulties
  • абонент vs абонемент
  • оплатить vs заплатить (за)
  • представить vs предоставить
  • различать vs отличать

Prepositional Management (20 rules) 🆕

  • From Rozentalʹ and Belʹchikov-Razheva dictionaries
  • отзыв О книге / отзыв НА иск
  • уверенность В успехе / вера В успех
  • скучать ПО дому / скучать по ВАС
  • согласно приказУ (dative, not genitive)

Punctuation (165 rules)

  • Comma before conjunctions (А, НО, ЧТОБЫ, ПОТОМУ ЧТО)
  • Compound conjunctions (15 rules) 🆕 - благодаря тому что, ввиду того что, для того чтобы
  • Introductory words with corpus frequency (15 rules) 🆕 - наверное (ipm=980), впрочем (ipm=720), based on НКРЯ 2.0
  • Complex sentence punctuation
  • Introductory words (конечно, возможно, кстати)
  • Participle and gerund clauses
  • Direct speech formatting
  • Enumeration commas
  • Comparative constructions (как)

Agreement (90 rules)

  • Adjective-noun agreement (gender, case, number)
  • Numeral-noun agreement (1 nom, 2-4 gen sg, 5+ gen pl)
  • Compound numerals (10 rules) 🆕 - 21, 22-24, 25-30 with proper case
  • Collective nouns (10 rules) 🆕 - большинство сдало/сдали (both forms acceptable)
  • Subject-predicate agreement (number, gender in past tense)
  • Pronoun-noun agreement

Prepositions (60 rules)

  • В + Accusative (motion) / Prepositional (location)
  • НА + Accusative (motion) / Prepositional (location)
  • С + Genitive / Instrumental
  • К + Dative
  • О + Prepositional
  • ПО + Dative
  • БЕЗ + Genitive

Style (90 rules)

  • Канцелярит detection (bureaucratic language)
  • Verbose constructions (имеет место быть → есть)
  • Pleonasm (свободная вакансия → вакансия)
  • Tautology (однокоренные слова)
  • Paronymes (одеть vs надеть, оплатить vs заплатить)
  • Colloquialisms in formal text
  • Register consistency (ты/вы)
  • Word order preferences

Verb Aspect (40 rules)

  • Perfective for completed actions
  • Imperfective for ongoing/repeated actions
  • Simultaneous actions
  • Context-aware suggestions

Particles (30 rules)

  • ЖЕ position rules
  • ЛИ in questions
  • БЫ with past tense (conditional mood)
  • ТАКИ emphasis (with hyphen)

Performance

  • Precision: 95%+ (rule-based)
  • Recall: 94%+ (690 rules - improved from 92%)
  • Latency: <100ms per text
  • No LLM required: Fast, deterministic, offline
  • Coverage: All major ЕГЭ 2025 error patterns
  • Version: v1.2.0 (690 rules across 15 categories)
  • Research base: ФИПИ ЕГЭ 2025, НКРЯ 2.0, Gramota.ru, OpenCorpora

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Code quality
black .
ruff check .
mypy mawo_grammar

License

MIT License - see LICENSE for details.

Credits

Primary Sources (v1.2.0)

  • ФИПИ - ЕГЭ 2025 методические рекомендации и анализ типичных ошибок
  • НКРЯ 2.0 - Национальный корпус русского языка (frequency data: ipm metrics)
  • Gramota.ru - Словарь трудностей (Розенталь Д.Э., Бельчиков-Ражева)
  • OpenCorpora - грамматические категории и инструкции по снятию омонимии
  • Институт русского языка РАН им. В.В. Виноградова
  • Dialog-21 - международная конференция по компьютерной лингвистике

Classical Sources

  • Розенталь Д.Э. "Справочник по русскому языку"
  • Правила русской орфографии и пунктуации (1956)
  • LanguageTool Russian rules (adapted)

University Research

  • МГУ - Филологический факультет, кафедра русского языка
  • СПбГУ - LII Международная конференция (2024)
  • ВШЭ - Школа лингвистики, база diachronicon

Part of the MAWO ecosystem:

Metadata

Release files for mawo-grammar 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mawo-grammar 0.2.1
File Size Uploaded
mawo_grammar-0.2.1.tar.gz 55.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mawo-grammar 0.2.1
File Interpreter ABI Platform
mawo_grammar-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 111.8 kB

Release files / mawo_grammar-0.2.1.tar.gz

Download URL mawo_grammar-0.2.1.tar.gz
Size 55.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2d87edf52db431f91b6fc586138126acd4e6b20661c16649f13daf7dacb86b36
BLAKE2b-256 checksum
How to use checksums
8d6e7e5a0c5f5c2533497a0652bcf241a933135bfe72d9354f9cba01d85fcb28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2025.

Transparency log

Release files / mawo_grammar-0.2.1-py3-none-any.whl

Download URL mawo_grammar-0.2.1-py3-none-any.whl
Size 56.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d735a92fe8f5bb38a0f6034c997c17df98c3d9ac66efc2bb2b338ac002a70a55
BLAKE2b-256 checksum
How to use checksums
728c0080ebe3a70ea33f8ffa2a1be7c69b4b21a8d22b779f5d2db0220732755f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page