vector<string> ltest::stripParentheses(vector<string> & words) { vector<string> strippedWords = words; for (usInt ii = 0; ii < words.size(); ii++) strippedWords[ii] = stripParentheses(strippedWords[ii]); return strippedWords; }
bool ltest::isInvalidAnswer(string answer, vector<string> ws) { vector<string> strippedws = stripParentheses(ws); bool isWrong = true; for (usInt ii = 0; ii < ws.size() && isWrong; ii++) if ( !answer.compare(ws[ii]) || !answer.compare(strippedws[ii]) ) { isWrong = false; break; } return isWrong; }
void RESGen::ParseSentence(const char* const sentence) { // Not so performance critical here std::string sentenceLower(sentence); strToLower(sentenceLower); if( (sentenceLower.length() > 0) // References string in sentences.txt && (sentenceLower[0] != '!') // References string in Titles.txt && (sentenceLower[0] != '#') ) { // See if value references a wav file if( // Only one word (sentenceLower.find(' ') == std::string::npos) && !CompareStrEnd(sentenceLower, ".wav") ) { // TODO: Check that specifying a wav actually // works, and not that people are just misusing // this entity std::string resource = sentenceLower; std::string soundPrefix("sound/"); // Add sound/ to start if it isn't already if(resource.compare(0, soundPrefix.length(), soundPrefix)) { resource.insert(0, soundPrefix); } AddRes(resource); } else { // Everything between parentheses is for intonation // Ignore unbalanced parentheses - we'll just fail to find a // resource for that token (probably an emoticon) stripParentheses(sentenceLower); const size_t slashIndex = sentenceLower.find('/'); std::string soundPrefix("sound/"); // Is an announcer specified? if(slashIndex != std::string::npos) { soundPrefix += sentenceLower.substr(0, slashIndex + 1); sentenceLower.erase(0, slashIndex + 1); } else { // Default announcer soundPrefix += "vox/"; } // These get converted into comma and period sounds which definitely exist replaceCharAll(sentenceLower, ',', ' '); replaceCharAll(sentenceLower, '.', ' '); removeSubstring(sentenceLower, "\\n"); removeSubstring(sentenceLower, "\\r"); // Ignore any other illegal characters left over replaceCharAll(sentenceLower, '\\', ' '); Tokenizer<' '> tokenizer(sentenceLower); // while(true) incorrectly triggers MSVC C4127 for(;;) { const char* token = tokenizer.Next(); if(token == NULL) { break; } AddRes(token, soundPrefix.c_str(), ".wav"); } } } }