Python search technology: word similarity

I want to get the percentage of similarity of two words, for example)

abcd versus zzabcdzz == 50% similarity

No need to be very precise. Is there any way to do this? I use python but don't want to rewrite other languages.

+3
source share
4 answers

Try using python-Levenshteinto calculate the editing distance .

The Levenshtein Python C extension module contains functions for quick computation

  • Levenshtein (edit) distance and edit operations
  • string similarity
  • approximate median lines and usually line averaging
  • sequence of strings and establish similarity

, , . 4, - 8, 50%.

+6

python difflib

>>> s = SequenceMatcher(None, "abcd", "bcde")
>>> s.ratio()
0.75
+3

:

Python difflib.

difflib SequenceMatcher, , . :

def text_compare(text1, text2, isjunk=None):
    return difflib.SequenceMatcher(isjunk, text1, text2).ratio()
0

Source: https://habr.com/ru/post/1791640/


All Articles