This library is in alpha state, PRs are welcomed. An optional Forward Maximum Matching Searcher is provided when enabled by features.
Add it to your Cargo.toml
:
toml
[dependencies]
darts = "0.1"
then you are good to go. If you are using Rust 2015 you have to extern crate darts
to your crate root as well.
```rust use std::fs::File; use darts::DoubleArrayTrie;
fn main() { let mut f = File::open("./priv/dict.big.bincode").unwrap(); let da = DoubleArrayTrie::load(&mut f).unwrap(); let string = "中华人民共和国"; let prefixes = da.commonprefixsearch(string).map(|matches| { matches .iter() .map(|(endidx, v)| { &string[..endidx] }) .collect(); }).unwrapor(vec![]); asserteq!(vec!["中", "中华", "中华人民", "中华人民共和国"], prefixes); } ```
```rust use std::fs::File; use darts::DoubleArrayTrie;
fn main() { let mut f = File::open("./priv/dict.big.bincode").unwrap(); let da = DoubleArrayTrie::load(&mut f).unwrap(); assert!(da.exactmatchsearch("东湖高新技术开发区").is_some()); } ```
searcher
feature enables searcher for maximum forward matcherserialization
feature enables saving and loading serialized DoubleArrayTrie
datatoml
[dependencies]
darts = { version = "0.1", features = ["searcher", "serialization"] }
```bash
time cargo test -- --nocapture --ignored testdatbasic ```
bash
cargo bench --all-features
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.