Git Product home page Git Product logo

Comments (1)

maxbachmann avatar maxbachmann commented on July 24, 2024

ratio and get_matching_blocks use two different algorithms. ratio is based on the Indel distance, which only allows Insertions and Deletions, while get_matching_blocks is based on the normal Levenshtein distance.

In fact ratio() should be the correct one, because in the sense of "minimal string distance" we should indeed regard "a" and "c" as the two best matching blocks, yielding 2 * (1 + 1) / (3 + 3) = 0.66

get_matching_blocks simply does no guarantee, that it will behave this way. In you case the edit distance is 2. However there are multiple ways to convert them accordingly:

  1. "abc" -> "dbc" -> "dac"
  2. "abc" -> "dabc" -> "dac"

You expect it to take the second path. However it will simply take one of them (scanning all possible paths is a lot slower)

It's sad to learn that this library is currently not being maintained. I just leave this open quesition here and hope for someone's answer in maybe 2030 :)

This library has not been maintained for a long time. I am however actively maintaining a fork of this library: https://github.com/maxbachmann/Levenshtein. If you expect a drop in replacement for difflib, which has the corresponding behavior for get_matching_blocks, you can use https://github.com/maxbachmann/CyDifflib instead.

from python-levenshtein.

Related Issues (9)

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.