Comments (1)
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:
- "abc" -> "dbc" -> "dac"
- "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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-levenshtein.