class LexiconLexicon
class supports efficient lookup operations for words and prefixes.
| Constructor | |
| Lexicon() Lexicon(filename) | Initializes a new lexicon. |
| Methods | |
| size() | Returns the number of words contained in the lexicon. |
| isEmpty() | Returns true if the lexicon contains no words. |
| clear() | Removes all words from the lexicon. |
| add(word) | Adds the specified word to the lexicon. |
| addWordsFromFile(filename) | Reads the file and adds all of its words to the lexicon. |
| contains(word) | Returns true if word is contained in the lexicon. |
| containsPrefix(prefix) | Returns true if any words in the lexicon begin with prefix. |
| mapAll(fn) mapAll(fn, data) | Calls the specified function on each word in the lexicon. |
| Macro | |
| foreach(string word in lexicon) | Iterates over the words in the lexicon in alphabetical order. |
Lexicon(); Lexicon(string filename);
English.dat
containing a list of words in English. The standard code pattern
to initialize that lexicon looks like this:
Lexicon english("English.dat");
Usage:
Lexicon lex; Lexicon lex(filename);
int size();
Usage:
int n = lex.size();
bool isEmpty();
true if the lexicon contains no words.
Usage:
if (lex.isEmpty()) . . .
void clear();
Usage:
lex.clear();
void add(string word);
Usage:
lex.add(word);
void addWordsFromFile(string filename);
Usage:
lex.addWordsFromFile(filename);
bool contains(string word);
true if word is contained in the
lexicon. In the Lexicon class, the case of letters is
ignored, so "Zoo" is the same as "ZOO" or "zoo".
Usage:
if (lex.contains(word)) . . .
bool containsPrefix(string prefix);
prefix.
Like containsWord, this method ignores the case of letters
so that "MO" is a prefix of "monkey" or "Monday".
Usage:
if (lex.containsPrefix(prefix)) . . .
void mapAll(void (*fn)(string value));
void mapAll(void (*fn)(string value, ClientDataType & data),
ClientDataType & data);
Usage:
lexicon.mapAll(fn); lexicon.mapAll(fn, data);
foreach (string word in lexicon) . . .