Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: extract phrases of n-words length

by Polyglot (Pilgrim)
on Jun 24, 2009 at 15:37 UTC ( #774431=note: print w/replies, xml ) Need Help??


in reply to extract phrases of n-words length

I might do it something like this:
my $abstract = 'Perl is a high-level, general-purpose, interpreted, dynamic programming language.'; my $maxphraselength = 4; my $minphraselength = 2; my %phrasearray; my ($i,$offset); $abstract =~ s/\n|\r//g; for ($i=$minphraselength; $i<$maxphraselength; $i++) { for ($offset=0; $offset<$i; $offset++) { while ($abstract =~ /(\w+\W+){$offset}((\w+\W+){$i})/) { $phrasearray{$2}++; } } } foreach(keys %phrasearray){ print $_."\n"; } #sample output
Would that work?

Blessings,

~Polyglot~

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://774431]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-06-18 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (109 votes). Check out past polls.

    Notices?