Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
P is for Practical
 
PerlMonks  

Re: Finding duplicate text in a paragraph

by davido (Bishop)
on Aug 20, 2012 at 20:57 UTC ( #988508=note: print w/ replies, xml ) Need Help??


in reply to Finding duplicate text in a paragraph

This is related to the Longest Repeated Substring Problem. According to the article I linked to, the problem can be solved in linear time after building a Suffix Tree. It turns out there's a module on CPAN that works with suffix trees: Tree::Suffix.

Tree::Suffix is a big pain to install. You have to visit http://www.icir.org/christian/libstree/, download and unpack its tarball, and then sudo ./configure. After it's installed you have to force the installation of Tree::Suffix: cpanm -f Tree::Suffix. I haven't taken the time to uncover what's wrong with it that causes some failures. But it seems to work once installed.

After that's all said and done, it becomes easy:

use Tree::Suffix; my $string = 'The cat jumped over the dog. Smart cat! He jumped over the dog. + ' . 'The cat jumped over the dog.'; my $tree = Tree::Suffix->new($string); print "$_\n" for $tree->lrs;

The output...

The cat jumped over the dog.

$tree->lrs is a convenient alias to $tree->longest_repeated_substrings; you can use either method name.

If anyone knows of a better module for building suffix trees (one that installs cleanly), please follow-up with suggestions.

An aside: If anyone knows how to get in touch with the author for SuffixTree please let me know. His listed email address is no longer valid. I've also sent a message to module-authors@perl.org trying to locate him so that I can work on applying the patches that have been sitting for a few years in the RT. In the meantime an unofficial release has been uploaded.


Dave


Comment on Re: Finding duplicate text in a paragraph
Select or Download Code
Re^2: Finding duplicate text in a paragraph
by Jester (Novice) on Aug 20, 2012 at 21:00 UTC
    Interesting module and article. This is more what I was looking for! Thanks a lot, I'll look into it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2013-05-18 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (396 votes), past polls