Here's a pretty simple way to score the matching. Convert the array of search terms to a regex alternation and count the number of matches for each datum:
my @guesses = ('Place De La Gare', 'Rennes'); my $grei = do { # this case insensitive re added local $" = '|'; qr/@{[map {quotemeta} @guesses]}/i; }; my $gre = do { local $" = '|'; qr/@{[map {quotemeta} @guesses]}/; }; my %score; for (@data) { $score{$_} = () = m/($grei)/g; # edited. # $score{$_} += () = m/($gre)/g; # uncomment to give extra # credit for exact match } # sort keys by value or grep for threshold to pick best matches
Update: Case insensitivity was being overruled by the compiled $gre. Repaired. Got rid of non-capture grouping and added quotemeta to defang special characters in the data. More: Added the '()=" trick to force array context - that fixes the counts.
After Compline,
Zaxo
In reply to Re: Guessing/Ordering Partial Data
by Zaxo
in thread Guessing/Ordering Partial Data
by ropey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |