当前位置: 首页>>代码示例>>C++>>正文


C++ Lexicon类代码示例

本文整理汇总了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);
                }
            }
        }
    }
}
开发者ID:jnicolls,项目名称:CS106X,代码行数:26,代码来源:boggle.cpp

示例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;
}
开发者ID:shtef12,项目名称:CS106B,代码行数:33,代码来源:Boggle.cpp

示例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++;
    }
}
开发者ID:Geekking,项目名称:lima,代码行数:37,代码来源:getLexiconFromBoW.cpp

示例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;
}
开发者ID:dchaniel,项目名称:Boggle,代码行数:36,代码来源:Boggle.cpp

示例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;
}
开发者ID:Chefslayer,项目名称:Translator,代码行数:28,代码来源:Levenshtein.cpp

示例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;
}
开发者ID:Yotta2,项目名称:Stanford_CS106B,代码行数:34,代码来源:WordLadder.cpp

示例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;
}
开发者ID:shpp-aotyan,项目名称:CS-B,代码行数:28,代码来源:WordLadder.cpp

示例8: InEnglish

bool InEnglish(const string &word)
{
  for(Lexicon::iterator it = english.begin(); it != english.end(); ++it)
    if(word == *it) return true;

  return false;
}
开发者ID:wizardforcel,项目名称:se106labs,代码行数:7,代码来源:Boggle.cpp

示例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);
	}
}
开发者ID:BackupTheBerlios,项目名称:mrs-svn,代码行数:25,代码来源:CCompress.cpp

示例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++;
	}
}
开发者ID:nhayes-roth,项目名称:cs106b_3,代码行数:39,代码来源:MindReading.cpp

示例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;
}
开发者ID:gregmalcolm,项目名称:KataBankOCR,代码行数:25,代码来源:AccountNumbersConverter.cpp

示例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;
}
开发者ID:kimochg,项目名称:Boggle,代码行数:32,代码来源:boggle.cpp

示例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;
}
开发者ID:nejyeah,项目名称:cplusplus,代码行数:26,代码来源:part4.cpp

示例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;
        }
开发者ID:diogoamvasconcelos,项目名称:cs106b-eroberts2015-solutions,代码行数:26,代码来源:WordLadder.cpp

示例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);
        } 
    }
}
开发者ID:brianjscoles,项目名称:CS106b-solutions,代码行数:11,代码来源:4+-+keypad+words.cpp


注:本文中的Lexicon类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。