Giter VIP home page Giter VIP logo

darts's Introduction

Double Array Trie

Intro

Double-Array Trie is a structure designed to make the size compact while maintaining fast access with algorithms for retrieval. It is more effective when using in Chinese/Japanese environment

Double-Array Trie is first presented in the paper below:

An Efficient Digital Search Algorithm by Using a Double-Array Structure

reference: An Implementation of Double-Array Trie

The project clones from the go-darts, but provides two more features

Usage

package main

import (
    "bufio"
    "bytes"
    "fmt"
    "io"
    "os"
)

import (
    "github.com/anknown/darts"
)

func ReadRunes(filename string) ([][]rune, error) {
    dict := [][]rune{}

    f, err := os.OpenFile(filename, os.O_RDONLY, 0660)
    if err != nil {
        return nil, err
    }

    r := bufio.NewReader(f)
    for {
        l, err := r.ReadBytes('\n')
        if err != nil || err == io.EOF {
            break
        }
        l = bytes.TrimSpace(l)
        dict = append(dict, bytes.Runes(l))
    }

    return dict, nil
}

func main() {
    d := new(godarts.Darts)
    dict, err := ReadRunes("your dict file")
    if err != nil {
        fmt.Println(err)
        return
    }

    dat, _, err := d.Build(dict)
    if err != nil {
        fmt.Println(err)
        return
    }

    //dat.PrintTrie()   //double array trie
    //llt.PrintTrie()   //linked list trie

    for _, d := range dict {
        if !dat.ExactMatchSearch(d, 0) {
            fmt.Printf("%s not found\n", string(d))
            return
        }
    }

    fmt.Printf("Test total %d english words\n", len(dict))
}

License

MIT License

darts's People

Watchers

 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.