ericleasemorgan,
You're data structure doesn't allow short circuiting. You could do a 1 time pass of %words and create a parallel data structure that would make subsequent searches a hash lookup. Something like this:
my %stems;
for my $word (keys %words) {
my $stem = $stemmer->stem($word);
$stems{$stem} += $words{$word};
}
for my $idea (@ideas) {
my $stem = $stemmer->$stem($idea);
my $val = $stems{$stem} || 0;
print "$idea\t$val\n";
}
Of course, if %words is constantly changing then so must %stems. There are ways to do this (tied hashes for instance) or just a better datastructure (tree versus hash). As far as better stemming library - the library you are using does support exceptions. When you say you are going to run the program 10K times, it makes me wonder if you mean each time it is only going to get the value of a single word. That would obviously be inefficient. It would be better to serialize (freeze/thaw) your data structure so you don't pay the runtime performance penalty of converting the hash.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.