You should change your approach:
levenshtein Distance is useful in calculating the similarity in units, or they are “characters” or “words”.
Conceptually, you consider Alabama and the university (2 words) as 2 units, and you want to calculate the distance between words for which the levenshtein distance should mean how many words are between Alabama and the University, which should be 1.
But you are trying to apply the levenshtein algorithm, which is implemented for characters within a word. This implementation will only work for matching single words of NOT sentences.
Better you have to implement your own levenshtein algorithm (using BK-Tree) for the "words" above and inside each match, you again match each word using levenshtein for the "characters".
your result for (1) should match distance 1 with this algorithm and No match for (2).
mathsRuinedme
source share