GithubHelp home page GithubHelp logo

levtrie's Introduction

levtrie

This go package implements a Trie that acts like a map from strings to strings, allowing the usual Get, Set, and Delete operations on key-value associations. In addition, the Trie supports a few variations on searches for key-value pairs where the key is within a particular edit distance of a query string.

Here's an example of how you might use levtrie to find the 10 closest words to the word "sitting" that are within edit distance 2 from a list of words held in the slice wordlist:

import "github.com/aaw/levtrie"

...

t := levtrie.New()
for _, word := range wordlist {
    t.Set(word, "")
}
results := t.Suggest("sitting", 2, 10)

Or see a full example at the Go Playground.

See the godoc for this package for complete documentation.

See examples/typeahead in this repo for an extended example of implementing typeahead-style query suggestions with levtrie. You can launch a small webapp with go run examples/typeahead/typeahead.go from the top level clone of this repo that lets you type in a query box to find suggestions for spelling corrections.

All of the searches restricted by edit distance in levtrie are accomplished by generating a non-deterministic Levenshtein Automata on the fly and simulating it in parallel with the Trie search. I've described this technique in more detail in this post.

levtrie's People

Contributors

aaw avatar

Stargazers

 avatar

Watchers

 avatar James Cloos 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.