本文整理汇总了C++中Lexicon类的典型用法代码示例。如果您正苦于以下问题:C++ Lexicon类的具体用法?C++ Lexicon怎么用?C++ Lexicon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lexicon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateAllPossibleWords
static void generateAllPossibleWords(const Grid<char> & boggleBoard, Set<string> & wordsSpottedSoFar,
const Lexicon & english, int rowIndex, int colIndex, string buildingWord,
Set<coord> wordPath){
buildingWord += boggleBoard[rowIndex][colIndex];
if (buildingWord.size() >= kMinGuessLength && english.contains(buildingWord)
&& !wordsSpottedSoFar.contains(buildingWord)) {
wordsSpottedSoFar.add(buildingWord);
recordWordForPlayer(buildingWord, COMPUTER);
}
if (!english.containsPrefix(buildingWord)) return;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <=1; j++){
if(isShiftValid(boggleBoard, rowIndex, colIndex, i, j)){
coord nextPos;
nextPos.row = rowIndex + i;
nextPos.col = colIndex + j;
if (!wordPath.contains(nextPos)){
wordPath.add(nextPos);
generateAllPossibleWords(boggleBoard, wordsSpottedSoFar, english,
rowIndex + i, colIndex + j, buildingWord, wordPath);
wordPath.remove(nextPos);
}
}
}
}
}
示例2: recursiveFindWord
//credit to erickwill, his code guided me to the answer
void recursiveFindWord(int row, int col,std::string soFar, Grid<char> &grid, Lexicon words, Vector<std::string> &foundWords)
{
char orig = grid.get(row,col);
soFar = soFar + grid.get(row,col);
drawCubes(grid);
cout << "row = " << row << " col = " << col << endl;
cout << "sofar = " << soFar << endl;
if(words.contains(soFar) && !containsWord(foundWords,soFar)){
cout << "contains word: " << soFar << endl;
foundWords.push_back(soFar);
return;
}
if(!words.containsPrefix(soFar)){
cout << "does not contain prefix: " << soFar << endl;
return;
}
for(int i = -1; i < 2; i++){
for(int j = -1; j < 2; j++){
if(row+i>=0 && col+j >=0 && row+i < grid.numRows() && col+j < grid.numCols() && (row+i < grid.numRows() && col+j < grid.numCols())
&& !(i==0 && j==0) && grid.get(row+i,col+j) != '~')
{
grid.set(row,col,'~');
recursiveFindWord(row+i,col+j,soFar,grid,words,foundWords);
grid.set(row,col,orig);
}
}
}
return;
}
示例3: readBowFileText
//! @brief read a text Bow file and fills a lexicon
//! @param fileIn the file to read
//! @param reader the file reader
//! @param lex the lexicon to fill
//! @param propertyAccessor
//! @param referenceProperties
void readBowFileText(ifstream& fileIn,
BoWBinaryReader& reader,
Lexicon& lex,
const PropertyAccessor& propertyAccessor,
set<LinguisticCode>& referenceProperties
)
{
BoWText text;
reader.readBoWText(fileIn,text);
bool filterCategory = false;
if ( referenceProperties.size() > 0 ) {
filterCategory = true;
}
BoWTokenIterator it(text);
while (! it.isAtEnd()) {
const BoWToken& token = *(it.getElement());
if (filterCategory) {
set<LinguisticCode>::const_iterator referencePropertyIt =
referenceProperties.find(propertyAccessor.readValue(token.getCategory()));
if ( referencePropertyIt != referenceProperties.end() ) {
lex.add(getStringDecomp(&token),token.getIndexString());
}
}
else {
lex.add(getStringDecomp(&token),token.getIndexString());
}
it++;
}
}
示例4: recursiveComputer
/*
* Recursive Computer Search
*
* Recursively searches the Boggle board to find all the
* words that can be made on the board and haven't
* been guessed correctly by the human player
*/
void recursiveComputer(int row, int col, string word, Grid<string>& board, Lexicon& dictionary, Set<string>& results, Grid<bool>& visitedCubes, int& computerScore, Set<string>& usedWords){
if(!board.inBounds(row, col)) return;
if(dictionary.contains(word) && word.length() >= 4) {
if (!results.contains(word) && !usedWords.contains(word)) {
computerScore += word.length() - 3;
results.add(word);
}
}
if(!dictionary.containsPrefix(word)){
return;
}
word = word + board[row][col];
visitedCubes[row][col] = true;
for(int i = -1; i <= 1; i++){
for(int j = -1; j <= 1; j++){
if(visitedCubes.inBounds(row + i, col + j) && !visitedCubes[row + i][col + j]){
recursiveComputer(row + i, col + j, word, board, dictionary, results, visitedCubes, computerScore, usedWords);
}
if(visitedCubes.inBounds(row + i, col + j) && dictionary.contains(word) && !results.contains(word) && word.length() >=4) {
computerScore += word.length() - 3;
results.add(word);
}
}
}
visitedCubes[row][col] = false;
}
示例5: getPath
string Levenshtein::getPath(Lexicon &lex)
{
string path_ops = this->getPathOps();
string path = "";
unsigned int trans_counter = 0, ref_counter = 0;
for (unsigned int i=0; i<path_ops.size(); i++)
{
switch (path_ops[i])
{
case 'm':
path += "(m:"+lex.getWord(trans_v[trans_counter])+")";
trans_counter++;
ref_counter++;
break;
case 'i':
path += "(i:"+lex.getWord(ref_v[ref_counter])+")";
ref_counter++;
break;
case 'd':
path += "(d:"+lex.getWord(trans_v[trans_counter])+")";
trans_counter++;
break;
}
}
return path;
}
示例6: bfs
//return a string vector as the shortest ladder, if found
//return an empty vector, if not found
Vector<string> bfs(string &startingWord, string &endingWord) {
Lexicon english("EnglishWords.dat");
Lexicon wordUsed;
Queue<Vector<string>> queue;
Vector<string> ladder;
ladder.push_back(startingWord);
queue.enqueue(ladder);
while (!queue.isEmpty()) {
Vector<string> front = queue.dequeue();
if (front.get(front.size() - 1) == endingWord)
return front;
string current = front.get(front.size() - 1);
for (int i = 0; i < current.size(); i++)
for (char j = 'a'; j <= 'z'; j++)
if (current[i] != j){
string next = current;
next[i] = j;
if (!english.contains(next))
continue;
if (wordUsed.contains(next))
continue;
wordUsed.add(next);
Vector<string> nextLadder = front;
nextLadder.push_back(next);
queue.enqueue(nextLadder);
}
}
Vector<string> empty;
return empty;
}
示例7: main
int main() {
Lexicon english ("EnglishWords.dat");
Lexicon usedWords; // need to check the unique word
Queue<Vector<string>> result;
string firstWord, secondWord;
while(true){
readWords (firstWord, secondWord, english);
createFirstLadder(result, firstWord);
usedWords.add(firstWord);
while(!result.isEmpty ()){
Vector<string> firstLadder = result.dequeue ();
if(firstLadder.get (firstLadder.size () - 1) == secondWord){
display(firstLadder);
result.clear();
usedWords.clear ();
break;
}
string currentWord = firstLadder.get(firstLadder.size ()-1);
usedWords.add(currentWord);
createNextLadder(currentWord, firstLadder, usedWords, result, english);
}
/* If the ladder of the two entered words is impossible */
if(!usedWords.isEmpty ()){
cout << "Sorry, this ladder is impossible..." << endl;
}
}
return 0;
}
示例8: InEnglish
bool InEnglish(const string &word)
{
for(Lexicon::iterator it = english.begin(); it != english.end(); ++it)
if(word == *it) return true;
return false;
}
示例9: lower_bound
void CCmpLexicon::WriteToken(const char* inText, obit_stream& ioBits)
{
Lexicon::iterator i = lower_bound(lexicon.begin() + 1, lexicon.end(), LexEntry(inText, 0));
if (i != lexicon.end() && strcmp(inText, (*i).text) == 0)
{
Push(ioBits, (*i).code, (*i).cnt);
}
else
{
Push(ioBits, lexicon[0].code, lexicon[0].cnt);
for (const char* p = inText; *p; ++p)
{
RestChar e;
e.ch = static_cast<unsigned char>(*p);
RestCharacters::iterator i = lower_bound(rest.begin(), rest.end(), e);
assert(i != rest.end());
assert((*i).ch == static_cast<unsigned char>(*p));
Push(ioBits, (*i).code, (*i).cnt);
}
Push(ioBits, rest[0].code, rest[0].cnt);
}
}
示例10: ListCompletions
/* ListCompletions(string, Lexicon):
* Prints all words from the lexicon that can be formed by extending
* the given digit sequence.
*/
void ListCompletions(string digits, Lexicon & lex) {
int index=0;
/*find the first digit*/
while(index<(int)digits.length() && !isdigit(digits[index]))
index++;
/*Don't start checking until the digits have been entirely converted to letters*/
if(index == digits.length() ){
string word = digits; //redundant, but helps me understand
/*Lexicon doesn't containPrefix=>these aren't the droids I'm looking for*/
if(!lex.containsPrefix(word)) return;
/*Otherwise check if the current word is in the lexicon and print it if it is*/
if( lex.contains(word)){
cout << "\t" << word << endl;
}
/*...and then try recursively checking after adding each letter*/
for( char ch='a'; ch<='z'; ++ch){
string newWord = digits + ch;
ListCompletions(newWord, lex);
}
return;
}
/*make a prefix out of the current letters, check what could come next, and recursively check each*/
string prefix = digits.substr(0, index);
string digitLetters = letterSets[digits[index] - '0']; //subtracting '0' converts digits[index] a char to an int
int i=0; //not intuitive at all
while(i<digitLetters.length()){
ListCompletions(prefix + digitLetters[i] + digits.substr(index + 1), lex );
i++;
}
}
示例11: extractAccounts
AccountList AccountNumbersConverter::extractAccounts() {
_accounts.clear();
OCREntryListCIter iter;
Lexicon lex;
Account account;
ChecksumCalculator checksumCalc;
int expectedChecksum;
for(iter = _entries.begin(); iter != _entries.end(); ++iter) {
account.number = lex.parse( (*iter) );
expectedChecksum = checksumCalc.checksumFor(account.number);
account.checksum = ( (*iter).getChecksum() );
account.isErroneous = (expectedChecksum != account.checksum);
account.displayText = account.number;
if (account.isErroneous) {
account.displayText += " ERR";
}
_accounts.push_back(account);
}
return _accounts;
}
示例12: sloveBoggle
Vector<string> sloveBoggle(Grid<char> &grid, Point start, int depth, Vector<Point> &path, string &word, Lexicon &lex) {
Vector<string> result;
if (depth > MAX_LENGTH) {
// greater than maxium length, return
// return lex.containsWord(word);
} else {
//recursion to the element around the current element.
int i = start.x;
int j = start.y;
if(lex.containsWord(word) && depth >= MIN_LENGTH) {
result.add(word);
}
for(Direction dir = TOPLEFT; dir <= LEFT; dir++) {
if(isBound(grid, i, j, dir)) {
Point new_start = adjustPoint(start, dir);
if(isContainPoint(path, new_start)) continue;
string new_word = word + grid.getAt(new_start.x, new_start.y);
if(!lex.containsPrefix(new_word)) continue;
path.add(new_start);
depth++;
Vector<string> res = sloveBoggle(grid, new_start, depth, path, new_word, lex);
result = concateVec(result, res);
path.removeAt(path.size() - 1);
depth--;
}
}
}
return result;
}
示例13: ListWords
int ListWords(const map<char,string> &keypads,string prex,string digitSequence,string alber,Lexicon &lex){
int count=0;
if(digitSequence.empty()&&lex.containsPrefix(prex)){
if(lex.containsWord(prex)){
count++;
cout<<prex<<endl;
}
for(unsigned int i=0;i<alber.size();i++){
string p=prex;
p.push_back(alber[i]);
count+=ListWords(keypads,p,digitSequence,alber,lex);
}
return count;
}
if(!digitSequence.empty()&&lex.containsPrefix(prex)){
string nextchar=(keypads.find(digitSequence[0]))->second;
digitSequence.erase(digitSequence.begin());
for(unsigned int i=0;i<nextchar.size();i++){
string p=prex;
p.push_back(nextchar[i]);
count+=ListWords(keypads,p,digitSequence,alber,lex);
}
}
return count;
}
示例14: findWordLadder
string findWordLadder(string startWord, string endWord, Lexicon& wordsLexicon)
{
Queue<Vector<string>> ladderQueue;
Lexicon usedWords;
Vector<string> startingLadder;
startingLadder.add(startWord);
ladderQueue.enqueue(startingLadder);
usedWords.add(startWord);
while(ladderQueue.size() > 0)
{
Vector<string> wordLadder = ladderQueue.dequeue();
string lastWord = wordLadder[wordLadder.size() - 1];
if(lastWord == endWord)
{
string returnValue = "Ladder found:";
foreach(string word in wordLadder)
{
returnValue += " " + word;
}
return returnValue;
}
示例15: printValidWords
// checks lexicon and prints all words that begin with the given prefix
void printValidWords(string prefix, Lexicon &lex){
string alpha = "abcdefghijklmnopqrstuvwxyz";
if(lex.containsWord(prefix)) cout << prefix << " ";
if(lex.containsPrefix(prefix)){
for(int i = 0; i < alpha.length(); i++){
printValidWords(prefix + alpha.at(i), lex);
}
}
}