|Syntactic Confectionery Delight|
Finding dictionary words in a string.by ehdonhon (Curate)
|on Mar 13, 2004 at 04:07 UTC||Need Help??|
ehdonhon has asked for the
wisdom of the Perl Monks concerning the following question:
I have a lot of strings which are potentially nonsense, but might contain a few english words. For example:
owijfwapplelaskfiwejfcherryalkfwiofwfblossomowiejfcontains the words "apple", "cherry" and "blossom".
My job is to score each string so that strings that are composed entirely of words get a better score than strings that are not. Strings with the fewest number of words will also get a higher score than strings with many words.
Is this a job for recursive descent parsing, or is there a faster way to be doing this? For this task, I am willing to trade off a little accuracy for speed. I'm trying to remember back to my cryptography class to think if there was any kind of algorithm to decide if a string was likely to be an english word.
My dictionary is going to consist of about 250,000 words. I can store them on the disk in any fashion I want. Is there any kind of format (perhaps some db file format) that would lend itself well to the kind of lookups that I am going to need to be doing?
I see there is a Text::ExtractWords module on CPAN, but it doesn't seem to be actually implemented. There is also Games::TrackWord, but it wants me to loop through every single dictionary word to try to find it. That would take too long. Is there a CPAN module that would be a good fit for me?