First for making it more efficient.stem_in_place is a very good fit for this. however,because it will modify all your words you should have a way to keep track of the initial words. you can choose to make something like:

my @words_stemmed = @words; $stemmer->stem_in_place(\@words_stemmed); my @all; # will contain hashrefs like { original => 'books' , stemmed +=> 'book' } map{ +{ original => $words[$_], stemmed => $words_stemmed[$_], }; } 0..-1+@words;

I also think you should use ->stem_in_place with some kind of global cache(but that would mean adding this to the .xs if it's not already there).

For performance related issues you can use Gearman or POE to distribute the work on many machines.It's not a surprise that just "counting words" is time-consuming, a lot of things in NLP are.

PetaMem here on Perlmonks also does NLP so maybe he can also give some details on how this can be improved

UPDATE: took a closer look to the OP , read more carefuly


In reply to Re: finding a set of relevant keys by spx2
in thread finding a set of relevant keys by ericleasemorgan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.