Russian grammar checker with 500+ rules for professional NLP quality
Project description
mawo-grammar
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:
- mawo-pymorphy3 - Morphological analysis
- mawo-razdel - Tokenization
- mawo-slovnet - NER and syntax
- mawo-core - Unified API
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a03e46e977755a0a06838908a1320c0e75cb19cab233b6ea9a71163c81b405db
|
|
| MD5 |
06063e07098cd62d3f6f81e87847efbe
|
|
| BLAKE2b-256 |
ce28c0ba731282b98bbf5d3913085ace3e0163ca733ffafc2ddbb5026d353ee0
|
Provenance
The following attestation bundles were made for mawo_grammar-0.1.0.tar.gz:
Publisher:
publish.yml on mawo-ru/mawo-grammar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mawo_grammar-0.1.0.tar.gz -
Subject digest:
a03e46e977755a0a06838908a1320c0e75cb19cab233b6ea9a71163c81b405db - Sigstore transparency entry: 702365095
- Sigstore integration time:
-
Permalink:
mawo-ru/mawo-grammar@09698fcb23e635f36485eec2a3f3b0a5aa817a94 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mawo-ru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09698fcb23e635f36485eec2a3f3b0a5aa817a94 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c764e8ff31427084490f0cf79295afa13972a82fd47c6cce93a454101a406796
|
|
| MD5 |
8d2d8b89a44b703c6ead634c18ca458c
|
|
| BLAKE2b-256 |
2333d64ca0a4865a65a515ac13fd5081462e20669b9336468e49da6c4ab0c772
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mawo_grammar-0.1.0-py3-none-any.whl -
Subject digest:
c764e8ff31427084490f0cf79295afa13972a82fd47c6cce93a454101a406796 - Sigstore transparency entry: 702365096
- Sigstore integration time:
-
Permalink:
mawo-ru/mawo-grammar@09698fcb23e635f36485eec2a3f3b0a5aa817a94 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mawo-ru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09698fcb23e635f36485eec2a3f3b0a5aa817a94 -
Trigger Event:
release
-
Statement type: