String Similarity (Levenshtein)
From Erlang Community
| Revision as of 16:15, 27 October 2006 (edit) 213.171.204.166 (Talk) (→Solution) ← Previous diff |
Revision as of 03:44, 4 December 2006 (edit) (undo) Kaiserpanda (Talk | contribs) m Next diff → |
||
| Line 70: | Line 70: | ||
| [[Category:CookBook]][[Category:StringRecipes]] | [[Category:CookBook]][[Category:StringRecipes]] | ||
| + | |||
| + | |||
| + | |||
| + | [http://www.magical-casino.com/no_deposit.html Casinos with no deposit required.] | ||
| + | [http://www.web-craps.com craps] | ||
| + | [http://www.bestweb-online-casinos.com/slots-game/diamond-club-slots.html diamond club slots] | ||
| + | [http://www.slots-wiki.com/index.php/slots_hints slots hints] | ||
| + | [http://www.fortune-slots.com/ slots online] | ||
| + | [http://www.gambling-online-theory.com/fortune-roulette/on-line-roulette-game.html on line roulette game] | ||
| + | [http://www.casino-games-wiki.com/index.php/online_casino_games online casino games] | ||
| + | [http://www.casino-games-wiki.com/index.php/on_line_casino_games on line casino games] | ||
| + | [http://www.magical-casino.com/casino_risk.html Gambling Online - Risks.] | ||
| + | [http://www.fortune-slots.com/ slots] | ||
Revision as of 03:44, 4 December 2006
Problem
You need to compare two strings and get an index of how similar they are.
Solution
This module implements the Levenshtein edit distance algorithm (described more here). In short, it calculates the number of edit steps that are needed to transform the source string to the target string. The lesser the more similiar.
%%%============================================================================= %%% @author Adam Lindberg |
You can use the levenshtein function to compare two strings.
2> string_metrics:levenshtein("Aloha!", "Alhoa!").
2
3> string_metrics:levenshtein("adam", "Adam").
1
4> string_metrics:levenshtein("adam", "Assam").
3
5> string_metrics:levenshtein("teh", "the").
2
6> string_metrics:levenshtein("the", "the").
0
7> string_metrics:levenshtein("the", "").
3
|
Note that the function is not case insensitive (and the algorithm isn't either), though you can always use the httpd_util library to_lower or to_upper functions to put the two strings on an equal footing:
8> string_metrics:levenshtein(httpd_util:to_lower("Adam"), "adam").
0
|
Casinos with no deposit required. craps diamond club slots slots hints slots online on line roulette game online casino games on line casino games Gambling Online - Risks. slots

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

