Git Product home page Git Product logo

dym's Introduction

Did you mean? Build Status GoDoc

This package gets the inspiration from git's "Did you mean this?" feature. That is, it detects typos and it offers similar words that might be what the user really wanted to type. This package offers two public methods:

func Similar(dict []string, word string) []string
func SimilarDistance(dict []string, word string, dist int) []string

The first method returns all the words from the given dictionary that are close to the given word. The second method is identical to the first one but it also accepts a distance (the number of swaps, additions, deletions, etc. allowed). Finally, this package also provides a couple of helper methods:

func IsSimilar(string1, string2 string) bool
func IsSimilarDistance(string1, string2 string, dist int) bool

The first method returns whether the two given strings are similar. The second method does the same but it also requires a distance.

Usage

Here goes an example:

package main

import "github.com/mssola/dym"

func main() {
  a := "thing"
  dict := []string{"thingie", "lala", "ting"}

  results := dym.Similar(dict, a)
  // results now contains: ["thingie", "ting"]

  results = dym.SimilarDistance(dict, a, 1)
  // results now contains: ["ting"]
}

Copyright © 2014-2016 Miquel Sabaté Solà, released under the MIT License.

dym's People

Contributors

mssola avatar

Stargazers

 avatar  avatar  avatar

Watchers

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