本文整理汇总了C++中TStrV::Len方法的典型用法代码示例。如果您正苦于以下问题:C++ TStrV::Len方法的具体用法?C++ TStrV::Len怎么用?C++ TStrV::Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStrV
的用法示例。
在下文中一共展示了TStrV::Len方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddFtr
void TMultinomial::AddFtr(const TStrV& StrV, const TFltV& FltV, TIntFltKdV& SpV) const {
// make sure we either do not have explicit values, or their dimension matches with string keys
EAssertR(FltV.Empty() || (StrV.Len() == FltV.Len()), "TMultinomial::AddFtr:: String and double values not aligned");
// generate internal feature vector
SpV.Gen(StrV.Len(), 0);
for (int StrN = 0; StrN < StrV.Len(); StrN++) {
const int FtrId = FtrGen.GetFtr(StrV[StrN]);
// only use features we've seen during updates
if (FtrId != -1) {
const double Val = FltV.Empty() ? 1.0 : FltV[StrN].Val;
if (Val > 1e-16) { SpV.Add(TIntFltKd(FtrId, Val)); }
}
}
SpV.Sort();
// merge elements with the same id
int GoodSpN = 0;
for (int SpN = 1; SpN < SpV.Len(); SpN++) {
if (SpV[GoodSpN].Key == SpV[SpN].Key) {
// repetition of previous id, sum counts
SpV[GoodSpN].Dat += SpV[SpN].Dat;
} else {
// increase the pointer to the next good position
GoodSpN++;
// and move the new value down to the good position
SpV[GoodSpN] = SpV[SpN];
}
}
// truncate the vector
SpV.Trunc(GoodSpN + 1);
// replace values with 1 if needed
if (IsBinary()) { for (TIntFltKd& Sp : SpV) { Sp.Dat = 1.0; } }
// final normalization, if needed
if (IsNormalize()) { TLinAlg::Normalize(SpV); }
}
示例2: DocStrToWIdV
//////////////////////////////////////////////////////////////////////////
// String-To-Words
void TStrParser::DocStrToWIdV(const TStr& _DocStr, TIntV& WordIdV, const bool& Stemm) {
TStr DocStr = _DocStr.GetUc(); // to upper case
TStrV WordV; DocStr.SplitOnWs(WordV); int WordN = WordV.Len();
WordIdV.Reserve(WordN, 0);
PStemmer Stemmer = TStemmer::New(stmtPorter);
TIntH WordsInDoc;
for (int WordC = 0; WordC < WordN; WordC++) {
TStr WordStr;
if (Stemm) {
WordStr = Stemmer->GetStem(WordV[WordC]);
} else {
WordStr = WordV[WordC];
}
int WId = GetWId(WordStr);
if (WId == -1) {
WId = WordToIdH.AddKey(WordStr);
WordToIdH[WId] = 0;
}
WordIdV.Add(WId);
// is it first time we see this word in this doc?
if (!WordsInDoc.IsKey(WId)) WordsInDoc.AddKey(WId);
}
//do some statistics for DF
DocsParsed++;
for (int i = 0, l = WordsInDoc.Len(); i < l; i++)
WordToIdH[WordsInDoc.GetKey(i)]++;
Assert(WordV.Len() == WordIdV.Len());
}
示例3: FIn
//////////////////////////////////////
// URL-Redirect-Function
TSASFunRedirect::TSASFunRedirect(const TStr& FunNm,
const TStr& SettingFNm): TSAppSrvFun(FunNm, saotUndef) {
printf("Loading redirects %s\n", FunNm.CStr());
TFIn FIn(SettingFNm); TStr LnStr, OrgFunNm;
while (FIn.GetNextLn(LnStr)) {
TStrV PartV; LnStr.SplitOnAllCh('\t', PartV, false);
if (PartV.Empty()) { continue; }
if (PartV[0].Empty()) {
// parameters
EAssert(PartV.Len() >= 3);
TStr FldNm = PartV[1];
TStr FldVal = PartV[2];
if (FldVal.StartsWith("$")) {
MapH.GetDat(OrgFunNm).FldNmMapH.AddDat(FldVal.Right(1), FldNm);
} else {
MapH.GetDat(OrgFunNm).FldNmValPrV.Add(TStrKd(FldNm, FldVal));
}
} else {
// new function
EAssert(PartV.Len() >= 2);
OrgFunNm = PartV[0];
MapH.AddDat(OrgFunNm).FunNm = PartV[1];
printf(" %s - %s\n", PartV[0].CStr(), PartV[1].CStr());
}
}
printf("Done\n");
}
示例4: Update
bool TBagOfWords::Update(const TStrV& TokenStrV) {
// Generate Ngrams if necessary
TStrV NgramStrV;
GenerateNgrams(TokenStrV, NgramStrV);
// process tokens to update DF counts
bool UpdateP = false;
if (IsHashing()) {
// consolidate tokens and get their hashed IDs
TIntSet TokenIdH;
for (int TokenStrN = 0; TokenStrN < NgramStrV.Len(); TokenStrN++) {
const TStr& TokenStr = NgramStrV[TokenStrN];
TInt TokenId = TokenStr.GetHashTrick() % HashDim;
TokenIdH.AddKey(TokenId);
if (IsStoreHashWords()) { HashWordV[TokenId].AddKey(TokenStr); }
}
// update document counts
int KeyId = TokenIdH.FFirstKeyId();
while (TokenIdH.FNextKeyId(KeyId)) {
const int TokenId = TokenIdH.GetKey(KeyId);
// update DF
DocFqV[TokenId]++;
}
} else {
// consolidate tokens
TStrH TokenStrH;
for (int TokenStrN = 0; TokenStrN < NgramStrV.Len(); TokenStrN++) {
const TStr& TokenStr = NgramStrV[TokenStrN];
TokenStrH.AddKey(TokenStr);
}
// update document counts and update vocabulary with new tokens
int KeyId = TokenStrH.FFirstKeyId();
while (TokenStrH.FNextKeyId(KeyId)) {
// get token
const TStr& TokenStr = TokenStrH.GetKey(KeyId);
// different processing for hashing
int TokenId = TokenSet.GetKeyId(TokenStr);
if (TokenId == -1) {
// new token, remember the dimensionality change
UpdateP = true;
// remember the new token
TokenId = TokenSet.AddKey(TokenStr);
// increase document count table
const int TokenDfId = DocFqV.Add(0);
// increase also the old count table
OldDocFqV.Add(0.0);
// make sure we DF vector and TokenSet still in sync
IAssert(TokenId == TokenDfId);
IAssert(DocFqV.Len() == OldDocFqV.Len());
}
// document count update
DocFqV[TokenId]++;
}
}
// update document count
Docs++;
// tell if dimension changed
return UpdateP;
}
示例5: GetTokens
void TTokenizer::GetTokens(const TStrV& TextV, TVec<TStrV>& TokenVV) const {
IAssert(TextV.Len() == TokenVV.Len()); // shall we rather say Tokens.Gen(Texts.Len(), 0); ?
for (int TextN = 0; TextN < TextV.Len(); TextN++) {
TStrV& TokenV = TokenVV[TextN];
TokenVV.Gen(32,0); // assume there will be at least 32 tokens, to avoid small resizes
GetTokens(TextV[TextN], TokenV);
}
}
示例6: Dump
void TNEANetMP::Dump(FILE *OutF) const {
const int NodePlaces = (int) ceil(log10((double) GetNodes()));
const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
fprintf(OutF, " %*d]\n", NodePlaces, NodeI.GetId());
// load node attributes
TIntV IntAttrN;
IntAttrValueNI(NodeI.GetId(), IntAttrN);
fprintf(OutF, " nai[%d]", IntAttrN.Len());
for (int i = 0; i < IntAttrN.Len(); i++) {
fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
TStrV StrAttrN;
StrAttrValueNI(NodeI.GetId(), StrAttrN);
fprintf(OutF, " nas[%d]", StrAttrN.Len());
for (int i = 0; i < StrAttrN.Len(); i++) {
fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
TFltV FltAttrN;
FltAttrValueNI(NodeI.GetId(), FltAttrN);
fprintf(OutF, " naf[%d]", FltAttrN.Len());
for (int i = 0; i < FltAttrN.Len(); i++) {
fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }
fprintf(OutF, " in[%d]", NodeI.GetInDeg());
for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
fprintf(OutF, "\n");
fprintf(OutF, " out[%d]", NodeI.GetOutDeg());
for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
fprintf(OutF, "\n");
}
for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
fprintf(OutF, " %*d] %*d -> %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
// load edge attributes
TIntV IntAttrE;
IntAttrValueEI(EdgeI.GetId(), IntAttrE);
fprintf(OutF, " eai[%d]", IntAttrE.Len());
for (int i = 0; i < IntAttrE.Len(); i++) {
fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]());
}
TStrV StrAttrE;
StrAttrValueEI(EdgeI.GetId(), StrAttrE);
fprintf(OutF, " eas[%d]", StrAttrE.Len());
for (int i = 0; i < StrAttrE.Len(); i++) {
fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]());
}
TFltV FltAttrE;
FltAttrValueEI(EdgeI.GetId(), FltAttrE);
fprintf(OutF, " eaf[%d]", FltAttrE.Len());
for (int i = 0; i < FltAttrE.Len(); i++) {
fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]());
}
fprintf(OutF, "\n");
}
fprintf(OutF, "\n");
}
示例7: EscapableHandleScope
v8::Local<v8::Value> TNodeJsUtil::GetStrArr(const TStrV& StrV) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope EscapableHandleScope(Isolate);
v8::Local<v8::Array> JsStrV = v8::Array::New(Isolate, StrV.Len());
for (int StrN = 0; StrN < StrV.Len(); StrN++) {
JsStrV->Set(StrN, v8::String::NewFromUtf8(Isolate, StrV[StrN].CStr()));
}
return EscapableHandleScope.Escape(JsStrV);
}
示例8: CopyFolder
// copy files for a particular folder info
void TBackupProfile::CopyFolder(const TStr& BaseTargetFolder, const TStr& SourceFolder, const TStrV& Extensions, const TStrV& SkipIfContainingV, const bool& IncludeSubfolders, const bool& ReportP, TStr& ErrMsg)
{
try {
// get the name of the source folder
TStrV PathV; TDir::SplitPath(SourceFolder, PathV);
EAssert(PathV.Len() > 0);
// create the folder in the base target folder
TStr TargetFolder = BaseTargetFolder + PathV[PathV.Len() - 1] + "/";
if (!TDir::Exists(TargetFolder))
TDir::GenDir(TargetFolder);
// find files to be copied
TStrV FileV;
TFFile::GetFNmV(SourceFolder, Extensions, false, FileV);
TStrV FolderV;
// copy them
for (int N = 0; N < FileV.Len(); N++) {
// we found a file
if (TFile::Exists(FileV[N])) {
const TStr FileName = TDir::GetFileName(FileV[N]);
// is this a file that we wish to ignore?
bool ShouldCopy = true;
for (int S = 0; S < SkipIfContainingV.Len(); S++) {
if (FileName.SearchStr(SkipIfContainingV[S]) >= 0)
ShouldCopy = false;
}
if (!ShouldCopy)
continue;
const TStr TargetFNm = TargetFolder + FileName;
if (ReportP)
TNotify::StdNotify->OnStatusFmt("Copying file: %s\r", FileName.CStr());
TFile::Copy(FileV[N], TargetFNm);
}
// we found a folder
else {
FolderV.Add(FileV[N]);
}
}
if (IncludeSubfolders) {
for (int N = 0; N < FolderV.Len(); N++)
CopyFolder(TargetFolder, FolderV[N], Extensions, SkipIfContainingV, IncludeSubfolders, ReportP, ErrMsg);
}
}
catch (PExcept E) {
if (ErrMsg != "")
ErrMsg += "\n";
ErrMsg += "Exception while copying from " + SourceFolder + ": " + E->GetMsgStr();
}
catch (...) {
if (ErrMsg != "")
ErrMsg += "\n";
ErrMsg += "Exception while copying from " + SourceFolder + ": " + "Unrecognized exception occured.";
}
}
示例9: GetIfArgPrefixStrV
TStrV TEnv::GetIfArgPrefixStrV(
const TStr& PrefixStr, TStrV& DfValV, const TStr& DNm) const {
TStrV ArgValV;
if (Env.GetArgs()<=MnArgs) {
// 'usage' argument message
if (!SilentP) {
printf(" %s%s (default:", PrefixStr.CStr(), DNm.CStr());
for (int DfValN=0; DfValN<DfValV.Len(); DfValN++) {
if (DfValN>0) {
printf(", ");
}
printf("'%s'", DfValV[DfValN].CStr());
}
printf(")\n");
}
return ArgValV;
} else {
// argument & value message
TStr ArgValVChA;
for (int ArgN=0; ArgN<GetArgs(); ArgN++) {
// get argument string
TStr ArgStr=GetArg(ArgN);
if (ArgStr.StartsWith(PrefixStr)) {
// extract & add argument value
ArgStr.DelStr(PrefixStr);
ArgValV.Add(ArgStr);
// add to message string
if (ArgValV.Len()>1) {
ArgValVChA+=", ";
}
ArgValVChA+=ArgValV.Last();
}
}
if (ArgValV.Empty()) {
ArgValV=DfValV;
}
// output argument values
TChA MsgChA;
MsgChA+=" "+DNm;
MsgChA+=" (";
MsgChA+=PrefixStr;
MsgChA+=")=";
for (int ArgValN=0; ArgValN<ArgValV.Len(); ArgValN++) {
if (ArgValN>0) {
MsgChA+=", ";
}
MsgChA+="'";
MsgChA+=ArgValV[ArgValN];
MsgChA+="'";
}
if (!SilentP) {
TNotify::OnStatus(Notify, MsgChA);
}
return ArgValV;
}
}
示例10: mkdir
// Test drawing of SNAP graphs using GraphViz with color labeling
TEST(GVizTest, DrawGViz) {
PUNGraph UNGraph1;
UNGraph1 = LoadEdgeList<PUNGraph>(TStr::Fmt("%s/sample_ungraph1.txt", DIRNAME));
PNGraph NGraph1;
NGraph1 = LoadEdgeList<PNGraph>(TStr::Fmt("%s/sample_ngraph1.txt", DIRNAME));
mkdir(DIRNAME, S_IRWXU | S_IRWXG | S_IRWXO);
TStrV LNames; // gvlDot, gvlNeato, gvlTwopi, gvlCirco
LNames.Add("Dot");
LNames.Add("Neato");
LNames.Add("Twopi");
LNames.Add("Circo");
TStrV Exts;
Exts.Add("ps");
//Exts.Add("gif");
Exts.Add("png");
for (int i = 0; i < LNames.Len(); i++) {
for (int e = 0; e < Exts.Len(); e++) {
for (int d = 0; d < 2; d++) {
// Baseline file has already been created (use as benchmark)
TStr FNameBase = TStr::Fmt("%s/base_%s_%s.%s", DIRNAME, d ? "ngraph" : "ungraph" , LNames[i].CStr(), Exts[e].CStr());
TStr FNameTest = TStr::Fmt("%s/test_%s_%s.%s", DIRNAME, d ? "ngraph" : "ungraph" , LNames[i].CStr(), Exts[e].CStr());
// Remove test graph if it already exists
remove(FNameTest.CStr());
EXPECT_FALSE(fileExists(FNameTest.CStr()));
// Draw new graph and check if created and equal to baseline (for ps only)
if (d) {
TSnap::DrawGViz(NGraph1, TGVizLayout(i), FNameTest, LNames[i], true);
}
else {
TSnap::DrawGViz(UNGraph1, TGVizLayout(i), FNameTest, LNames[i], true);
}
// Check if file exists
EXPECT_TRUE(fileExists(FNameTest.CStr()));
#ifdef __linux
// Compare directly for ps files, (can't compare png and gif due to EXIF-labels)
if (Exts[e] == "ps") {
EXPECT_TRUE(compareFiles(FNameBase.CStr(), FNameTest.CStr()));
}
#endif
}
}
}
}
示例11: RestoreLatest
bool TFolderBackup::RestoreLatest(const TStr& ProfileName, const TBackupProfile::ERestoringMode& RestoringMode) const
{
if (ProfileH.IsKey(ProfileName)) {
TStrV FolderV; GetBackupFolders(ProfileName, FolderV);
if (FolderV.Len() > 0) {
ProfileH.GetDat(ProfileName).Restore(FolderV[FolderV.Len()-1], RestoringMode, ReportP);
return true;
}
}
return false;
}
示例12: Update
void TFtrGenBs::Update(const TStrV& FtrValV) {
EAssert(State == fgsUpdate);
EAssert(FtrValV.Len() == FtrGenV.Len());
try {
for (int FtrValN = 0; FtrValN < FtrValV.Len(); FtrValN++) {
FtrGenV[FtrValN]->Update(FtrValV[FtrValN]);
}
} catch (PExcept Ex) {
TExcept::Throw(TStr::Fmt("Error feature generation: '%s'!", Ex->GetMsgStr().CStr()));
}
}
示例13: ExtrCountry
/////////////////////////////////////////////////
// EuPartner
TStr TCordisEuPart::ExtrCountry(const TStr& AddrStr){
TStr CountryStr;
TStrV LnV; AddrStr.SplitOnStr("<br>", LnV);
if (LnV.Len()>0){
CountryStr=LnV.Last();
if (CountryStr.Empty()&&(LnV.Len()>1)){
CountryStr=LnV[LnV.Len()-2];}
CountryStr.DelChAll('\r');
CountryStr.DelChAll('\n');
}
if (CountryStr.Empty()){
printf("Country Field Not Found!\n");}
return CountryStr;
}
示例14: GenFtrV
void TFtrGenBs::GenFtrV(const TStrV& FtrValV, TIntFltKdV& FtrSpV) const {
EAssert(State == fgsGen);
EAssert(FtrValV.Len() == FtrGenV.Len());
try {
int Offset = 0;
for (int FtrValN = 0; FtrValN < FtrValV.Len(); FtrValN++) {
const PFtrGen& FtrGen = FtrGenV[FtrValN];
const TStr& FtrVal = FtrValV[FtrValN];
FtrGen->Add(FtrVal, FtrSpV, Offset);
}
} catch (PExcept Ex) {
TExcept::Throw(TStr::Fmt("Error feature generation: '%s'!", Ex->GetMsgStr().CStr()));
}
}
示例15: GetIfArgPrefixStrV
TStrV TEnv::GetIfArgPrefixStrV(const TStr& PrefixStr,
TStrV& DfValV,
const TStr& DNm) const {
TStrV ArgValV;
if (Env.GetArgs() <= MnArgs) {
// 'usage' argument message
if (!SilentP) {
printf(" %s%s (default:", PrefixStr.CStr(),
DNm.CStr());
for (int DfValN = 0; DfValN < DfValV.Len();
DfValN++) {
if (DfValN > 0) printf(", ");
printf("%s", DfValV[DfValN].CStr());
}
printf(")\n");
}
return ArgValV;
} else {
// argument & value message
TStrV Items;
for (int ArgN = 0; ArgN < GetArgs(); ArgN++) {
// get argument string
TStr ArgStr = GetArg(ArgN);
if (ArgStr.GetSubStr(0, PrefixStr.Len() - 1) ==
PrefixStr) {
TStr ArgVals = ArgStr.GetSubStr(
PrefixStr.Len(), ArgStr.Len());
ArgVals.SplitOnAllCh(',', Items);
for (int i = 0; i < Items.Len(); i++)
ArgValV.Add(Items[i]);
}
}
if (ArgValV.Empty()) ArgValV = DfValV;
// output argument values
TChA MsgChA;
MsgChA += DNm;
MsgChA += " (";
MsgChA += PrefixStr;
MsgChA += ")=";
for (int ArgValN = 0; ArgValN < ArgValV.Len();
ArgValN++) {
if (ArgValN > 0) MsgChA += ", ";
MsgChA += ArgValV[ArgValN];
}
if (!SilentP) TNotify::OnStatus(Notify, MsgChA);
return ArgValV;
}
}