NAME
Game::WordBrain::Prefix - Creates a Cache of Valid Word Prefixes
SYNOPSIS
# Create new Prefix Cache
my $prefix = Game::WordBrain::Prefix->new({
max_prefix_length => 5, # Optional
word_list => '/path/to/wordlist', # Optional
});
# Test if a string could be the start of a word
my $start_of_word = 'fla';
if( $prefix->is_start_of_word( $start_of_word ) ) {
print "Could be a word...";
}
else {
print "Nope, no way this is going to be a word.";
}
DESCRIPTION
Game::WordBrain::Prefix is the largest speedup afforded to the Game::WordBrain->solve method. It works by reading in a wordlist and using it to construct a hash of valid word prefixes. As an example, let's take the word "flag"
{
'f' => 1,
'fl' => 1,
'fla' => 1,
'flag' => 1,
}
By creating this Game::WordBrain is able to check if the current path being walked ( collection of Game::WordBrain::Letters ) could possibly ever be a real word. By leverage the fact that, for example, no word in the english language starts with 'flaga' we can short circuit and abandon a path that will not lead to a solution sa fast as possible.
ATTRIBUTES
max_prefix_length
The length of the prefixes to build. This should equal the max Game::WordBrain::WordToFind->{num_letters}. If not provided, it defaults to 8.
Keep in mind, the larger this value the longer the spin up time needed in order to run the solver.
word_list
Path to a new line delimited word_list. If not provided, the wordlist provided with this distrubtion will be used.
METHODS
new
my $prefix = Game::WordBrain::Prefix->new({
max_prefix_length => 5, # Optional
word_list => '/path/to/wordlist', # Optional
});
If the max_prefix length is not specified it will default to 8. If no word_list is specified then the bundled wordlist will be used.
Returns an instance of Game::WordBrain::Prefix
is_start_of_word
my $prefix = Game::WordBrain::Prefix->...;
my $start_of_word = 'fla';
if( $prefix->is_start_of_word( $start_of_word ) ) {
print "Could be a word...";
}
else {
print "Nope, no way this is going to be a word.";
}
Given a string, will check to seeif there are any words in the provided word_list that start with this string. If there are ( meaning this could become a real word at some point ) a truthy value is returned. If not, a falsey value is returned.