hi, I'm parsing documents,each of them has a location
written on them.
There is a slight problem as people write differently
their location.
A friend suggested some time ago using Levenshtein's
algorithm for getting the edit distance between words
if needed.
I used that to establish similarity between words
calculating to know if they belong to a certain class.
So,what I'm trying to do:
Having a list of inconsistent locations,divide them into
equivalence classes choosing an appropriate representant
for each of the classes.
In doing so ,I have used a hash and a similarity function
wich establishes if two words are similar or not like this:

f(w1,w2) return 1 if w1 is contained in w2 return 1 if w2 is contained in w1 return edit_distance(w1,w2)/length(w2) < 0.34 ? 1 : 0
I have a hash whose keys are representants of an equivalence
class and whose values are the classes themselfes.
And after words are classified for a first time. The classes suffer a further re-merging.

Here is the script wich does this.
Here is a information sample on wich it runs.
These are the results I got.
The results are pretty much ok,but they need to be improved.
Questions : are there articles regarding this problem, wich present better solutions? How can I optimise this one ?
Any suggestions are welcome
PS:you can decomment line 92 to make it not process all the file and run faster.
EDIT:
corrected problem in the f function above instead
of > it's <


In reply to separating text words in similarity classes using levenshtein by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.