rs-natural
Natural language processing library written in Rust. Still very much a work in progress. Basically an experiment, but hey maybe something cool will come out of it.
Currently working:
- Jaro-Winkler Distance
- Levenshtein Distance
- Tokenizing
- NGrams (with and without padding)
- Phonetics (Soundex)
- Stemming (Using a fork of rust-stem)
- Naive-Bayes classification
- Term Frequency-Inverse Document Frequency(tf-idf)
Near-sight goals:
- Logistic regression classification
- Optimize naive-bayes (currently pretty slow)
- Plural/Singular inflector
How to use
Use at your own risk. Some functionality is missing, some other functionality is slow as molasses because it isn't optomized yet. I'm targeting master, and don't offer backward compatibility.
Setup
It's a crate with a cargo.toml. Add this to your cargo.toml:
[dependencies]
natural = "0.2.1"
Distance
extern crate natural;
use jaro_winkler_distance;
use levenshtein_distance;
assert_eq!;
assert_eq!;
Note, don't actually assert_eq!
on JWD since it returns an f64. To test, I actually use:
Phonetics
There are two ways to gain access to the SoundEx algorithm in this library, either through a simple soundex
function that accepts two &str
parameters and returns a boolean, or through the SoundexWord struct. I will show both here.
use soundex;
use SoundexWord;
assert!;
let s1 = new;
let s2 = new;
assert!;
assert!;
Tokenization
extern crate natural;
use tokenize;
assert_eq!;
assert_eq!;
NGrams
You can create an ngram with and without padding, e.g.:
extern crate natural;
use get_ngram;
use get_ngram_with_padding;
assert_eq!;
assert_eq!;
Classification
extern crate natural;
use NaiveBayesClassifier;
let mut nbc = new;
nbc.train;
nbc.train;
nbc.train;
nbc.train;
nbc.guess; //returns a label with the highest probability
Tf-Idf
extern crate natural;
use TfIdf;
tf_idf.add;
tf_idf.add;
tf_idf.add;
tf_idf.add;
println!; //0.2993708f32
println!; //0.13782766f32
//average of multiple terms
println!