unsigned ResidentVocabulary::_GetNumSymbols(SymbolType symType) const { switch (symType) { case kLexicalTerminal: return getVocab(kTerminal).getNumSymbols(); case kRegularNonterminal: return getVocab(kNonterminal).getNumSymbols(); default: return getVocab(symType).getNumSymbols(); } }
void ResidentVocabulary::loadNonterminals(const std::string& nonTerminalPath) { std::string entry; std::vector<std::string> strings; SymbolType kType = sdl::kNonterminal; Util::Input inSrcFile(nonTerminalPath); while (Util::nfcline.getline(inSrcFile, entry)) { Util::splitSpaces(strings, entry); (void)getVocab(kType).add(strings[1], kType); } }
void ResidentVocabulary::loadTerminals(std::string const& terminalPath) { // TODO: test std::string entry; std::vector<std::string> strings; SymbolType kType = sdl::kTerminal; Util::Input in(terminalPath); while (Util::nfcline(in, entry)) { Util::splitSpaces(strings, entry); (void)getVocab(kType).add(strings[1], kType); } }
bool Dialog::handleNounSuffix(char *destP, int nounNum, const char *srcP) { char srcLine[40]; // The next source character must be a colon in front of the first verb if (*srcP != ':') return false; // Copy the remainder of the line into a temporary buffer to get the seperate verbs strcpy(srcLine, ++srcP); char *altP = strchr(srcLine, ':'); if (altP) *altP = '\0'; if (*srcP != '\0') { while (*srcP != ':') { ++srcP; if (!*srcP) break; } } if (*srcP != '\0') ++srcP; // char var_FC[40]; char tempLine[40]; strcpy(var_FC, srcP); char *tmpP = &tempLine[0]; char *tmp2P = tmpP; uint16 _vocabIds[2] = {1, 1}; // FIXME/TODO: Proper vocab ids getVocab(_vocabIds[nounNum], &tmpP); if ((*(tmpP - 1) != 'S') && (*(tmpP - 1) != 's')) { // Singular object tmpP = &var_FC[0]; } else if (!strcmp(tempLine, "a ")) { // Pontially plural char ch = tolower(*tmp2P); if (!((ch > 'U') || ((ch != 'A') && (ch != 'E') && (ch != 'I') && (ch != 'O')))) strcpy(tempLine, "an "); } strcpy(destP, tmpP); return true; }
static void copyToken(char token){ const char* vocabEntry = s_vocab; int y=0; while(getVocab(vocabEntry,y)){ if(getVocab(vocabEntry,y) == token && getVocab(vocabEntry,y+1) & 0x80){ while(getVocab(vocabEntry,++y)){ rprintfChar((char)(getVocab(vocabEntry,y) & 0x7f)); } break; } while(getVocab(vocabEntry,y++)); // Move to end of phoneme } }
// Set 'numChars' to the number of characters in the source text // that we match exactly against this phoneme dictionary entry static size_t countMatches(const char* textp,const char* vocabEntry){ size_t numChars; for(numChars=0;textp[numChars];numChars++){ // get next input character and make lower case char nextChar = textp[numChars]; if(nextChar>='A' && nextChar<='Z'){ nextChar = nextChar - 'A' + 'a'; } if(nextChar != getVocab(vocabEntry,numChars) ){ break; } } if(!isEndOfString(vocabEntry,numChars)){ numChars = 0; } return numChars; }
static void printPeakClusterInfo(struct trackDb *tdb, struct cart *cart, struct sqlConnection *conn, char *inputTrackTable, struct slName *fieldList, struct bed *cluster) /* Print an HTML table showing sources with hits in the cluster, along with signal. If cluster is NULL, show all sources assayed */ { /* Make the SQL query to get the table and all other fields we want to show * from inputTrackTable. */ struct dyString *query = dyStringNew(0); queryInputTrackTable(query, inputTrackTable, fieldList); char *vocabFile = NULL; struct hash *vocabHash = NULL; getVocab(tdb, cart, &vocabFile, &vocabHash); int displayNo = 0; int fieldCount = slCount(fieldList); struct sqlResult *sr = sqlGetResult(conn, query->string); char **row; while ((row = sqlNextRow(sr)) != NULL) { double signal = 0; if (cluster != NULL) { char *table = row[0]; signal = getSignalAt(table, cluster); if (signal == 0) continue; } printf("</TR><TR>\n"); webPrintIntCell(++displayNo); if (signal != 0) webPrintDoubleCell(signal); printControlledVocabFields(row+1, fieldCount, fieldList, vocabFile, vocabHash); printMetadataForTable(row[0]); } sqlFreeResult(&sr); freez(&vocabFile); dyStringFree(&query); }
/** * Enter: * src => English text * return null if errors, else phoneme string */ static void text2Phonemes(const char * src){ // int outIndex = 0;// Current offset into phonemes int inIndex = -1; // Starts at -1 so that a leading space is assumed while(inIndex==-1 || src[inIndex]){ // until end of text int maxMatch=0; // Max chars matched on input text // int numOut=0; // Number of characters copied to output stream for the best match int maxWildcardPos = 0; // Start with first vocab entry const char* vocabEntry = s_vocab; // Keep track of best match so far const char* bestEntry = null; int bestWildCardInPos=0; char bestWildCard=0; boolean bestHasWhiteSpace=FALSE; int wildcardInPos; // Get next phoneme, P2 while(getVocab(vocabEntry,0)){ int y; char wildcard=0; // The wildcard character boolean hasWhiteSpace=FALSE; wildcardInPos=0; // The index in the vocab where it occurs for(y=0;;y++){ char nextCharIn,nextVocabChar; // Get next char from user input // Make next char upper case and remove control characters nextCharIn = (y + inIndex == -1) ? ' ' : src[y + inIndex]; if(nextCharIn>='a' && nextCharIn<='z'){ nextCharIn = nextCharIn - 'a' + 'A'; }else if(nextCharIn<' '){ nextCharIn = ' '; } // Get next text char from vocab nextVocabChar = getVocab(vocabEntry,y); if( (nextVocabChar & 0x80)){ nextVocabChar = 0; } // If its a wildcard then save its value and position if(nextVocabChar=='#' && nextCharIn >= 'A' && nextCharIn <= 'Z'){ wildcard = nextCharIn; // The character equivalent to the '#' wildcardInPos=y; continue; } // Check if vocab is looking for end of word if(nextVocabChar=='_'){ // try to match against a white space hasWhiteSpace=TRUE; if(whitespace(nextCharIn)){ continue; } y--; break; } // check for end of either string if(nextVocabChar==0 || nextCharIn==0){ break; } if(nextVocabChar != nextCharIn){ break; } } // See if its the longest complete match so far if(y > maxMatch && ( getVocab(vocabEntry,y) & 0x80) == 0x80){ // This is the longest complete match maxMatch = y; maxWildcardPos = 0; // Point to the start of the phoneme bestEntry = vocabEntry + y; bestWildCardInPos = wildcardInPos; bestWildCard = wildcard; bestHasWhiteSpace = hasWhiteSpace; } // Move to start of next entry while(getVocab(vocabEntry,y++)); // Move to end of phoneme asciiz vocabEntry += y; }// check next phoneme // 15 - end of vocab table //16 if(bestHasWhiteSpace==TRUE){ maxMatch--; } //17 if(maxMatch==0){ loggerP(PSTR("No token for ")); logger(&src[inIndex]); loggerCRLF(); return; } // Copy data for best match { int y; // Copy the matching phrase changing any '#' to the phoneme for the wildcard for(y=0;;y++){ char c = getVocab(bestEntry,y) & 0x7f; // Get the next phoneme character if(c==0){ y++; // move to start of next vocab entry break; } if(c=='#'){ if(getVocab(bestEntry,y+1)==0){ // replacement ends in wild card maxWildcardPos = bestWildCardInPos; }else{ // Copy the phonemes for the wild card character copyToken(bestWildCard); } }else{ rprintfChar(c); // output the phoneme character } } } inIndex += (maxWildcardPos>0) ? maxWildcardPos : maxMatch; } }
bool ResidentVocabulary::_containsSym(Sym symId) const { return getVocab(symId.type()).containsSym(symId); }
bool ResidentVocabulary::_contains(std::string const& symbol, SymbolType symType) const { bool const have = getVocab(symType).contains(symbol); return have; }
std::string const& ResidentVocabulary::_Str(Sym const symId) const { return getVocab(symId.type()).str(symId); }
Sym ResidentVocabulary::_Add(std::string const& symbol, SymbolType symType) { return getVocab(symType).add(symbol, symType); }
void ResidentVocabulary::_AcceptType(IVocabularyVisitor& visitor, SymbolType type) { getVocab(type).accept(visitor); }
unsigned ResidentVocabulary::_Size(SymbolType symType) const { return getVocab(symType).size(); }
bool ResidentVocabulary::_boundsSym(Sym symId) const { return getVocab(symId.type()).boundsSym(symId); }
Dialog::Dialog(MadsM4Engine *vm, const char *msgData, const char *title): View(vm, Common::Rect(0, 0, 0, 0)) { assert(msgData); _vm->_font->setFont(FONT_INTERFACE_MADS); const char *srcP = msgData; bool skipLine = false; bool initFlag = false; bool cmdFlag = false; bool crFlag = false; bool underline = false; _screenType = LAYER_DIALOG; _widthChars = 0; _dialogIndex = 0; _askPosition.x = 0; _askPosition.y = 0; _lineX = 0; _widthX = 0; _dialogWidth = 0; _commandCase = false; char dialogLine[256]; char cmdText[80]; char *lineP = &dialogLine[0]; char *cmdP = NULL; while (srcP && *(srcP - 1) != '\0') { if ((*srcP == '\n') || (*srcP == '\0')) { // Line completed *lineP = '\0'; ++srcP; if (!initFlag) { initDialog(); initFlag = true; } if (!skipLine) writeChars(dialogLine); else { addLine(dialogLine, underline); if (crFlag) incLine(); } // Clear the current line contents dialogLine[0] = '\0'; lineP = &dialogLine[0]; skipLine = crFlag = underline = false; continue; } else if (*srcP == '[') { // Start of a command sequence cmdFlag = true; cmdP = &cmdText[0]; ++srcP; continue; } else if (*srcP == ']') { // End of a command sequence *cmdP = '\0'; cmdFlag = false; strToUpper(cmdText); if (matchCommand(cmdText, "ASK")) { setupInputArea(); } else if (matchCommand(cmdText, "BAR")) { // Adds a full-width line instead of normal text addBarLine(); } else if (matchCommand(cmdText, "CENTER")) { // Center command skipLine = true; } else if (matchCommand(cmdText, "CR")) { // CR command if (skipLine) crFlag = true; else if (!initFlag) { initDialog(); initFlag = true; } } else if (matchCommand(cmdText, "NOUN1")) { // Noun command 1 handleNounSuffix(lineP, 1, cmdText + 5); } else if (matchCommand(cmdText, "NOUN2")) { // Noun command 2 handleNounSuffix(lineP, 2, cmdText + 5); } else if (matchCommand(cmdText, "SENTENCE")) { // Sentence command - loads the title into the line buffer strcpy(dialogLine, title); strToUpper(dialogLine); lineP += strlen(dialogLine) + 1; } else if (matchCommand(cmdText, "TAB")) { // Specifies the X offset for the current line _lines[_lines.size() - 1].xp = atoi(cmdText + 3); } else if (matchCommand(cmdText, "TITLE")) { // Title command - specifies the dialog width in number of characters skipLine = true; crFlag = true; underline = true; int id = atoi(cmdText + 5); if (id > 0) { // Suffix provided - specifies the dialog width in number of chars _widthChars = id * 2; _dialogWidth = id * (_vm->_font->current()->getMaxWidth() + DIALOG_SPACING) + 10; } } else if (matchCommand(cmdText, "UNDER")) { // Underline command underline = true; } else if (matchCommand(cmdText, "VERB")) { // Verb/vocab retrieval int verbId = 1; // TODO: Get correct vocab getVocab(verbId, &lineP); } else if (matchCommand(cmdText, "INDEX")) { // Index command _dialogIndex = atoi(cmdText + 5); } else { error("Unknown dialog command '%s' encountered", cmdText); } } *lineP++ = *srcP; if (cmdFlag) *cmdP++ = *srcP; ++srcP; } draw(); }
Sym ResidentVocabulary::_AddSymbolMustBeNew(std::string const& symbol, SymbolType symType) { return getVocab(symType).addSymbolMustBeNew(symbol); }
/** * * Convert phonemes to data string * Enter: textp = phonemes string * Return: phonemes = string of sound data * modifier = 2 bytes per sound data * */ static boolean phonemesToData(const char* textp){ size_t phonemeOut = 0; // offset into the phonemes array size_t modifierOut = 0; // offset into the modifiers array uint8_t L81=0; // attenuate uint8_t previousL81=16; #ifdef _WINDOWS_ memset(modifier,0xAA,sizeof(modifier)); #endif while(*textp){ int numOut; // P20: Get next phoneme size_t longestMatch=0; const char* vocabEntry = s_phonemes; const char* bestPhoneme = null; uint8_t bestPhonemeNo=0; // Get next phoneme, P2 uint8_t phonemeNumber; for(phonemeNumber = 0; getVocab(vocabEntry,0);phonemeNumber++){ // Find the exact matching characters size_t numChars = countMatches(textp,vocabEntry); // if not the longest match so far, or not a complete match, then ignore if(numChars > longestMatch){ // P7: we have matched the whole phoneme longestMatch = numChars; bestPhoneme = vocabEntry + numChars; bestPhonemeNo = phonemeNumber; } // Move to next phoneme while(getVocab(vocabEntry++,0)!=0); // Skip over sound data } // next phoneme // p13 if(!bestPhoneme){ loggerP(PSTR("Mistake in speech at ")); logger(textp); loggerCRLF(); return FALSE; } L81 = pgm_read_byte(&s_attenuate[bestPhonemeNo]) /*+'0'*/; // Get char from text after the phoneme and test if it is a numeric if(textp[longestMatch]>='0' && textp[longestMatch]<='9'){ // Pitch change requested modifier[modifierOut] = pgm_read_byte(&PitchesP[textp[longestMatch]-'1'] ); modifier[modifierOut+1] = L81; longestMatch++; }else{ modifier[modifierOut]=-1; modifier[modifierOut+1]=0; } // P10 if(L81!='0' && L81 != previousL81 && modifierOut!=0 && modifier[modifierOut]>=0){ modifier[modifierOut - 2] = modifier[modifierOut]; modifier[modifierOut - 1] = '0'; }else{ // P11 if( (textp[longestMatch-1] | 0x20) == 0x20){ // end of input string or a space modifier[modifierOut] = (modifierOut==0) ? 16 : modifier[modifierOut-2]; } } // Copy phoneme data to sound data for(numOut=0; getVocab(bestPhoneme,numOut)!= 0; numOut++){ sounds[phonemeOut++] = getVocab(bestPhoneme,numOut) & 0x7f; } if(phonemeOut > sizeof(sounds)-16){ loggerP(PSTR("Line too long\n")); return FALSE; } // P16 // Copy the modifier setting to each sound data element for this phoneme if(numOut > 2){ int count; for(count=0; count <= numOut; count+=2){ modifier[modifierOut + count + 2] = modifier[modifierOut + count]; modifier[modifierOut + count + 3] = modifier[modifierOut + count + 1]; } } modifierOut += numOut; //p21 textp += longestMatch; previousL81 = L81; } sounds[phonemeOut++]='z'; sounds[phonemeOut++]='z'; sounds[phonemeOut++]='z'; sounds[phonemeOut++]='z'; while(phonemeOut < sizeof(sounds)){ sounds[phonemeOut++]=0; } while(modifierOut < sizeof(modifier)){ modifier[modifierOut++]=-1; modifier[modifierOut++]=0; } return TRUE; }
Sym ResidentVocabulary::_Sym(std::string const& symbol, SymbolType symType) const { return getVocab(symType).sym(symbol); }