本文整理汇总了C++中CWord::str方法的典型用法代码示例。如果您正苦于以下问题:C++ CWord::str方法的具体用法?C++ CWord::str怎么用?C++ CWord::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CWord
的用法示例。
在下文中一共展示了CWord::str方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPossibleTagsBySuffix
unsigned long long TARGET_LANGUAGE::CTagger::getPossibleTagsForWord( const CWord &word ) {
static unsigned long long possible_tags;
possible_tags = m_TagDict.lookup(word);
if (possible_tags==0) possible_tags = ~0L;
#ifdef _ENGLISH_TAGS_H
possible_tags |= getPossibleTagsBySuffix( word.str() );
possible_tags |= PENN_TAG_MUST_SEE ;
#endif
assert(possible_tags!=0);
return possible_tags;
}
示例2: updateLocalFeatureVector
void CFeatureHandle::updateLocalFeatureVector(SCORE_UPDATE method, const CStringVector* outout, int index, int round) {
// abstd::cout words
CWord word = outout->at(index);
CWord last_word = index>0 ? outout->at(index-1) : g_emptyWord;
CTwoWords two_word;
two_word.allocate(word.str(), last_word.str());
CStringVector chars;
chars.clear(); getCharactersFromUTF8String(word.str(), &chars);
// abstd::cout length
int length = getUTF8StringLength(word.str()); if (length > LENGTH_MAX-1) length = LENGTH_MAX-1;
int last_length = getUTF8StringLength(last_word.str()); if (last_length > LENGTH_MAX-1) last_length = LENGTH_MAX-1;
// abstd::cout chars
CWord first_char = getFirstCharFromUTF8String(word.str());
CWord last_char = getLastCharFromUTF8String(word.str());
CWord first_char_last_word = index>0 ? getFirstCharFromUTF8String(last_word.str()) : g_emptyWord;
CWord last_char_last_word = index>0 ? getLastCharFromUTF8String(last_word.str()) : g_emptyWord;
CWord two_char = index>0 ? last_char_last_word.str() + first_char.str() : g_emptyWord;
CTwoWords first_and_last_char, lastword_firstchar, currentword_lastchar, firstcharlastword_word, lastword_lastchar;
first_and_last_char.allocate(first_char.str(), last_char.str());
if (index>0) {
lastword_firstchar.allocate(last_word.str(), first_char.str());
currentword_lastchar.allocate(word.str(), last_char_last_word.str());
firstcharlastword_word.allocate(first_char_last_word.str(), first_char.str());
lastword_lastchar.allocate(last_char_last_word.str(), last_char.str());
}
SCORE_TYPE amount = ( (method==eAdd) ? 1 : -1 ) ;
m_weights.m_mapSeenWords.updateScore(word, amount, round);
m_weights.m_mapLastWordByWord.updateScore(two_word, amount, round);
if (length==1) m_weights.m_mapOneCharWord.updateScore(first_char, amount, round);
else {
m_weights.m_mapFirstAndLastChars.updateScore(first_and_last_char, amount, round);
for (int j=0; j<chars.size()-1; j++) {
m_weights.m_mapConsecutiveChars.updateScore(chars[j]+chars[j+1], amount, round);
}
m_weights.m_mapLengthByFirstChar.updateScore(std::make_pair(first_char, length), amount, round);
m_weights.m_mapLengthByLastChar.updateScore(std::make_pair(last_char, length), amount, round);
}
if (index>0) {
m_weights.m_mapSeparateChars.updateScore(two_char, amount, round);
m_weights.m_mapLastWordFirstChar.updateScore(lastword_firstchar, amount, round);
m_weights.m_mapCurrentWordLastChar.updateScore(currentword_lastchar, amount, round);
m_weights.m_mapFirstCharLastWordByWord.updateScore(firstcharlastword_word, amount, round);
m_weights.m_mapLastWordByLastChar.updateScore(lastword_lastchar, amount, round);
m_weights.m_mapLengthByLastWord.updateScore(std::make_pair(last_word, length), amount, round);
m_weights.m_mapLastLengthByWord.updateScore(std::make_pair(word, last_length), amount, round);
}
}
示例3: tag
void CTagger :: updateLocalFeatureVector( SCORE_UPDATE method , const CTwoStringVector * sentence , unsigned long index , unsigned long round ) {
// abstd::cout words
CWord word = sentence->at( index ).first ;
CWord last_word = index > 0 ? sentence->at( index - 1 ).first : g_emptyWord ;
CWord next_word = index < sentence->size() - 1 ? sentence->at( index + 1 ).first : g_emptyWord ;
CStringVector chars , last_chars ;
chars.clear() ;
getCharactersFromUTF8String( sentence->at(index).first , &chars ) ;
last_chars.clear() ;
if ( index > 0 ) getCharactersFromUTF8String( sentence->at( index - 1 ).first , &last_chars ) ;
// abstd::cout length
int length = chars.size() ; //if ( length > LENGTH_MAX-1 ) length = LENGTH_MAX-1 ;
int last_length = last_chars.size() ; //if ( last_length > LENGTH_MAX-1 ) last_length = LENGTH_MAX-1 ;
// abstd::cout chars
CWord first_char = chars[ 0 ];
CWord last_char = chars[ chars.size() - 1 ];
CWord first_char_last_word = index > 0 ? last_chars[ 0 ] : g_emptyWord;
CWord last_char_last_word = index > 0 ? last_chars[ last_chars.size() - 1 ] : g_emptyWord;
CWord first_char_next_word = index + 1 < sentence->size() ? getFirstCharFromUTF8String( sentence->at( index + 1 ).first ) : g_emptyWord ;
CWord last_twochar_last_word = last_chars.size() > 1 ? last_chars[ last_chars.size() - 2 ] + last_chars[ last_chars.size() - 1]
: ( index > 1 ? getLastCharFromUTF8String(sentence->at(index-2).first) + last_chars[ 0 ] : g_emptyWord );
CWord first_twochar = chars.size() > 1 ? chars[ 0 ] + chars [ 1 ] : ( index + 1 <sentence->size() ? chars[ 0 ] + getFirstCharFromUTF8String( sentence->at( index + 1 ).first ) : g_emptyWord );
CWord currentword_lasttwochar = index > 1 ? last_twochar_last_word.str() + word.str() : g_emptyWord ;
CWord lastword_firsttwochar = index > 0 && index+1 < sentence->size() ? last_word.str() + first_twochar.str() : g_emptyWord ;
CWord two_char = index > 0 ? last_char_last_word.str() + first_char.str() : g_emptyWord ;
CWord lastword_firstchar = index > 0 ? last_word.str() + first_char.str() : g_emptyWord ;
CWord currentword_lastchar = index > 0 ? last_char_last_word.str() + word.str() : g_emptyWord ;
CWord three_char = length == 1 ? last_char_last_word.str() + word.str() + first_char_next_word.str() : g_emptyWord ;
CTwoWords two_word ;
// abstd::cout tags
const CTag tag( sentence->at(index).second ) ;
const CTag last_tag = index > 0 ? CTag( sentence->at( index-1 ).second) : CTag::SENTENCE_BEGIN ;
const CTag second_last_tag = index > 1 ? CTag( sentence->at( index-2 ).second) : CTag::SENTENCE_BEGIN ;
const CTagSet<CTag, 2> tag_bigram(encodeTags(tag, last_tag));
const CTagSet<CTag, 3> tag_trigram(encodeTags(tag, last_tag, second_last_tag));
CTaggedWord<CTag, TAG_SEPARATOR> wt1, wt2;
CTwoTaggedWords wt12;
// abstd::cout the char categories
long int first_char_cat = m_weights->m_mapCharTagDictionary.lookup(first_char) | (1<<tag.code()) ;
long int last_char_cat = m_weights->m_mapCharTagDictionary.lookup(last_char) | (1<<tag.code()) ;
SCORE_TYPE amount = method == eAdd ? 1 : -1 ;
m_weights->m_mapCurrentTag[ std::make_pair(word, tag) ].updateCurrent( amount , round ) ;
m_weights->m_mapLastTagByTag[ tag_bigram ].updateCurrent( amount , round ) ;
m_weights->m_mapLastTwoTagsByTag[ tag_trigram ].updateCurrent( amount , round ) ;
if ( index > 0 ) {
if ( last_length <= 2 ) m_weights->m_mapTagByLastWord[ std::make_pair(last_word, tag) ].updateCurrent( amount , round ) ;
if ( length <= 2 ) m_weights->m_mapLastTagByWord[ std::make_pair(word, last_tag) ].updateCurrent( amount , round ) ;
if ( length <= 2 ) m_weights->m_mapTagByWordAndPrevChar[ std::make_pair(currentword_lastchar, tag) ].updateCurrent( amount , round ) ;
if ( last_length <= 2 ) m_weights->m_mapTagByWordAndNextChar[ std::make_pair(lastword_firstchar, last_tag) ].updateCurrent( amount , round ) ;
}
if ( length == 1 ) {
if ( index > 0 && index < sentence->size() - 1 )
m_weights->m_mapTagOfOneCharWord[ std::make_pair(three_char, tag) ].updateCurrent( amount , round ) ;
}
else {
m_weights->m_mapTagByFirstChar[ std::make_pair(first_char, tag) ].updateCurrent( amount , round ) ;
m_weights->m_mapTagByLastChar[ std::make_pair(last_char, tag) ].updateCurrent( amount , round ) ; //
m_weights->m_mapTagByFirstCharCat[ std::make_pair(first_char_cat, tag) ].updateCurrent( amount , round ) ;
m_weights->m_mapTagByLastCharCat[ std::make_pair(last_char_cat, tag) ].updateCurrent( amount , round ) ;
for ( int j = 0 ; j < chars.size() ; ++ j ) {
if ( j > 0 && j < chars.size() - 1 )
m_weights->m_mapTagByChar[ std::make_pair(CWord(chars[j]), tag) ].updateCurrent( amount , round ) ;
if ( j > 0 ) {
wt1.load(chars[j], tag);
wt2.load(first_char);
wt12.allocate(wt1, wt2);
m_weights->m_mapTaggedCharByFirstChar[ wt12 ].updateCurrent( amount , round ) ;
if ( chars[j] == chars[j-1] ) m_weights->m_mapRepeatedCharByTag[ std::make_pair(CWord(chars[j]), tag) ].updateCurrent( amount , round ) ; //
}
if (j<chars.size()-1) {
wt1.load(chars[j], tag);
wt2.load(last_char);
wt12.allocate(wt1, wt2);
m_weights->m_mapTaggedCharByLastChar[ wt12 ].updateCurrent(amount, round);
}
}
}
}