Skip to content

Difference between java and python implementation: Spoiler, the problem is the round #99

@timotta

Description

@timotta

Here is the example where I was stuck. The python implemention gets 22, and the java implementation gets 23:

fuzz.token_set_ratio(
  "Vêndo ou troco por outro carro pode ser atrasado negócio volta ",
  "Titan 150 ano 2005 ", 
  False
)
FuzzySearch.tokenSetRatio(
  "Vêndo ou troco por outro carro pode ser atrasado negócio volta", 
  "Titan 150 ano 2005"
);

Debugging both code I could find that the problem is when rounding the value: 22.5

Python code, located in utils.py:

int(round(n))

Java code, located in SimpleRatio class is:

(int) Math.round(100 * DiffUtils.getRatio(s1, s2));

TLDR:

Java: Math.round(22.5) => 23
Python: round(22.5) => 22

Don't know which one is correct for this algorithm...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions