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.
Try using python-Levenshteinto calculate the editing distance .
python-Levenshtein
The Levenshtein Python C extension module contains functions for quick computationLevenshtein (edit) distance and edit operationsstring similarityapproximate median lines and usually line averagingsequence of strings and establish similarity
The Levenshtein Python C extension module contains functions for quick computation
, , . 4, - 8, 50%.
python difflib
>>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75
nltk:
http://www.opendocs.net/nltk/0.9.5/api/nltk.wordnet.similarity-module.html
:
Python difflib.
difflib SequenceMatcher, , . :
difflib
def text_compare(text1, text2, isjunk=None): return difflib.SequenceMatcher(isjunk, text1, text2).ratio()
Source: https://habr.com/ru/post/1791640/More articles:How can I handle paid memberships safely? - djangoASP.NET Web Form Render Engine displays control tree? Finding Information About Rendering Logic - asp.netMargin does not press another margin - cssThread-priority multithreading and synchronization - javaWhat are the options for using temporary tables in SQL database systems? - sqlзакрыть все сокеты после использования? на стороне сервера - javaList Generation Erlang - listPerl Linux :: Inotify2 - can no longer respond to events - eventshow to get unique values from a list of duplicate values - pythonКак получить "широту" и "долготу" для адреса? Карты Гугл - mapsAll Articles