本文整理汇总了C++中Wtroka类的典型用法代码示例。如果您正苦于以下问题:C++ Wtroka类的具体用法?C++ Wtroka怎么用?C++ Wtroka使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Wtroka类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddQuoteMultiWord
void CMultiWordCreator::AddQuoteMultiWord(CWordSequence& ws, const TArticleRef& article)
{
SWordHomonymNum wh;
Wtroka str;
CWord* pNewWord = GetWordForMultiWord(ws, str, wh);
if (pNewWord->m_SourceWords.Size() == 1 && pNewWord->HasOnlyUnknownPOS()) {
size_t firstId = pNewWord->IterHomonyms().GetID();
CHomonym& h = pNewWord->GetRusHomonym(firstId);
h.SetSourceWordSequence(&ws);
h.PutArticle(article);
wh.m_HomNum = firstId;
} else {
pNewWord->m_SourceWords.SetPair(ws.FirstWord(), ws.LastWord());
if (str.size() == 0)
str = pNewWord->m_txt;
TMorph::ToLower(str);
CHomonym* pNewHom = new CHomonym(TMorph::GetMainLanguage(), str);
pNewHom->SetSourceWordSequence(&ws);
pNewHom->PutArticle(article);
wh.m_HomNum = pNewWord->AddRusHomonym(pNewHom);
}
if (article.AuxDic().IsValid()) {
const article_t* pArt = GlobalDictsHolder->GetAuxArticle(article.AuxDic());
YASSERT(pArt != NULL);
AddFoundArticle(pArt->get_kw_type(), pArt->get_title(), wh);
} else {
YASSERT(!article.Gzt().Empty());
AddFoundArticle(article.Gzt().GetType(), article.Gzt().GetTitle(), wh);
}
m_wordSequences.push_back(&ws);
}
示例2: HasMorphNounWithGrammems_i
bool CWord::RightPartIsSurname(int& iH, THomonymGrammems& grammems, Wtroka& strLemma)
{
iH = HasMorphNounWithGrammems_i(TGramBitSet(gSurname));
if (iH != -1) {
CHomonym& h = GetRusHomonym(iH);
grammems = h.Grammems;
strLemma = h.GetLemma();
size_t ii = strLemma.find('-');
YASSERT(ii != Wtroka::npos);
strLemma = strLemma.substr(ii + 1);
return true;
}
//if this word is in morphology - do not try to predict
if (IsDictionary())
return false;
size_t ii = m_txt.find('-');
if (ii == Wtroka::npos)
return false;
Wtroka strRightPart = m_txt.substr(ii + 1);
TMorph::ToLower(strRightPart);
yvector<TSurnamePredictor::TPredictedSurname> out;
if (!TMorph::PredictSurname(strRightPart, out))
return false;
TGrammarBunch newForms;
NSpike::ToGrammarBunch(out[0].StemGrammar, out[0].FlexGrammars, newForms);
grammems.Reset(newForms);
strLemma = out[0].Lemma;
return true;
}
示例3: SetText
CWordBase::CWordBase(docLanguage lang,const CPrimGroup &prim,const Wtroka &strWord)
: m_lang(lang)
{
m_bHasAltWordPart = false;
m_typ = prim.m_gtyp;
m_num = prim.m_prim.size();
if (strWord.size() >= MAXWORD_LEN)
SetText(strWord.substr(0, MAXWORD_LEN - 2));
else
SetText(strWord);
m_pos = prim.m_pos;
m_len = prim.m_len;
m_bUp = false;
m_bHasUnusefulPostfix = false;
m_bHasOpenQuote = false;
m_bHasCloseQuote = false;
m_bSingleOpenQuote = false;
m_bSingleCloseQuote = false;
m_bIsPunct = false;
InitPunc();
}
示例4: ToFirstUpper
void ToFirstUpper(Wtroka& str)
{
if (!str.empty() && ::IsLower(str[0]))
*(str.begin()) = static_cast<wchar16>(::ToUpper(str[0]));
// TODO: this does not work properly for surrogate pairs (UTF-16)
}
示例5: EqualCiRus
bool EqualCiRus(const Wtroka& s1, const char* s2) {
static const CodePage& cp = *CodePageByCharset(CODES_WIN);
const ui16* w = s1.begin();
for (; w != s1.end() && *s2 != 0; ++w, ++s2)
if (::ToLower(*w) != ::ToLower(cp.unicode[static_cast<ui8>(*s2)]))
return false;
return w == s1.end() && *s2 == 0;
}
示例6: GetLemma
Wtroka CHomonym::GetLemma() const
{
if (m_pSourceWordSequence && (m_pSourceWordSequence->Size() > 1)) {
Wtroka s = m_pSourceWordSequence->GetLemma();
if (!s.empty())
return s;
}
return CHomonymBase::GetLemma();
}
示例7: AddHyphenSurnameLemma
//Try to predict double-word surname if the last part is found in dictionary.
//Then check if the first part is found in dictionary as surname.
//If it is not then try predicting it.
bool CWord::PredictHyphenSurname()
{
if (!((m_typ == Hyphen || m_typ == HypDiv || m_typ == DivWord) && m_variant.size() > 0))
return false;
size_t ii = m_txt.find('-');
if (ii == Wtroka::npos)
return false;
//only one hyphen is allowed
if (ii != m_txt.rfind('-'))
return false;
Wtroka strRightPart = m_txt.substr(ii + 1);
if (strRightPart.size() < 1 || !::IsUpper(strRightPart[0]))
return false;
int iH = -1;
THomonymGrammems rightPartGrammems;
Wtroka strRightPartLemma;
if (!RightPartIsSurname(iH, rightPartGrammems, strRightPartLemma))
return false;
ii = m_txt.find('-'); //unnecessary call?
if (ii == Wtroka::npos)
return false;
Wtroka strFirstPart = m_txt.substr(0, ii);
TMorph::ToLower(strFirstPart);
//look in morphology
THomonymVector res;
TMorph::GetDictHomonyms(strFirstPart, res);
bool found = false;
for (size_t i = 0; i < res.size(); ++i) {
if (!found && res[i]->HasGrammem(gSurname) &&
NGleiche::Gleiche(res[i]->Grammems, rightPartGrammems, NGleiche::GenderNumberCaseCheck)) {
found = true;
Wtroka joined_lemma = res[i]->GetLemma() + '-' + strRightPartLemma;
AddHyphenSurnameLemma(iH, rightPartGrammems, joined_lemma);
}
}
if (found)
return true;
//if the word was in morphology then do not do any further predictions
if (res.size() > 0)
return false;
yvector<TSurnamePredictor::TPredictedSurname> out;
TMorph::PredictSurname(strFirstPart, out);
if (out.size() > 0 && NGleiche::Gleiche(out[0].FlexGrammars, rightPartGrammems.Forms(), NGleiche::GenderNumberCaseCheck)) {
Wtroka joined_lemma = out[0].Lemma + '-' + strRightPartLemma;
AddHyphenSurnameLemma(iH, rightPartGrammems, joined_lemma);
return true;
}
return false;
}
示例8: Strip
void Strip(Wtroka& w) {
const wchar16* p = w.c_str();
const wchar16* pe = p + w.size();
while (p != pe) {
if (!IsWhitespace(*p)) {
if (p != w.c_str()) {
w.erase(w.c_str(), p);
}
pe = w.c_str() - 1;
p = pe + w.size();
while (p != pe) {
if (!IsWhitespace(*p))
break;
--p;
}
w.remove(p - pe); // it will not change the string if (p - pe) is not less than size
return;
}
++p;
}
// all characters are spaces
w.clear();
}
示例9: ReplaceSubstr
size_t ReplaceSubstr(Wtroka& str, const TWtringBuf& from, const TWtringBuf& to)
{
size_t count = 0;
size_t pos = str.off(TCharTraits<wchar16>::Find(~str, +str, ~from, +from));
while (pos != Wtroka::npos) {
str.replace(pos, +from, ~to, 0, Wtroka::npos, +to);
++count;
size_t next = pos + to.size();
pos = str.off(TCharTraits<wchar16>::Find(~str + next, +str - next, ~from, +from));
}
return count;
}
示例10: CreateTextField
void CQuotesFinder::CreateTextField(const Stroka& TextFieldName, CSentence* pSent, const SWordHomonymNum& WH,
CFactFields& factFields, const Wtroka& Postfix)
{
CNormalization InterpNorm(pSent->m_Words);
const CHomonym& h = pSent->m_Words[WH];
const CFioWordSequence* pFioWS = dynamic_cast<const CFioWordSequence*>(h.GetSourceWordSequence());
if (pFioWS != NULL) {
CFioWS newFioWS(*pFioWS);
newFioWS.SetMainWord(WH);
newFioWS.AddLemma(SWordSequenceLemma (InterpNorm.GetArtificialLemma(WH)));
CTextWS newTextWS;
newTextWS.SetPair(*pFioWS);
newTextWS.SetMainWord(WH);
newTextWS.ResetLemmas(newFioWS.GetLemmas(), true);
if (!Postfix.empty())
newTextWS.AddLemma(SWordSequenceLemma(Postfix));
factFields.AddValue(TextFieldName, newTextWS);
} else {
const CFactsWS* pFactWS = dynamic_cast<const CFactsWS*>(h.GetSourceWordSequence());
if (pFactWS) {
CTextWS newTextWS;
newTextWS.SetPair(*pFactWS);
newTextWS.SetMainWord(WH);
newTextWS.ResetLemmas(pFactWS->GetLemmas(), true);
if (!Postfix.empty())
newTextWS.AddLemma(SWordSequenceLemma(Postfix));
factFields.AddValue(TextFieldName, newTextWS);
} else {
const CTextWS* pTextWS = dynamic_cast<const CTextWS*>(h.GetSourceWordSequence());
if (pTextWS) {
CTextWS newTextWS = *pTextWS;
if (!Postfix.empty())
newTextWS.AddLemma(SWordSequenceLemma(Postfix));
factFields.AddValue(TextFieldName, newTextWS);
} else {
if (h.GetSourceWordSequence() == 0 || h.GetSourceWordSequence()->Size() == 1) {
CTextWS newTextWS;
newTextWS.SetPair(pSent->m_Words.GetWord(WH).GetSourcePair());
newTextWS.SetMainWord(WH);
newTextWS.AddLemma(SWordSequenceLemma(h.GetLemma()));
if (!Postfix.empty())
newTextWS.AddLemma(SWordSequenceLemma(Postfix));
factFields.AddValue(TextFieldName, newTextWS);
}
}
}
}
}
示例11: PutStrType
void SArtPointer::PutStrType(const Wtroka& s)
{
if (s.empty())
return;
m_strArt = s;
m_KWType = NULL;
}
示例12: getWord
bool CSentence::GetWSLemmaString(Wtroka& sLemmas, const CWordSequence& ws, bool bLem) const
{
sLemmas = ws.GetCapitalizedLemma();
if (bLem)
return !sLemmas.empty();
if (sLemmas.empty())
for (int j = ws.FirstWord(); j <= ws.LastWord(); j++) {
if (!sLemmas.empty())
sLemmas += ' ';
sLemmas += getWord(j)->GetOriginalText();
}
static const Wtroka trim_chars = CharToWide(" \"\'");
TWtringBuf res = sLemmas;
while (!res.empty() && trim_chars.find(res[0]) != TWtringBuf::npos)
res.Skip(1);
while (!res.empty() && trim_chars.find(res.back()) != TWtringBuf::npos)
res.Chop(1);
if (sLemmas.size() != res.size())
sLemmas = ::ToWtring(res);
return true;
}
示例13: GetSentPrc
// обычно функция возвращает clause->ToString(),
// если в клаузе есть открывающая кавычка, а нет закрывающей, тогда функция добавляет к результату
// все слова до закрывающей кавычки
Wtroka CQuotesFinder::FindRightQuoteIfHas(const CWordsPair& PeriodToPrint, int SentNo,
const CWordsPair& GroupToExclude, yvector<SFactAddress>& FioInQuotes)
{
FioInQuotes.clear();
CSentenceRusProcessor* pSentPrc = GetSentPrc(SentNo);
yset<int> QuoteWords;
Wtroka ClauseStr;
static const Wtroka COMMA = Wtroka::FromAscii(",");
for (int i = PeriodToPrint.FirstWord(); i <= PeriodToPrint.LastWord(); i++) {
const CWord& w = pSentPrc->m_Words.GetOriginalWord(i);
if (!GroupToExclude.Contains(i) &&
!(GroupToExclude.Contains(i - 1) && w.GetText() == COMMA) &&
!(GroupToExclude.Contains(i + 1) && w.GetText() == COMMA)) {
ClauseStr += w.GetOriginalText() + ' ';
QuoteWords.insert(i);
}
}
size_t index = ClauseStr.find('"');
if (index != Wtroka::npos && ClauseStr.rfind('"') == index) {
yset<int> AddQuoteWords;
Wtroka Add;
// если только одна кавычка, то пойдем искать вторую кавычку
int i;
for (i = PeriodToPrint.LastWord()+1; i < (int)pSentPrc->getWordsCount(); i++) {
const CWord& w = pSentPrc->m_Words.GetOriginalWord(i);
if (!GroupToExclude.Contains(i)) {
Add += w.GetOriginalText() + ' ';
AddQuoteWords.insert(i);
}
if (w.HasCloseQuote())
break;
}
if (i != (int)pSentPrc->getWordsCount()) {
ClauseStr += ' ';
ClauseStr += Add;
QuoteWords.insert(AddQuoteWords.begin(), AddQuoteWords.end());
}
}
AddFios(SentNo, QuoteWords, FioInQuotes);
return ClauseStr;
};
示例14: Collapse
void Collapse(Wtroka& w) {
size_t len = w.size();
for (size_t start = 0; start < len; ++start)
{
size_t n = 0;
for (; start + n < len; ++n)
{
if (!IsWhitespace(w[start + n]))
break;
}
if (n > 1 || (n == 1 && w[start] != ' ')) {
w.replace(start, n, 1, ' ');
len = w.size();
}
}
}
示例15: IsDoubleQuote
bool CWordBase::IsDoubleQuote(const Wtroka& str)
{
return str.size() == 1 && ::IsQuotation(str[0]) && str[0] != SINGLE_QUOTE_CHAR;
/*return IsChar(str, DOUBLE_QUOTE_CHAR) ||
IsChar(str, 127) || // wtf?
IsChar(str, 0x00BB) || // »
IsChar(str, 0x00AB) || // «
IsChar(str, 0x201C) || // “
IsChar(str, 0x201D); // ”
*/
}