Pages

24 juil. 2008

Levenshtein distance

Par Gary de la liste applescript-users@lists.apple.com

La distance de Levenshtein est égale au nombre minimal de caractères qu'il faut supprimer, insérer, ou remplacer pour passer d’une chaîne à l’autre.

on LEVENSHTEIN_DISTANCE(thisText, thatText)
set phpScr to "$lev=levenshtein('" & thisText & "', '" & thatText & "');echo $lev;"
set shCmdStub to "php -r "
set sh to shCmdStub & (quoted form of phpScr)
set res to do shell script sh
end LEVENSHTEIN_DISTANCE


LEVENSHTEIN_DISTANCE("the", "they") --> 1
LEVENSHTEIN_DISTANCE("hello world", "hell worm") --> 3

>>Ouvrir le script dans l'éditeur

En savoir plus ...

Aucun commentaire: