An AI-enhanced grammar checking hook for PyLine (which can be found here, bundled together with this hook - PyLine), that uses advanced natural language processing with LanguageTool, pandas, and numpy for intelligent grammar and style suggestions.
- AI-Enhanced Grammar Checking: Uses LanguageTool with custom rule enhancements
- Intelligent Pattern Recognition: Advanced regex patterns for common grammar errors
- Statistical Analysis: Uses pandas/numpy for text statistics and readability scoring
- Context-Aware Suggestions: Analyzes context to reduce false positives
- Writing Style Analysis: Provides feedback on sentence structure, vocabulary, and readability
- Configurable Rules: JSON-based configuration for easy customization
- Line Number Tracking: Shows exact line numbers for each issue detected
# Make the install script executable
chmod +x install.sh
# Run the installer
./install.sh# Create the hook directory
mkdir -p ~/.pyline/hooks/editing_ops/process_content/
# Copy the hook files
cp grammar_checker__70.py ~/.pyline/hooks/editing_ops/process_content/
cp grammar_config.json ~/.pyline/hooks/editing_ops/process_content/
# Set execute permissions
chmod +x ~/.pyline/hooks/editing_ops/process_content/grammar_checker__70.pypip install language-tool-python pandas numpy- LanguageTool: Local server for faster processing (optional)
- Java: Required for local LanguageTool server
The hook automatically integrates with PyLine's content processing. No additional commands required!
- Open PyLine with any text file
- The grammar checker runs automatically on content display
- Review grammar suggestions and statistics in the output
============================================================
PYLINE GRAMMAR CHECKER - AI ENHANCED
============================================================
π TEXT STATISTICS:
Words: 46
Sentences: 9
Avg. Sentence Length: 5.11 words
Vocabulary Diversity: 28.3%
Readability Score: 95.0/100
π GRAMMAR & STYLE ISSUES:
MEDIUM:
β οΈ Line 6: Possible error: Missing 'is' in greeting phrases like 'Hello this' (62% confidence)
π‘ Suggestion: Hello, is this some text, that I am typing?
β οΈ Line 10: Possible error: Missing 'is' in greeting phrases like 'Hello this' (64% confidence)
π‘ Suggestion: Hello this is some text, that I am typing
LOW:
π‘ Line 1: Short sentences (avg: 5.11 words) can feel choppy (49% confidence)
π‘ Suggestion: Vary sentence length for better flow
π WRITING TIPS:
β’ Try varying your vocabulary for more engaging writing
π‘ Tip: Run this check after writing to catch common errors.
============================================================
Edit grammar_config.json to modify:
- Common Error Patterns: Add new grammar rules
- Confidence Levels: Adjust detection sensitivity
- Writing Style Rules: Change readability thresholds
- Output Settings: Customize display preferences
{
"common_errors": {
"their_there_theyre": [
{
"pattern": "\\btheir\\b",
"suggestion": "they're",
"explanation": "their (possessive) vs they're (they are)",
"confidence": 0.7
}
]
},
"writing_style_rules": {
"sentence_length": {
"too_long_threshold": 25,
"too_short_threshold": 8
}
}
}- Their/There/They're confusion
- Your/You're misuse
- Its/It's confusion
- Then/Than errors
- Missing copula verbs
- Subject-verb agreement
- Question structure issues
- Sentence ending punctuation
- Sentence length optimization
- Vocabulary diversity scoring
- Readability assessment (Flesch Reading Ease)
- Passive voice detection
- Repetition analysis
Hook Type: editing_ops/search_replace
Priority: 70 (balanced priority for grammar checking)
Language: Python 3.6+
AI Components: LanguageTool, pandas, numpy
This hook is licensed under GNU GPL v3+, compatible with PyLine's license.
| Component | License | Notes |
|---|---|---|
| LanguageTool | LGPL 2.1+ | Grammar checking engine |
| LanguageTool Dictionaries | Mixed (GPL, BSD, etc.) | Language data files may have various open-source licenses |
| NumPy | BSD 3-Clause | Numerical computing library |
| pandas | BSD 3-Clause | Data analysis library |
Important: While LanguageTool's code is under LGPL, some of its language dictionaries (data files) may be under different licenses like GPL or BSD. When using this hook, you are also subject to the license terms of these dictionary files.
- Text Analysis: Uses pandas/numpy for statistical text analysis
- Grammar Checking: Integrates LanguageTool for comprehensive grammar checking
- Pattern Matching: Applies custom regex patterns for common errors
- Context Analysis: Uses context to improve suggestion accuracy
- Confidence Scoring: AI-powered confidence levels for each suggestion
- Initial Load: May take 2-3 seconds to load LanguageTool
- Subsequent Checks: Fast processing with cached analysis
- Memory Usage: Moderate (LanguageTool Java process)
- CPU: Low during normal operation
# Install language-tool-python
pip install language-tool-python
# Test installation
python -c "import language_tool_python; print('OK')"# Install data science packages
pip install pandas numpy
# Test installation
python -c "import pandas, numpy; print('OK')"# Check file permissions
chmod +x ~/.pyline/hooks/editing_ops/search_replace/grammar_checker__70.py
# Test the hook directly
python grammar_checker__70.py- Edit
grammar_config.json - Add patterns to
common_errorssection - Define pattern, suggestion, and confidence level
- Restart PyLine to apply changes
Adjust thresholds in writing_style_rules:
sentence_length: Ideal sentence length rangesreadability: Score thresholds for different levelsvocabulary: Diversity and richness targets
# Remove hook files
rm ~/.pyline/hooks/editing_ops/process_content/grammar_checker__70.py
rm ~/.pyline/hooks/editing_ops/process_content/grammar_config.jsonGNU GPL v3+ - See LICENSE for details.
- Python: 3.6+
- PyLine: Version 1.1.0
- Systems: Cross-platform (WSL, Linux, macOS)
- Dependencies: language-tool-python, pandas, numpy
Enhance your writing with AI-powered grammar checking directly in PyLine!