|
|
| P is for Practical | |
| PerlMonks |
Re: Finding duplicate text in a paragraphby davido (Bishop) |
| on Aug 20, 2012 at 20:57 UTC ( #988508=note: print w/ replies, xml ) | Need Help?? |
|
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:
The output...
$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
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||