Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bminixhofer/nlprule
A fast, low-resource Natural Language Processing and Text Correction library written in Rust.
https://github.com/bminixhofer/nlprule
grammar grammatical-error-correction machine-learning natural-language-processing nlp proofreading rust spellcheck style-checker
Last synced: 13 days ago
JSON representation
A fast, low-resource Natural Language Processing and Text Correction library written in Rust.
- Host: GitHub
- URL: https://github.com/bminixhofer/nlprule
- Owner: bminixhofer
- License: apache-2.0
- Created: 2020-07-19T16:24:54.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-23T00:44:59.000Z (over 1 year ago)
- Last Synced: 2024-10-13T14:24:54.577Z (28 days ago)
- Topics: grammar, grammatical-error-correction, machine-learning, natural-language-processing, nlp, proofreading, rust, spellcheck, style-checker
- Language: Rust
- Homepage:
- Size: 898 KB
- Stars: 597
- Watchers: 13
- Forks: 39
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
nlpruleA fast, low-resource Natural Language Processing and Error Correction library written in Rust. nlprule implements a rule- and lookup-based approach to NLP using resources from [LanguageTool](https://github.com/languagetool-org/languagetool).
Python Usage
Install: `pip install nlprule`
Use:
```python
from nlprule import Tokenizer, Rulestokenizer = Tokenizer.load("en")
rules = Rules.load("en", tokenizer)
```
```python
rules.correct("He wants that you send him an email.")
# returns: 'He wants you to send him an email.'rules.correct("I can due his homework.")
# returns: 'I can do his homework.'for s in rules.suggest("She was not been here since Monday."):
print(s.start, s.end, s.replacements, s.source, s.message)
# prints:
# 4 16 ['was not', 'has not been'] WAS_BEEN.1 Did you mean was not or has not been?
```
```python
for sentence in tokenizer.pipe("A brief example is shown."):
for token in sentence:
print(
repr(token.text).ljust(10),
repr(token.span).ljust(10),
repr(token.tags).ljust(24),
repr(token.lemmas).ljust(24),
repr(token.chunks).ljust(24),
)
# prints:
# 'A' (0, 1) ['DT'] ['A', 'a'] ['B-NP-singular']
# 'brief' (2, 7) ['JJ'] ['brief'] ['I-NP-singular']
# 'example' (8, 15) ['NN:UN'] ['example'] ['E-NP-singular']
# 'is' (16, 18) ['VBZ'] ['be', 'is'] ['B-VP']
# 'shown' (19, 24) ['VBN'] ['show', 'shown'] ['I-VP']
# '.' (24, 25) ['.', 'PCT', 'SENT_END'] ['.'] ['O']
```Rust Usage
Recommended setup:
`Cargo.toml`
```toml
[dependencies]
nlprule = ""[build-dependencies]
nlprule-build = "" # must be the same as the nlprule version!
````build.rs`
```rust
fn main() -> Result<(), nlprule_build::Error> {
println!("cargo:rerun-if-changed=build.rs");nlprule_build::BinaryBuilder::new(
&["en"],
std::env::var("OUT_DIR").expect("OUT_DIR is set when build.rs is running"),
)
.build()?
.validate()
}
````src/main.rs`
```rust
use nlprule::{Rules, Tokenizer, tokenizer_filename, rules_filename};fn main() {
let mut tokenizer_bytes: &'static [u8] = include_bytes!(concat!(
env!("OUT_DIR"),
"/",
tokenizer_filename!("en")
));
let mut rules_bytes: &'static [u8] = include_bytes!(concat!(
env!("OUT_DIR"),
"/",
rules_filename!("en")
));let tokenizer = Tokenizer::from_reader(&mut tokenizer_bytes).expect("tokenizer binary is valid");
let rules = Rules::from_reader(&mut rules_bytes).expect("rules binary is valid");assert_eq!(
rules.correct("She was not been here since Monday.", &tokenizer),
String::from("She was not here since Monday.")
);
}
````nlprule` and `nlprule-build` versions are kept in sync.
## Main features
- Rule-based Grammatical Error Correction through multiple thousand rules.
- A text processing pipeline doing sentence segmentation, part-of-speech tagging, lemmatization, chunking and disambiguation.
- Support for English, German and Spanish.
- Spellchecking. (*in progress*)## Goals
- A single place to apply spellchecking and grammatical error correction for a downstream task.
- Fast, low-resource NLP suited for running:
1. as a pre- / postprocessing step for more sophisticated (i. e. ML) approaches.
2. in the background of another application with low overhead.
3. client-side in the browser via WebAssembly.
- 100% Rust code and dependencies.## Comparison to LanguageTool
| | \|Disambiguation rules\| | \|Grammar rules\| | LT version | nlprule time | LanguageTool time |
| ------- | --------------------------------------------- | ----------------- | ---------- | ------------ | ----------------- |
| English | 843 (100%) | 3725 (~ 85%) | 5.2 | 1 | 1.7 - 2.0 |
| German | 486 (100%) | 2970 (~ 90%) | 5.2 | 1 | 2.4 - 2.8 |
| Spanish | *Experimental support. Not fully tested yet.* |See the [benchmark issue](https://github.com/bminixhofer/nlprule/issues/6) for details.
## Projects using nlprule
- [prosemd](https://github.com/kitten/prosemd-lsp): a proofreading and linting language server for markdown files with VSCode integration.
- [cargo-spellcheck](https://github.com/drahnr/cargo-spellcheck): a tool to check all your Rust documentation for spelling and grammar mistakes.Please submit a PR to add your project!
## Acknowledgements
All credit for the resources used in nlprule goes to [LanguageTool](https://github.com/languagetool-org/languagetool) who have made a Herculean effort to create high-quality resources for Grammatical Error Correction and broader NLP.
## License
nlprule is licensed under the MIT license or Apache-2.0 license, at your option.
The nlprule binaries (`*.bin`) are derived from LanguageTool v5.2 and licensed under the LGPLv2.1 license. nlprule statically and dynamically links to these binaries. Under LGPLv2.1 §6(a) this does not have any implications on the license of nlprule itself.