Comments (2)
Yes it is using a sliding window of the length of the shorter string. This window can be shorter when it is placed at the start/end of the longer string. When both strings have the same length it will calculate the similarity in both directions and returns the higher similarity. This is done to ensure partial_ratio(a, b) == partial_ratio(b, a)
.
You can use fuzz.partial_ratio_alignment
to retrieve both the similarity and the alignment/window used to achieve this similarity.
from rapidfuzz.
I think I just understood what is going on:
although the shorter string is always kept the same length, it is compared against a sliding window of variable length in the longer string. (I was somehow expecting a sliding window of the same constant length as well).
In this case both are equally long, so we can freely pick which one is the longer. Let's pick toad as the short one.
Now it finds the best alignment for toad <> goa
The similarity for this comparison is (1 substitution, 1 deletion): 1 - (2+1)/(3+4) = 0.5714286
Interestingly enough, when adding one character at the beginning and one at the and of the longer string, the partial ratio become 0.50 (because the shorter windows are only evaluated at the beginning and the end of the character string):
rfuzz.partial_ratio("toad","(goat)")
returns 0.50, because toad is not compared against goa or oat, but only against the shorter windows (go and at).
from rapidfuzz.
Related Issues (20)
- understanding similitude differences between extract, cdist and extractOne HOT 4
- Processor Extraction Choices Documentation HOT 1
- Checking for NA without importing pandas HOT 12
- 1 test fails HOT 5
- AttributeError: module 'rapidfuzz.process' has no attribute 'cpdist' HOT 1
- Different results on Windows and Linux? Linux didn't supported? HOT 4
- Incorrect type hinting in extract HOT 1
- Build issue with nightly build of CMake HOT 3
- "import rapidfuzz" causes "illegal hardware instruction" HOT 20
- Please add support for newer versions of TaskFlow HOT 4
- Inconsistent comparison between empty string and None/NA HOT 4
- Quick Question HOT 4
- Migration to `scikit-build-core` HOT 1
- add simd binaries to pyinstaller
- Documentation error for rapidfuzz.fuzz.process.ratio HOT 1
- is there any plan to return the matched segment in function "extract" ?
- Build requirements issue: PEP517 build from sdist fails HOT 1
- Add support for free threaded Python HOT 1
- partial ratio output unexpected results HOT 2
- Could partial_ratio support Levenshtein.normalized_similarity? HOT 2
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 rapidfuzz.