english-tokenizer
Regex-driven tokenizer that splits a sentence and tags each token with its type.
Give it a string and it returns an ordered list of tokens. Each token has a
value and a tag. Tags name the type: word, number, ordinal, email,
url, mention, hashtag, emoji, emoticon, time, currency,
quoted_phrase, punctuation, symbol, plus alien for text no rule matched.
The tokenizer handles Latin-1 and Devanagari scripts. It splits common English
contractions and possessives into separate word tokens. I'll becomes I and
'll. dog's becomes dog and 's.
Installation
[]
= "0.1"
Usage
use Tokenizer;
let mut tk = new;
let tokens = tk.tokenize;
assert_eq!;
assert_eq!;
Configuration
Tokenizer::new enables every type except quoted_phrase. Turn types on or off
with define_config. It returns the count of unique active categories.
use Tokenizer;
let mut tk = new;
tk.define_config; // returns 13
An empty config splits on spaces and tags everything alien.
The tags module holds the built-in tag names as constants. Use tags::HASHTAG
in place of the "hashtag" literal so a typo fails to compile.
Custom rules
add_regex injects a rule that wins over the built-ins. add_tag registers a
new tag with a fingerprint code. A later define_config call removes added
rules.
use Tokenizer;
use Regex;
let mut tk = new;
tk.add_regex.unwrap;
let tokens = tk.tokenize;
assert_eq!;
Fingerprint
get_tokens_fp returns a one character per token fingerprint of the last
tokenize call. Each token contributes its tag code, or its literal value when the
tag has no code. Punctuation and symbol have no code, so they pass through.
use Tokenizer;
let mut tk = new;
tk.tokenize;
assert_eq!;
License
Licensed under the MIT license.