|P is for Practical|
Re: Finding duplicate text in a paragraphby davido (Bishop)
|on Aug 20, 2012 at 20:57 UTC||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:
$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 email@example.com 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.