Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement optimal string alignment algorithm #19

Open
logannc opened this issue Oct 6, 2020 · 2 comments
Open

Implement optimal string alignment algorithm #19

logannc opened this issue Oct 6, 2020 · 2 comments
Assignees
Milestone

Comments

@logannc
Copy link
Owner

logannc commented Oct 6, 2020

See rapidfuzz/RapidFuzz#13 for generous details from another fuzzywuzzy compatible project author.

Essentially, partial_ratio attempts to align strings optimally, then take the ratio of the aligned string subsets. The method of alignment used in fuzzywuzzy is.. pretty bad, actually.

Implement Smith-Waterman for sequence alignment to power partial_ratio. Legacy partial_ratio behaviour will be relegated to a compatibility function (which, if there are more, might be put into a compatibility module).

@logannc
Copy link
Owner Author

logannc commented Oct 11, 2020

Example of a random python Smith-Waterman alignment:

>>> sw.align("what about supergreatfantastic theatre", "superduperfantastic theater about what").dump()
Query:  1 superdupe-rfantastic theater 27
          ||||| ..| .||||||||||||||| |
Ref  : 12 super-greatfantastic theat-r 37

Score: 38
Matches: 22 (78.6%)

This seems clearly superior to the existing alignment algorithm.

@logannc
Copy link
Owner Author

logannc commented Oct 11, 2020

In particular when comparing the following:

>>> sw.align("what about superduperfantastic", "superduperfantastic about what").dump()
Query:  1 superduperfantastic 19
          |||||||||||||||||||
Ref  : 12 superduperfantastic 30

Score: 38
Matches: 19 (100.0%)
Mismatches: 0
CIGAR: 19M
>>> partial_ratio("what about superduperfantastic", "superduperfantastic about what")
63

@seanpianka seanpianka added 1.0.0 Road to 1.0.0 and removed 1.0.0 Road to 1.0.0 labels Nov 2, 2020
@seanpianka seanpianka added this to the 1.1 milestone May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants