NLTK-inspired PerceptronTagger in Rust
The postagger
crate is available on crates.io
which can be added with,
postagger = "<latest-version>"
or
$> cargo add postagger
Download weights.json
, classes.txt
and tags.json
from the tagger
directory in the GitHub repo.
Create an instance of PerceptronTagger
, which requires file-paths to the three files downloaded in step-2. Then, use PerceptronTagger::tag
function which returns POS tags for all words present in the sentence as a Vec<Tag>
.
Each Tag
contains three attributes,
word
: the word for which the tag was predictedtag
: the POS tag of the word. Check the list of all possible NLTK POS tagsconf
: the confidence in the prediction of the POS tag
fn main() {
let tagger = PerceptronTagger::new( "tagger/weights.json" , "tagger/classes.txt" , "tagger/tags.json" ) ;
let tags = tagger.tag( "the quick brown fox jumps over the lazy dog" ) ;
for tag in &tags {
println!( "{} {} {}" , tag.word , tag.tag , tag.conf ) ;
}
}