本文整理汇总了C++中PhraseTable::storeIfNew方法的典型用法代码示例。如果您正苦于以下问题:C++ PhraseTable::storeIfNew方法的具体用法?C++ PhraseTable::storeIfNew怎么用?C++ PhraseTable::storeIfNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhraseTable
的用法示例。
在下文中一共展示了PhraseTable::storeIfNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
bool PhraseAlignment::create(const char line[], int lineID )
{
vector< string > token = tokenize( line );
int item = 1;
PHRASE phraseF, phraseE;
for (size_t j=0; j<token.size(); j++) {
if (token[j] == "|||") item++;
else {
if (item == 1)
phraseF.push_back( vcbF.storeIfNew( token[j] ) );
else if (item == 2)
phraseE.push_back( vcbE.storeIfNew( token[j] ) );
else if (item == 3) {
int e,f;
sscanf(token[j].c_str(), "%d-%d", &f, &e);
if ((size_t)e >= phraseE.size() || (size_t)f >= phraseF.size()) {
cerr << "WARNING: sentence " << lineID << " has alignment point (" << f << ", " << e << ") out of bounds (" << phraseF.size() << ", " << phraseE.size() << ")\n";
} else {
if (alignedToE.size() == 0) {
vector< size_t > dummy;
for(size_t i=0; i<phraseE.size(); i++)
alignedToE.push_back( dummy );
for(size_t i=0; i<phraseF.size(); i++)
alignedToF.push_back( dummy );
foreign = phraseTableF.storeIfNew( phraseF );
english = phraseTableE.storeIfNew( phraseE );
}
alignedToE[e].push_back( f );
alignedToF[f].push_back( e );
}
}
}
}
return (item>2); // real phrase pair, not just foreign phrase
}
示例2: create
// read in a phrase pair and store it
void PhraseAlignment::create(const vector<string>& token, int lineID) {
int item = 1;
PHRASE phraseS, phraseT;
for (size_t j=0; j<token.size(); ++j) {
if (token[j] == "|||")
item++;
else if (item == 1) // source phrase
phraseS.push_back( vcbS.storeIfNew( token[j] ) );
else if (item == 2) // target phrase
phraseT.push_back( vcbT.storeIfNew( token[j] ) );
else if (item == 3) { // alignment
int s = strtol(token[j].substr(0, token[j].find("-")).c_str(), NULL, 10);
int t = strtol(token[j].substr(token[j].find("-") + 1).c_str(), NULL, 10);
if (t >= phraseT.size() || s >= phraseS.size()) {
cerr << "WARNING: phrase pair " << lineID
<< " has alignment point (" << s << ", " << t
<< ") out of bounds (" << phraseS.size() << ", " << phraseT.size() << ")\n";
} else {
// first alignment point? -> initialize
if (alignedToT.size() == 0) {
assert(alignedToS.size() == 0);
size_t numTgtSymbols = (hierarchicalFlag ? phraseT.size()-1 : phraseT.size());
alignedToT.resize(numTgtSymbols);
size_t numSrcSymbols = (hierarchicalFlag ? phraseS.size()-1 : phraseS.size());
alignedToS.resize(numSrcSymbols);
source = phraseTableS.storeIfNew( phraseS );
target = phraseTableT.storeIfNew( phraseT );
}
// add alignment point
alignedToT[t].insert( s );
alignedToS[s].insert( t );
}
} else if (item == 4) // count
count = strtof(token[j].c_str(), NULL);
}
if (item == 3)
count = 1.0;
if (item < 3 || item > 4) {
cerr << "ERROR: faulty line " << lineID << ": ";
for(vector<string>::const_iterator i = token.begin(); i != token.end(); cerr << *(i++) << " ");
cerr << endl;
}
}