Git Product home page Git Product logo

Comments (2)

maxbachmann avatar maxbachmann commented on September 27, 2024 1

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.

koenvanbenthem avatar koenvanbenthem commented on September 27, 2024

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)

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.