Search code examples
pythonsearchsearch-enginesimilarity

python search technology: word similarity


I want to get a similarity percentage of two words, eg)

abcd versus zzabcdzz == 50% similarity

Don't need to be very accurate. Is there any way to do that? I am using python but feel free to recomment other languages.


Solution

  • Try using python-Levenshtein to calculate the edit distance.

    The Levenshtein Python C extension module contains functions for fast computation of

    • Levenshtein (edit) distance, and edit operations
    • string similarity
    • approximate median strings, and generally string averaging
    • string sequence and set similarity

    You can get a rough idea of similarity by calculating the edit distance between the two strings divided by the length of the longest string. In your example the edit distance is 4, and the maximum possible edit distance is 8, so the similarity is 50%.