Hi all,

I have a database of about 150.000 string literals per day, and I need to group the similars ones into clusters.

I'm currently using the String::Similarity perl module. It works fine but I have some performance problems. With a 5000 literal collection the system takes 3minutes more or less.

Update:Consider I have 5000 news headlines and I want to group them by similarity. I actually want to cluster all headlines 80% similars. To speed up the process, I don't compare the headlines its headlines length if greater than 20%.

My code looks like:
... my $docsProcessed; my $size = scalar (@{$arrayDocs}); for (my $i = 0; $i < ($size - 1); $i++) { # next if already processed next if (defined $docsProcessed->{$arrayDocs->[$i]}); for (my $j = $i + 1; $j < ($size - 1); $j++) { next if (defined $docsProcessed->{$arrayDocs->[$j]}); $similarity = similarity($arrayDocs->[$i], $arrayDocs->[$j], $se +lf->{THRESHOLD}); if ($similarity >= $self->{THRESHOLD}) { # Add the processed document into the cluster push (@{$clusters->{$arrayDocs->[$i]}}, $arrayDocs->[$j]); # Add the document to the processed hash $docsProcessed->{$arrayDocs->[$j]} = 1; } } } ...

I just wanted to know if there is other method, other modules o anything to speed up this process as much as possible.

Thank you very much

In reply to Fast string similarity method by icanwin

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.