Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Some kind of fuzzy logic.

by BrowserUk (Patriarch)
on Oct 17, 2003 at 21:20 UTC ( [id://300172]=note: print w/replies, xml ) Need Help??


in reply to Some kind of fuzzy logic.

This might serve as a starting point.

#! perl -slw use strict; sub genRegex { my $query = shift; $query =~ tr[A-Za-z0-9 ][a-za-z0-9 ]; my @words = split ' ', $query; my $regex = join '\W+'.$/, map{ my $s=''; $s = "(?:$_$s)?" for reverse split ''; chop $s; "\\b$s\\b" } @words; return qr[$regex]xi; } my $regex; while( my $line = <DATA> ) { chomp $line; $regex = genRegex( $1 ) and print'' and next if $line =~ m[search for (.*) should match...]; print +($line =~ $regex ? 'Matched ' : 'Failed ' ), $line; } __DATA__ search for Aetna Insurance Company should match... Aetna Insurance Company Aetna Ins. Co. Aetna Insurance Co. Aetna Ins. Company Aetna Ins Company aetna insurance co Aetna Ins Co Atna Insurance Company Aetna Ins. Ca. Aetna Insurance Go. Aetna Ins. Compary search for Sam Jones should match... Sam Jones Sam J. Jones Sam J Jones S. Jones Samuel Janes Sam L Jones Sam J.J. Jones Sam J Jones B. Jones Manuel Jones

Results:

P:\test>junk Matched Aetna Insurance Company Matched Aetna Ins. Co. Matched Aetna Insurance Co. Matched Aetna Ins. Company Matched Aetna Ins Company Matched aetna insurance co Matched Aetna Ins Co Failed Atna Insurance Company Failed Aetna Ins. Ca. Failed Aetna Insurance Go. Failed Aetna Ins. Compary Matched Sam Jones Matched Sam J. Jones Matched Sam J Jones Matched S. Jones Failed Samuel Janes Failed Sam L Jones Matched Sam J.J. Jones Matched Sam J Jones Failed B. Jones Failed Manuel Jones

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re: Re: Some kind of fuzzy logic.
by the_0ne (Pilgrim) on Oct 18, 2003 at 02:27 UTC
    Thanks everybody for your help. I'll try out your example BrowserUK.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://300172]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found