newbio has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, My question is about a faster way to do phrase matching in a sentence. + The usual standard way would be: $sentence="Jack and Jill went up the hill to fetch a pail of water."; $sentence=~/pail of water/\#pail of water\#/g; #tag the phrase 'pail o +f water' in the sentence. However, the above method becomes too slow when I have a long list of +phrases and also sentences. If I have single words instead of phrases +, I could use hash matching on 'split' sentence words, such as: @temp=split(' ', $sentence); my %hash=("pail of water"=>1); foreach my $i (@temp) { if ($hash{$i}) { --- } } However, this method cannot be applied to phrases. Can something simil +ar/faster be used for phrase tagging of sentences? On a related note, how to club the words of the marked phrase in the s +entence as a single unit (i.e. the phrase appears in a single array e +lement when the split is done on the sentence on the space character) +. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: phrase marking
by kyle (Abbot) on Sep 09, 2008 at 16:42 UTC | |
by newbio (Beadle) on Sep 09, 2008 at 17:25 UTC | |
by kyle (Abbot) on Sep 09, 2008 at 18:49 UTC | |
by newbio (Beadle) on Sep 10, 2008 at 18:51 UTC | |
by kyle (Abbot) on Sep 10, 2008 at 19:31 UTC | |
|
Re: phrase marking
by JadeNB (Chaplain) on Sep 09, 2008 at 17:05 UTC | |
|
Re: phrase marking
by toolic (Bishop) on Sep 09, 2008 at 17:19 UTC |