Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Fuzzy searching

by jaxz (Initiate)
on May 18, 2000 at 19:41 UTC ( #13032=perlquestion: print w/replies, xml ) Need Help??
jaxz has asked for the wisdom of the Perl Monks concerning the following question:

I have a flat datafile containing a variety of fields, mostly with text data to which I have written a CGI access program that appends the file with user inputted data. Before the file is updated, I want to run a check to see if the data being entered has been repeated elsewhere. The trick is that although the data might not have been repeated in the exact same form, I want the check to see if the newly entered data looks *similar* to existing data rather than exactly the same. So I'm looking for a fuzzy search algorithm, nothing too complex, but robust enough to catch possible repetitions in the data. Any help, greatly appreciated... jaxz

Replies are listed 'Best First'.
Re: Fuzzy searching
by lhoward (Vicar) on May 18, 2000 at 20:16 UTC
    turnstep's suggestion is excelent. There are 2 other modules you may want to check out:
    1. Text::Soundex - good for determining is words sound-alike
    2. Text::Metaphone - better algorithm that Text::Soundex and good for phrases
    You didn't say in your question if the "similar data" you're trying to match is strings or not. If it is numeric a simple +- %5 type algorithm would work well for determining similarity. For comparing strings one of the simplest algorithms you can use is ignoring case ("ANOTHER MAN DOWN" and "Antoher Man Down" are considered the same thing). Its not very powerful but it is very easy to do.

    Different algorithms may work better depending on exactly what piece(s) of data you want to de-duplicate on. If you're deduplicating on multiple fields some sort of hybrid de-duplication algorithm may be best. Here's an example deduplication scheme I cooked up for a database of people, where they live, and what their income is:

    (String::Approx of LAST_NAME the same) and (INCOME within %5) and (STATE the same)
    In my experience coming up with a de-duplication scheme for user-entered data is easy. Coming up with a good one is hard and may take weeks or months of tuning.
      Thanks for the hints - it sounds like the metaphone module might be what I need as the data is text, and in sometimes quite long phrases where the variation might be word order, similar but not necessarily all matching words and so on. I'll look it up. The ignoring case would not really be sufficient in this instance.
Re: Fuzzy searching
by turnstep (Parson) on May 18, 2000 at 19:53 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://13032]
Approved by root
help
Chatterbox?
[LanX]: but but but ... the errors are nicely formatted!
[tye]: 1) The python stack traces show you the names of variables, not the values of variables. Almost never informative.
[LanX]: do you have a py job now?
[tye]: Right now I have errors trying to fetch stuff from graphite. It says 'apps not ready, check startup logs'. I eventually find the startup logs and see 'no apps found'. Looking for fixes to this problem...
[LanX]: no idea ... ask py monks! ;-p
[tye]: it turns out that this can be caused by almost anything going wrong. If you want to know what caused the problem, you have to try to load each app by-hand to see what problems it is having, because none of those will be logged.
[tye]: No, I write more Perl than py at work. But I have to deal with plenty of py things.
[tye]: py monks would just be offended.
[Corion]: ;)
[Corion]: Hi tye btw ;)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-09-21 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (252 votes). Check out past polls.

    Notices?