Metadata-Version: 2.4
Name: mawo-grammar
Version: 0.1.0
Summary: Russian grammar checker with 500+ rules for professional NLP quality
Author-email: MAWO Team <info@mawo.ru>
License-Expression: MIT
Project-URL: Homepage, https://github.com/mawo-ru/mawo-grammar
Project-URL: Repository, https://github.com/mawo-ru/mawo-grammar
Project-URL: Issues, https://github.com/mawo-ru/mawo-grammar/issues
Keywords: nlp,russian,grammar,checker,linguistic,morphology
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mawo-pymorphy3>=1.0.4
Requires-Dist: pyyaml>=6.0.3
Provides-Extra: dev
Requires-Dist: pytest>=9.0.0; extra == "dev"
Requires-Dist: pytest-cov>=7.0.0; extra == "dev"
Requires-Dist: black>=25.11.0; extra == "dev"
Requires-Dist: ruff>=0.14.4; extra == "dev"
Requires-Dist: mypy>=1.18.2; extra == "dev"
Dynamic: license-file

# mawo-grammar

[![PyPI version](https://badge.fury.io/py/mawo-grammar.svg)](https://badge.fury.io/py/mawo-grammar)
[![Python versions](https://img.shields.io/pypi/pyversions/mawo-grammar.svg)](https://pypi.org/project/mawo-grammar/)
[![CI](https://github.com/mawo-ru/mawo-grammar/actions/workflows/ci.yml/badge.svg)](https://github.com/mawo-ru/mawo-grammar/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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

```bash
pip install mawo-grammar
```

## Quick Start

```python
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

```python
# 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

```python
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

```python
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

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

# Run tests
pytest

# Code quality
black .
ruff check .
mypy mawo_grammar
```

## License

MIT License - see [LICENSE](LICENSE) for details.

## Credits

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

Part of the MAWO ecosystem:
- [mawo-pymorphy3](https://github.com/mawo-ru/mawo-pymorphy3) - Morphological analysis
- [mawo-razdel](https://github.com/mawo-ru/mawo-razdel) - Tokenization
- [mawo-slovnet](https://github.com/mawo-ru/mawo-slovnet) - NER and syntax
- [mawo-core](https://github.com/mawo-ru/mawo-core) - Unified API
