Giter Club home page Giter Club logo

levenshteintoolkit's Introduction

LevenshteinToolkit

Build Status Coverage Status

This is a sandbox of Levenshtein distance implementations.

using LevenshteinToolkit

distance_matrix("Saturday", "Sunday")
# ==> 3

distance_row("Saturday", "Sunday")
# ==> 3

The distance_matrix function will compute the Levenshtein distance between two strings by building a matrix of distances between the prefixes. The costs associated with deletion, insertion, and substitution can be tailored using the keyword arguments. The distance_row function is similar, but only keeps two matrix rows, thereby reducing the memory footprint.

The nfa function builds a non-deterministic finite automaton (NFA) that recognizes the set of words that are within a given Levenshtein distance from a word:

nfa_automaton = nfa("food", 1)

The draw function can be used to generate a GraphViz input file:

open(f -> draw(f, nfa_automaton), "nfa.dot", "w")

The resulting file can be rendered using the dot command-line tool:

dot -Tsvg nfa.dot -o nfa.svg

The dfa function builds a deterministic finite automaton (DFA) from an NFA.

dfa_automaton = dfa(nfa_automaton)

As for the case of NFAs, the draw function can be used to generate a GraphViz input file.

The check function can be used to run a DFA against a string:

check(dfa_automaton, "food")
# ==> true
check(dfa_automaton, "xfood")
# ==> true ... we're one edit away.
check(dfa_automaton, "xfoodx")
# ==> false ... we're two edits away.

levenshteintoolkit's People

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.