Comments (4)
for sco in ['fuzz.ratio','fuzz.WRatio','fuzz.QRatio']:
result = extract(query = x, choices = choices, score_cutoff=90, scorer=eval(sco))
why would you use eval for this 😨 You can simply iterate over the functions:
for scorer in [fuzz.ratio, fuzz.WRatio, fuzz.QRatio]:
result = extract(x, choices, score_cutoff=90, scorer=scorer)
Why does extract() return an empty list from some of the explicit scorer values I tried? (fuzz.ratio and fuzz.QRatio)
process.extract
filters out results if you pass a score_cutoff. In your case fuzz.ratio
/fuzz.QRatio
return a similarity below 90 for each element.
Which scorer should I use in first test, so similitudes are not the same? (can't understand why all matches get a 90.0 score)
A lot of the scorers use a partial match and since:
- 'Soliva sessilis' is a substring of 'Soliva sessilis auct., non Ruiz & Pav.'
- 'Soliva sessilis' is a substring of 'Soliva sessilis Ruiz & Pav.'
- 'Soliva' is a substring of 'Soliva sessilis'
This partial match always has a similarity of 100. fuzz.WRatio
puts a weight of 0.9
on these partial matches, so you end up with a similarity of 90. E.g. fuzz.ratio
or the distances in rapidfuzz.distance.*
do not show this behaviour.
Why 2nd and 3rd example produce a 71.42857 similitude of 'Soliva sessilis' against 'Soliva sessilis Ruiz & Pav.', whereas in 1st example the output is 90, as I said above?
fuzz.ratio
and fuzz.QRatio
are based on the normalized Indel similarity. Not sure whether you have any specific questions into how they work.
from rapidfuzz.
Thanks a lot for your prompt answer and explanations @maxbachmann !
why would you use eval for this 😨 You can simply iterate over the functions
I knew, but I didn't know how to output functions' names in the next line of code.
I was rushy to post the question so I used strings for the names, and eval()
for this simple test.
Now I know I should use function.__name__
.
In your case fuzz.ratio/fuzz.QRatio return a similarity below 90 for each element.
Thanks, So I need to lower my cutoff and also read more carefully the defaults.
I misread and thought fuzz.ratio
was the default scorer
value for extract()
so the 1st two lines of my test 1 output looked inconsistent to me (but its default is actually fuzz.WRatio
, which explains their different output).
Changed cutoff to 70 and this is the output of 1st test:
String list (choices): ['Soliva sessilis auct., non Ruiz & Pav.', 'Soliva sessilis Ruiz & Pav.', 'Soliva']
- Result with no scorer (default scorer):
[('Soliva sessilis auct., non Ruiz & Pav.', 90.0, 0), ('Soliva sessilis Ruiz & Pav.', 90.0, 1), ('Soliva', 90.0, 2)]
+ Result when explicitly passing scorer=fuzz.ratio:
[('Soliva sessilis Ruiz & Pav.', 71.42857142857143, 1)]
+ Result when explicitly passing scorer=fuzz.WRatio:
[('Soliva sessilis auct., non Ruiz & Pav.', 90.0, 0), ('Soliva sessilis Ruiz & Pav.', 90.0, 1), ('Soliva', 90.0, 2)]
+ Result when explicitly passing scorer=fuzz.QRatio:
[('Soliva sessilis Ruiz & Pav.', 71.42857142857143, 1)]
That makes clear that I should use either choose fuzz.ratio
or fuzz.QRatio
for my use case.
fuzz.ratio and fuzz.QRatio are based on the normalized Indel similarity. Not sure whether you have any specific questions into how they work.
If it's not too advanced stuff yes, I'd like to know their difference (when using one or the other).
But I guess I'll better get how it works by example.
With my sample data above they both produce the same similarity values.
Any particular modification of my query that would produce differences between fuzz.ratio
and fuzz.QRatio
outputs?
... so I can figure out which of them suits better to what I want to do.
EDIT:
I had also pasted my example data but I guess this is not related to the issue title.
I better move it to discussions #347
from rapidfuzz.
I misread and thought fuzz.ratio was the default scorer value for extract() so the 1st two lines of my test 1 output looked inconsistent to me (but its default is actually fuzz.WRatio, which explains their different output).
Yes this is a bit inconsistent, since cdist
defaults to fuzz.ratio
, while extract
and extractOne
default to fuzz.WRatio
.
Any particular modification of my query that would produce differences between fuzz.ratio and fuzz.QRatio outputs?
They are pretty much exactly the same. The only difference between the two is the handling of empty strings.
>>> from rapidfuzz import fuzz
>>> fuzz.ratio("", "")
100.0
>>> fuzz.QRatio("", "")
0.0
In the past they had different defaults for the preprocessing function, but this was changed in v3.0.0.
from rapidfuzz.
Thanks a lot for explaining.
Issue solved!
from rapidfuzz.
Related Issues (20)
- 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.