Lexicon Class Reference

#include "lexicon.h"

List of all members.

Public Member Functions

 Lexicon ()
 Lexicon (string filename)
 ~Lexicon ()
int size ()
bool isEmpty ()
void add (string word)
void addWordsFromFile (string filename)
bool containsWord (string word)
bool containsPrefix (string prefix)
void clear ()
template<typename ClientDataType>
void mapAll (void(fn)(string word, ClientDataType &), ClientDataType &data)
 Lexicon (const Lexicon &rhs)
const Lexiconoperator= (const Lexicon &rhs)
template<typename ClientDataType>
void recMapAll (Edge *edge, bool first, string soFar, void(fn)(string word, ClientDataType &), ClientDataType &clientData)

Classes

struct  Edge


Detailed Description

This class is used to represent a lexicon, or word list. The main difference between the lexicon abstraction and a map or dictionary container is that the lexicon does not provide any mechanism for storing definitions of words; the lexicon contains only words, with no associated information. The lexicon supports very efficient lookup operations for words and prefixes. You can populate the lexicon by adding words one at a time or by constructing a lexicon with words read from a file. Here is sample use of a Lexicon object:

Lexicon lex("lexicon.dat"); // read words from lexicon.dat file lex.add("doughnut"); if (lex.containsPrefix("fru") || lex.containsWord("ball")) ...


Constructor & Destructor Documentation

Lexicon::Lexicon (  ) 

The constructor initializes a new empty lexicon.

Lexicon::Lexicon ( string  filename  ) 

The constructor initializes a new lexicon which is populated with the words read from the specified file. The file is expected to be either a special special binary format that represents a saved lexicon or a plain text file of words, one word per line. The constructor reads the file and adds all of its words to this lexicon. The file must be in the same folder as the program to be found. If the file doesn't exist or is malformed, Error is called to exit the program.

Lexicon::~Lexicon (  ) 

The destructor deallocates any storage associated with the lexicon.

Lexicon::Lexicon ( const Lexicon rhs  ) 

This copy constructor and operator= are defined to make a deep copy, making it possible to pass/return lexicons by value and assign from one lexicon to another. The entire contents of the lexicon, including all words, are copied. Making copies is generally avoided because of the expense and thus, lexicons are typically passed by reference, however, when a copy is needed, these operations are supported.


Member Function Documentation

int Lexicon::size (  ) 

This member function returns the number of words contained in this lexicon.

bool Lexicon::isEmpty (  ) 

This member function returns true if this lexicon contains no words, false otherwise.

void Lexicon::add ( string  word  ) 

This member function adds the specified word to this lexicon.

void Lexicon::addWordsFromFile ( string  filename  ) 

This member function reads the file and adds all of its words to this lexicon. The file is expected to be either a special special binary format that represents a saved lexicon or a plain text file of words, one word per line. The file must be in the same folder as the program to be found. If the file doesn't exist or is malformed, Error is called to exit the program.

bool Lexicon::containsWord ( string  word  ) 

This member function returns true if word is contained in this lexicon, false otherwise. Words are considered case-insensitively, "zoo" is the same as "ZOO" or "zoo".

bool Lexicon::containsPrefix ( string  prefix  ) 

This member function returns true if any words in this lexicon begin with prefix, false otherwise. A word is defined to be a prefix of itself and the empty string is a prefix of everything. Prefixes are considered case-insensitively, "mo" is a prefix of "MONKEY" or "Monday".

void Lexicon::clear (  ) 

This member function removes all words from this lexicon. The lexicon will be empty after being cleared.

template<typename ClientDataType>
void Lexicon::mapAll ( void(fn)(string word, ClientDataType &)  ,
ClientDataType &  data 
)

This member function iterates through this lexicon and calls the function fn once for each word, passing the word and the client's data. That data can be of whatever type is needed for the client's callback.

const Lexicon& Lexicon::operator= ( const Lexicon rhs  ) 

template<typename ClientDataType>
void Lexicon::recMapAll ( Edge *  edge,
bool  first,
string  soFar,
void(fn)(string word, ClientDataType &)  ,
ClientDataType &  clientData 
)


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1