ECString ECConfig::FindKey(const EC_PCHAR pStr) const { ECString sStr(pStr); EC_S32 nSize = sStr.FindChar(CONFIG_ASSGINV_CHAR); if(nSize >= 0) return ECString(pStr, nSize); else { if(pStr && (CONFIG_COMMENT_CHAR == pStr[0])) return ECString((EC_PCHAR)CONFIG_COMMENT_STR); } return ECString(); }
ECString ECConfig::FindVal(const EC_PCHAR pStr) const { ECString sStr(pStr); EC_S32 nSize = sStr.FindChar(CONFIG_ASSGINV_CHAR); if(nSize >= 0) { ECString sVal(pStr+nSize+1); sVal.Trim(); return sVal; } else if(pStr && (CONFIG_COMMENT_CHAR == pStr[0])) return ECString(pStr+1); return ECString(); }
static void* mainLoop(void* arg) { int *id = reinterpret_cast<int *>(arg); PrintStack printStack; for( ; ; ) { SentRep* srp = new SentRep(params.maxSentLen); pthread_mutex_lock(&readlock); if(Bchart::tokenize) *tokStream >> *srp; else *nontokStream >> *srp; int locCount = sentenceCount++; ExtPos extPos; if(params.extPosIfstream) extPos.read(params.extPosIfstream,*srp); pthread_mutex_unlock(&readlock); if( !params.field().in(sentenceCount) ) continue; printStruct printS; printS.name = srp->getName(); printS.sentenceCount = locCount; printS.numDiff = 0; int len = srp->length(); if (len == 0) { break; } if (len > params.maxSentLen) { ECString msg("skipping sentence longer than specified limit of "); msg += intToString(params.maxSentLen); WARN( msg.c_str() ); printSkipped(srp,NULL,printStack,printS); continue; } // handle input containing reserved word Bchart::HEADWORD_S1; could probably do // better (like undo replacement before printing) but this seems sufficient. int i; for (i = 0; i < len; ++i) { ECString& w = ((*srp)[i]).lexeme(); if (w == Bchart::HEADWORD_S1) { ECString msg = ECString("Replacing reserved token \"") + Bchart::HEADWORD_S1; msg += "\" at index " + intToString(i) + " of input with token \"^^^\""; WARN( msg.c_str() ); w = "^^^"; } } MeChart* chart = new MeChart( *srp,extPos,*id ); chart->parse( ); Item* topS = chart->topS(); if(!topS) { if (extPos.hasExtPos()) { WARN("Parse failed: !topS -- reparsing without POS constraints"); chart = new MeChart(*srp, *id); chart->parse(); topS = chart->topS(); if (!topS) { WARN("Reparsing without POS constraints failed too: !topS"); printSkipped(srp, chart, printStack, printS); continue; } } else { WARN( "Parse failed: !topS" ); printSkipped(srp,chart,printStack,printS); continue; } } bool failed = decodeParses(len, locCount, srp, chart, printS, printStack); if (failed) { continue; } if( printS.numDiff == 0) { if (extPos.hasExtPos()) { WARN("Parse failed from 0, inf or nan probabililty -- reparsing without POS constraints"); chart = new MeChart(*srp, *id); chart->parse(); bool failed = decodeParses(len, locCount, srp, chart, printS, printStack); if (failed || printS.numDiff == 0) { WARN("Parse failed from 0, inf or nan probabililty -- failed even without POS constraints"); printSkipped(srp,chart,printStack,printS); continue; } } else { WARN("Parse failed from 0, inf or nan probabililty"); printSkipped(srp,chart,printStack,printS); continue; } } /* put the sentence with which we just finished at the end of the printStack*/ printStack.push_back(printS); workOnPrintStack(&printStack); delete chart; delete srp; }