crftag
CRF-based POS tagger and shallow parser (chunker), written in Rust.
Built on crfrs — bring your own corpus and label set.
Features
POSTagger— structured-perceptron POS taggerChunker— IOB shallow parser (CRF-based)RuleBasedChunker— grammar-rule chunker; no model file requiredtree2brackets— formats a parse tree as a bracketed stringfeaturesmodule — raw feature extraction for custom models- Re-exports [
crfrs] for training and model management
Usage
[]
= "0.1"
POS Tagging
use POSTagger;
let mut tagger = new;
tagger.load_model.unwrap;
let tagged = tagger.tag.unwrap;
// → [("من", "PRON"), ("به", "ADP"), ("مدرسه", "NOUN"), ("رفتم", "VERB"), (".", "PUNCT")]
Training a POS Model
use ;
// Each sentence is a Vec of (word, tag) pairs
let corpus: = vec!;
train_and_save.unwrap;
Chunking
use Chunker;
let mut chunker = new;
chunker.load_model.unwrap;
let tagged = &;
let chunked = chunker.tag.unwrap;
// → [("نامه", "NOUN,EZ", "B-NP"), ("ایشان", "PRON", "I-NP"), ("را", "ADP", "B-POSTP"), ("داشتم", "VERB", "B-VP")]
Rule-Based Chunking (no model)
use ;
let chunker = new;
let tagged = &;
let tree = chunker.parse;
println!;
// → [نامه ایشان NP] [را POSTP] [داشتم VP] .
API
| Item | Description |
|---|---|
POSTagger::new() |
Create a tagger (no model loaded) |
POSTagger::universal() |
Create a tagger that maps to universal POS tags |
POSTagger::load_model(path) |
Load a trained model |
POSTagger::tag(tokens) |
Tag a single sentence |
POSTagger::tag_sents(sentences) |
Tag multiple sentences |
POSTagger::train_and_save(corpus, path, config) |
Train and persist a model |
POSTagger::evaluate(corpus) |
Token-level accuracy |
Chunker::new() |
Create a chunker (no model loaded) |
Chunker::load_model(path) |
Load a trained model |
Chunker::tag(tagged) |
Assign IOB chunk tags |
Chunker::parse(tagged) |
Parse into a tree |
Chunker::train_and_save(corpus, path, config) |
Train and persist a model |
Chunker::evaluate(corpus) |
Token-level IOB accuracy |
RuleBasedChunker::new() |
Grammar-rule chunker, no model needed |
RuleBasedChunker::parse(tagged) |
Parse into a tree |
tree2brackets(tree) |
Format a parse tree as a bracketed string |
features::pos_features(sentence, i) |
Extract POS features for token i |
features::chunk_features(words, pos, i) |
Extract chunk features for token i |
License
MIT