Skip to main content

Russian grammar checker with 500+ rules for professional NLP quality

Project description

mawo-grammar

PyPI version Python versions CI License: MIT

Russian grammar checker with 500+ rules for professional NLP quality.

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

Case Agreement (50+ rules)

  • Adjective-noun agreement (gender, case, number)
  • Numeral-noun agreement
  • Pronoun-noun agreement
  • Demonstrative-noun agreement

Verb Aspect (30+ rules)

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

Particles (20+ rules)

  • же, ли, бы, то, ка, таки
  • Position and usage validation

Prepositions (40+ rules)

  • в + Accusative (motion) / Prepositional (location)
  • на + Accusative (motion) / Prepositional (location)
  • с + Genitive / Instrumental
  • по + Dative / Prepositional

Register (10+ rules)

  • ты/вы consistency
  • Formal vs informal mixing

Performance

  • Precision: 95%+ (rule-based)
  • Recall: 90%+ (500+ rules)
  • Latency: <100ms per text
  • No LLM required: Fast, deterministic, offline

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

Based on:

  • Розенталь "Справочник по русскому языку"
  • OpenCorpora grammar annotations
  • LanguageTool Russian rules (adapted)

Part of the MAWO ecosystem:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mawo_grammar-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mawo_grammar-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file mawo_grammar-0.1.0.tar.gz.

File metadata

  • Download URL: mawo_grammar-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mawo_grammar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a03e46e977755a0a06838908a1320c0e75cb19cab233b6ea9a71163c81b405db
MD5 06063e07098cd62d3f6f81e87847efbe
BLAKE2b-256 ce28c0ba731282b98bbf5d3913085ace3e0163ca733ffafc2ddbb5026d353ee0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mawo_grammar-0.1.0.tar.gz:

Publisher: publish.yml on mawo-ru/mawo-grammar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mawo_grammar-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mawo_grammar-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mawo_grammar-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c764e8ff31427084490f0cf79295afa13972a82fd47c6cce93a454101a406796
MD5 8d2d8b89a44b703c6ead634c18ca458c
BLAKE2b-256 2333d64ca0a4865a65a515ac13fd5081462e20669b9336468e49da6c4ab0c772

See more details on using hashes here.

Provenance

The following attestation bundles were made for mawo_grammar-0.1.0-py3-none-any.whl:

Publisher: publish.yml on mawo-ru/mawo-grammar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page