本文整理汇总了C++中TChA::Trunc方法的典型用法代码示例。如果您正苦于以下问题:C++ TChA::Trunc方法的具体用法?C++ TChA::Trunc怎么用?C++ TChA::Trunc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TChA
的用法示例。
在下文中一共展示了TChA::Trunc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNGramBsFromLnDoc
PNGramBs TNGramBs::GetNGramBsFromLnDoc(
const TStr& LnDocFNm, const bool& NamedP, const int& MxDocs,
const int& MxNGramLen, const int& MnNGramFq,
const PSwSet& SwSet, const PStemmer& Stemmer){
// create n-gram-base
/* printf("Generating frequent n-grams (MaxLen:%d MinFq:%d) ...\n", MxNGramLen, MnNGramFq); */
PNGramBs NGramBs=TNGramBs::New(MxNGramLen, MnNGramFq, SwSet, Stemmer);
// interations over document-set
while (!NGramBs->IsFinished()){
// open line-doc file
TFIn FIn(LnDocFNm); char Ch=' '; int Docs=0;
while (!FIn.Eof()){
if(Ch == '\r' || Ch == '\n'){Ch = FIn.GetCh(); continue;}
Docs++; if ((MxDocs!=-1)&&(Docs>=MxDocs)){break;}
//printf("%d\r", Docs);
// document name
TChA DocNm;
if (NamedP){
Ch=FIn.GetCh();
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
DocNm+=Ch; Ch=FIn.GetCh();}
DocNm.Trunc();
if (DocNm.Empty()){Docs--; continue;}
}
// categories
TStrV CatNmV;
forever {
while ((!FIn.Eof())&&(Ch==' ')){Ch=FIn.GetCh();}
if (Ch=='!'){
TChA CatNm;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
CatNm+=Ch; Ch=FIn.GetCh();}
if (!CatNm.Empty()){CatNmV.Add(CatNm);}
} else {
break;
}
}
// document text
TChA DocChA;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')){
DocChA+=Ch; Ch=FIn.GetCh();}
// extract words & update ngram-base
/* printf(" Pass %2d: %6d Docs\r", NGramBs->GetPassN(), Docs); */
_UpdateNGramBsFromHtmlStr(NGramBs, DocChA, SwSet, Stemmer);
}
NGramBs->ConcPass();
}
/* printf("\nDone.\n"); */
// return
return NGramBs;
}
示例2: SaveLnDocToCpd
void TCpDoc::SaveLnDocToCpd(
const TStr& LnDocFNm, const TStr& OutCpdFNm, const bool& NamedP, const int& MxDocs){
printf("Saving Line-Document '%s' to '%s' ...\n", LnDocFNm.CStr(), OutCpdFNm.CStr());
// create output file
PSOut SOut=TFOut::New(OutCpdFNm);
// open line-doc file
TFIn FIn(LnDocFNm); char Ch=' '; int Docs=0;
while (!FIn.Eof()){
Docs++; if ((MxDocs!=-1)&&(Docs>=MxDocs)){break;}
printf("%d\r", Docs);
// document name
TChA DocNm;
if (NamedP){
Ch=FIn.GetCh();
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
DocNm+=Ch; Ch=FIn.GetCh();}
DocNm.Trunc();
if (DocNm.Empty()){Docs--; continue;}
}
// categories
TStrV CatNmV;
forever {
while ((!FIn.Eof())&&(Ch==' ')){Ch=FIn.GetCh();}
if (Ch=='!'){
if (!FIn.Eof()){Ch=FIn.GetCh();}
TChA CatNm;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
CatNm+=Ch; Ch=FIn.GetCh();}
if (!CatNm.Empty()){CatNmV.Add(CatNm);}
} else {
break;
}
}
// document text
TChA DocChA;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')){
DocChA+=Ch; Ch=FIn.GetCh();}
// skip empty documents (empty lines)
if (DocNm.Empty()&&DocChA.Empty()){
continue;}
// create & save cpd document
PCpDoc CpDoc=TCpDoc::New();
CpDoc->DocNm=DocNm;
CpDoc->ParStrV.Add(DocChA, 1);
for (int CatNmN=0; CatNmN<CatNmV.Len(); CatNmN++){
CpDoc->TopCdNmV.Add(CatNmV[CatNmN]);}
CpDoc->Save(*SOut);
}
printf("\nDone.\n");
}
示例3: LoadLnDocTxt
void TBowFl::LoadLnDocTxt(PBowDocBs BowDocBs, const TStr& LnDocFNm,
TIntV& NewDIdV, const bool& NamedP, const int& MxDocs, const bool& SaveDocP) {
// open line-doc file
NewDIdV.Clr(); TFIn FIn(LnDocFNm); char Ch=' '; int Docs=0;
while (!FIn.Eof()){
Docs++; if ((MxDocs!=-1)&&(Docs>=MxDocs)){break;}
printf("%d\r", Docs);
// document name
TChA DocNm;
Ch=FIn.GetCh();
if (NamedP){
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
DocNm+=Ch; Ch=FIn.GetCh();}
DocNm.Trunc();
if (DocNm.Empty()){Docs--; continue;}
} else {
DocNm = TInt::GetStr(Docs);
}
// categories
TStrV CatNmV;
forever {
while ((!FIn.Eof())&&(Ch==' ')){Ch=FIn.GetCh();}
if (Ch=='!'){
if (!FIn.Eof()){Ch=FIn.GetCh();}
TChA CatNm;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')&&(Ch!=' ')){
CatNm+=Ch; Ch=FIn.GetCh();}
if (!CatNm.Empty()){CatNmV.Add(CatNm);}
} else {
break;
}
}
// document text
TChA DocChA;
while ((!FIn.Eof())&&(Ch!='\r')&&(Ch!='\n')){
DocChA+=Ch; Ch=FIn.GetCh();}
// skip empty documents (empty lines)
if (DocNm.Empty()&&DocChA.Empty()){
continue;}
// add document to document-base
NewDIdV.Add(BowDocBs->AddHtmlDoc(DocNm, CatNmV, DocChA, SaveDocP));
}
// return document-base
BowDocBs->AssertOk();
printf("\n");
}