GithubHelp home page GithubHelp logo

vaslem / editdistance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roy-ht/editdistance

0.0 0.0 0.0 159 KB

Fast implementation of the edit distance(Levenshtein distance)

License: MIT License

C++ 62.43% Python 12.45% C 6.43% Cython 18.68%

editdistance's Introduction

editdistance

Fast implementation of the edit distance (Levenshtein distance).

This library simply implements Levenshtein distance with C++ and Cython.

The algorithm used in this library is proposed by Heikki Hyyrö, "Explaining and extending the bit-parallel approximate string matching algorithm of Myers", (2001)

Binary wheels

Thanks to pypa/cibuildwheel There are binary wheels on Linux, Mac OS, and Windows.

Install

You can install via pip:

pip install editdistance

Usage

It's quite simple:

import editdistance
editdistance.eval('banana', 'bahama')
# 2L

Simple Benchmark

With IPython, I tried several libraries:

On Python 2.7.5:

a = 'fsffvfdsbbdfvvdavavavavavava'
b = 'fvdaabavvvvvadvdvavavadfsfsdafvvav'
import pylev
timeit pylev.levenshtein(a, b)
# 100 loops, best of 3: 7.48 ms per loop

from pyxdameraulevenshtein import damerau_levenshtein_distance
timeit damerau_levenshtein_distance(a, b)
# 100000 loops, best of 3: 11.4 µs per loop

timeit editdistance.eval(a, b)  # my library
# 100000 loops, best of 3: 3.5 µs per loop

import Levenshtein

timeit Levenshtein.distance(a, b)
# 100000 loops, best of 3: 3.21 µs per loop

Distance with Any Object

Above libraries only support strings. But Sometimes other type of objects such as list of strings(words). I support any iterable, only requires hashable object of it:

Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
# <ipython-input-22-3e0b30d145ac> in <module>()
# ----> 1 Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
#
# TypeError: distance expected two Strings or two Unicodes

editdistance.eval(['spam', 'egg'], ['spam', 'ham'])
# 1L

So if object's hash is same, it's same. You can provide __hash__ method to your object instances.

Enjoy!

License

It is released under the MIT license.

Copyright (c) 2013 Hiroyuki Tanaka

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

editdistance's People

Contributors

amr-keleg avatar blag avatar boeddeker avatar jacobhayes avatar jogo avatar joshix-1 avatar roy-ht avatar s-weigand avatar wesinator avatar zoharby 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.