ropey has asked for the wisdom of the Perl Monks concerning the following question:
Hi All
I have a part of an application, where from a given (partial) user input a best guess should be made to match what the user is searching for.
In this example its in terms of locations, so the user wants to look for a given sub set of locations in say Paris, given that they have entered Paris, and optional search terms of 'Place De La Gare' and 'Rennes'. From the Paris part the application can simply find all Paris entries, lets say its the following subset of data
A simple script to *guess* from the subset is as follows
#!/usr/bin/perl -w use strict; use Data::Dumper; my @data = ( 'Place De La Gare - Angers', 'Place De La Gare - Nevers', 'Place Mohammed V - Oujda', 'Place De La Gare - Rennes', 'Place de la Gare - Quimper', 'Place Thiers - Nancy', 'Place De La Gare - Grenoble', 'Place Du Chateau - Galerie Marchande Du Rer', 'Place De La Gare - Angers', 'Place De La Gare 1 - Bannes Grenoble', 'Place De La Gare - Nevers', 'Place De La Gare - Rennes', 'Place De La Gare bannes', 'Place de la Gare', 'Place de la Gare - Bergerac', 'Place de la Gare - Moutiers', 'Place de la Gare - Libourne' ); my @guesses = ('Place de la Gare', 'Rennes'); my @list = @data; foreach my $guess(@guesses) { my @guessed = grep { /$guess/i } @list; # Now guess in reduced list @list = @guessed; } print "Guess this is what you wanted ? ", join "\n", @list;
Is there a better way, given this is a reduced subset of the real data (could be hundreds of possible choices) and multiple words to reduce the guessing ?
The next step would be to start weighting the guesses, in this case it will remove anything which is not a exact match to the terms, any *clean* ways of doing the weighting ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Guessing/Ordering Partial Data
by Zaxo (Archbishop) on Apr 13, 2005 at 03:48 UTC | |
by ropey (Hermit) on Apr 13, 2005 at 04:11 UTC | |
|
Re: Guessing/Ordering Partial Data
by toma (Vicar) on Apr 13, 2005 at 06:57 UTC | |
|
Re: Guessing/Ordering Partial Data
by johnnywang (Priest) on Apr 13, 2005 at 06:45 UTC | |
|
Re: Guessing/Ordering Partial Data
by bageler (Hermit) on Apr 13, 2005 at 13:55 UTC | |
|
Re: Guessing/Ordering Partial Data
by mattr (Curate) on Apr 14, 2005 at 07:29 UTC | |
|
Re: Guessing/Ordering Partial Data
by johnnywang (Priest) on Apr 13, 2005 at 17:13 UTC |