GithubHelp home page GithubHelp logo

pylev's Introduction

pylev

A pure Python Levenshtein implementation that's not freaking GPL'd.

Based off the Wikipedia code samples at http://en.wikipedia.org/wiki/Levenshtein_distance.

https://pepy.tech/badge/pylev https://travis-ci.com/toastdriven/pylev.svg?branch=main

Requirements

  • Python 2.7.X, Python 3.3+ or PyPy 1.6.0+

Usage

Usage is fairly straightforward:

import pylev
distance = pylev.levenshtein('kitten', 'sitting')
assert distance == 3

License

New BSD.

Tests

Setup:

$ git clone https://github.com/toastdriven/pylev.git
$ cd pylev

Running:

$ python -m unittest tests

Alternatives

Version History

  • v1.5.0

    • Added an alternatives section. Thanks to @graingert for the start!
  • v1.4.0

    • Updated for current versions of Python
    • Integrated a better Travis matrix. Thanks to @graingert!
    • Fixed mistaken docs about the assert. Thanks to @adamchainz!
    • Reorganized the package.
    • Blacked all the source code.
  • v1.3.0

    • Implemented a considerably faster variants (orders of magnitude).
    • Tested & working on Python 2.7.4, Python 3.3.1 & PyPy 1.9.0.
  • v1.2.0

    • Fixed all incorrect spellings of "Levenshtein" (there's no "c" in it).
    • Old methods are aliased for backward-compatibility.
  • v1.1.0

    • Implemented a much faster variant (several orders of magnitude).
    • The older variant was renamed to classic_levenschtein.
    • Tested & working on Python 3.3 & PyPy 1.6.0 as well.
  • v1.0.2

    • Python packaging is REALLY hard. Including the README this time.
  • v1.0.1

    • Python packaging is hard. Including the README this time.
  • v1.0.0

    • Initial release, just the naive implementation of Levenshtein.

pylev's People

Contributors

adamchainz avatar graingert avatar mbarkhau avatar msabramo avatar thedrow avatar toastdriven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pylev's Issues

Use pylev.levenshtein

Hi,

I have downloaded the package and it works great.
Now I want to use the pylev.levenshtein package as the metric for the scipy linkage function, something like:
Z = linkage(my_array, method='average', metric=pylev.levenshtein).

What exactly do I need to use?
Thanks

This project is active?

Hi, I note that this project is used on clikit and is a depedency of poetry.

I'm trying to package poetry on Debian and I need package pylev too. I was
wondering to know if this project is still maintained.

Cheers

LICENSE not included in pypi source

I'm working on packaging this project for fedora, and during the review, it was pointed out that the 1.2.0 sources that are available from PyPI don't include the LICENSE file - which they apparently should.

This project is active?

Hi, I note that this project is used on clikit and is a depedency of poetry.

I'm trying to package poetry on Debian and I need package pylev too. I was
wondering to know if this project is still maintained.

Cheers

Add v1.3.0 tag/release

I notice that the version on Pypi is 1.3.0 and the version in the README says 1.3.0 as of commit 72e3d49, but there isn't a Github release or a tag for v1.3.0. Can you add one? I'm packaging (NixOS/nixpkgs#53599) this for nixpkgs and it would be helpful.

Enable Travis CI

There's a .travis.yml but Travis had no builds yet so probably the hook was never added?

Convenience function: search

Happy to see this project active again.

I've copy pasted variations of this function between projects, perhaps it's worth considering inclusion.

def search(
    needle       : str,
    haystack     : Iterable[str],
    max_distance : int = 2,
    distance_func: Callable[[str, str], int] = pylev.damerau_levenshtein,
) -> List[str]:
    closest: List[Tuple[int, str]] = []
    for maybe_needle in haystack:
        dist = distance_func(needle, maybe_needle)
        if dist <= max_distance:
            closest.append((dist, maybe_needle))
    return [val for _dist, val in sorted(closest)]

Example usage.

if key not in VALID_KEYS:
    alternatives = pylev.search(key, VALID_KEYS)
    if alternatives: 
        raise KeyError(key, f"Maybe {alternatives} ?")
    else:
        raise KeyError(key)

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.