rajaman has asked for the wisdom of the Perl Monks concerning the following question:
#terms ID|related terms delimited by '|' 1|Tesla S|Tesla model V|Tesla model|Tesla 2|Ford RAM truck|2020 Ford Mustand|Ford ranger|Ranger|ford|2020 Ford F +-250|2020 Ford F250|Ford F 250 3|GM Chevrolet|GM Chevy|GM Chevrolet 2020|Chevrolet|Chevy|Chevrolet 20 +20|GM Chevrolet volt|Chevrolet Captiva Sport|General motors|GM . . Program input: ... 2020 Ford F 250 is great but I prefer Tesla Model-V + ... Desired output: ... <2><2020 Ford F 250> is great but I prefer <1><Tes +la model-V> ... #<2> and <1> are the IDs for the terms
Please suggest how to do this an efficient and fast way?$term1 = 'Tesla S|Tesla model V|Tesla model|TESLA'; $term2 = 'Ford RAM truck|2020 Ford Mustand|Ford ranger|Ranger|ford|202 +0 Ford F-250|2020 Ford F250|Ford F 250'; term1 =~ s/\-/ /g; term2 =~ s/\-/ /g; $input = '... 2020 Ford F 250 is great but I prefer Tesla Model-V ...' +; $input =~ s/\-/ /g; $input =~ s/($term1)/\<1\>\<$1\>/ig; $input =~ s/($term2)/\<2\>\<$1\>/ig; . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching terms in text
by Corion (Patriarch) on Apr 23, 2020 at 21:05 UTC | |
|
Re: Matching terms in text
by haukex (Archbishop) on Apr 23, 2020 at 21:25 UTC | |
|
Re: Matching terms in text
by AnomalousMonk (Archbishop) on Apr 24, 2020 at 00:33 UTC |