Git Product home page Git Product logo

rust-darts's Introduction

rust-darts: Double-Array Trie Rust implementation.

This library is in alpha state, PRs are welcomed. An optional Forward Maximum Matching Searcher is provided when enabled by features.

Build Status codecov Crates.io docs.rs

Installation

Add it to your Cargo.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.

Example

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.common_prefix_search(string).map(|matches| {
        matches
            .iter()
            .map(|(end_idx, v)| {
                &string[..end_idx]
            })
            .collect();
    }).unwrap_or(vec![]);
    assert_eq!(vec!["中", "中华", "中华人民", "中华人民共和国"], prefixes);
}
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.exact_match_search("东湖高新技术开发区").is_some());
}

Enabling Additional Features

  • searcher feature enables searcher for maximum forward matcher
  • serialization feature enables saving and loading serialized DoubleArrayTrie data
[dependencies]
darts = { version = "0.1", features = ["searcher", "serialization"] }

To Rebuild Dictionary

# It would take minutes, be patient.
time cargo test --all-features -- --nocapture --ignored test_dat_basic

To run benchmark tests

cargo bench --all-features

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

Reference

rust-darts's People

Contributors

andelf avatar messense avatar mno2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.