zod has asked for the wisdom of the Perl Monks concerning the following question:
I have a file that has a list of words on each line, let's say:
dog monkey cat cat ball stone monkey iron cat zoo
What I need to do is find out which two-word combinations (order does not matter) on each line are most common in the file.
So I need to generate all pair combinations for each line and then figure out which pair combo is the most common over all the lines.
So, the first line should generate:
dog monkey dog cat monkey cat
I figured I should dump each line into an array and then generate the pair combos for each array. So, I started with tye's Finding all Combinations node:
http://www.perlmonks.org/?node_id=128293
But, alas, I'm stuck already as I'm not sure how to generate only _pair_ combinations rather than every possible combo.
Can anyone point me in the right direction? My spidey sense tells me I should use a hash. But not sure where to start...
Thanks much,
Zod
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding Combinations of Pairs
by kyle (Abbot) on Jan 14, 2009 at 03:46 UTC | |
by tilly (Archbishop) on Jan 14, 2009 at 05:15 UTC | |
by grinder (Bishop) on Jan 14, 2009 at 08:38 UTC | |
by Limbic~Region (Chancellor) on Jan 14, 2009 at 15:03 UTC | |
by andye (Curate) on Jan 14, 2009 at 17:21 UTC | |
by Limbic~Region (Chancellor) on Jan 14, 2009 at 18:57 UTC | |
by tilly (Archbishop) on Jan 14, 2009 at 20:54 UTC | |
| |
by zod (Scribe) on Jan 14, 2009 at 07:23 UTC | |
by andye (Curate) on Jan 14, 2009 at 23:14 UTC | |
Re: Finding Combinations of Pairs
by BrowserUk (Patriarch) on Jan 14, 2009 at 08:52 UTC | |
Re: Finding Combinations of Pairs
by repellent (Priest) on Jan 14, 2009 at 18:23 UTC |