XmlTag::XmlTag (istream& i) { tagType = tagNULL; if (i.peek () == '<') i.get (); KKStr tagStr (100); ReadWholeTag (i, tagStr); if (tagStr.FirstChar () == '/') { tagStr.ChopFirstChar (); tagType = tagEnd; } if (tagStr.EndsWith ("/>")) { tagType = tagEmpty; tagStr.ChopLastChar (); tagStr.ChopLastChar (); } else if (tagStr.LastChar () != '>') { tagType = tagStart; } else { if (tagType == tagNULL) tagType = tagStart; tagStr.ChopLastChar (); } name.TrimLeft (); name.TrimRight (); name = tagStr.ExtractToken2 (" \n\r\t"); KKStr attributeName (20); KKStr attributeValue (20); while (!tagStr.Empty ()) { ExtractAttribute (tagStr, attributeName, attributeValue); if (!attributeName.Empty ()) attributes.push_back (XmlAttribute (attributeName, attributeValue)); } }
void RandomSplitJobManager::StatusFileProcessLine (const KKStr& _ln, istream& statusFile ) { KKStr ln (_ln); KKStr fieldName = ln.ExtractToken2 ("\t"); KKStr fieldValue = ln.ExtractToken2 ("\t"); if (fieldName.CompareIgnoreCase ("MLClasses") == 0) mlClasses = MLClassList::BuildListFromDelimtedStr (fieldValue, ','); else if (fieldName.CompareIgnoreCase ("ConfigFileName") == 0) configFileName = fieldValue; else if (fieldName.CompareIgnoreCase ("DataFileName") == 0) dataFileName = fieldValue; else if (fieldName.CompareIgnoreCase ("DataIndexFileName") == 0) dataIndexFileName = fieldValue; else if (fieldName.CompareIgnoreCase ("Format") == 0) format = FeatureFileIO::FileFormatFromStr (fieldValue); else if (fieldName.CompareIgnoreCase ("NumFolds") == 0) numFolds = fieldValue.ToInt (); else if (fieldName.CompareIgnoreCase ("NumSplits") == 0) numSplits = fieldValue.ToInt (); else if (fieldName.CompareIgnoreCase ("SplitFraction") == 0) { bool percentage = (fieldValue.LastChar () == '%'); if (percentage) { fieldValue.ChopLastChar (); splitFraction = fieldValue.ToFloat () / 100.0f; } else { splitFraction = fieldValue.ToFloat (); if (splitFraction > 1.0f) splitFraction = splitFraction / 100.0f; } } else KKJobManager::StatusFileProcessLine (_ln, statusFile); } /* StatusFileProcessLine */
void KKJobManager::ProcessJobXmlBlockOfText (const KKStr& startStr, istream& i ) { if ((startStr.SubStrPart (0, 4) != "<KKJob ") || (startStr.LastChar () != '>')) { log.Level (-1) << endl << "KKJobManager::ProcessJobXmlBlockOfText ***ERROR*** StartStr[" << startStr << "] is not a KKJob String." << endl << endl; return; } KKStr s = startStr.SubStrPart (5); s.TrimLeft (); s.ChopLastChar (); KKStr jobTypeStr = ""; kkint32 jobId = -1; VectorKKStr parameters = s.Split (','); for (kkuint32 x = 0; x < parameters.size (); ++x) { KKStr parameterStr = parameters[x]; parameterStr.TrimLeft (); parameterStr.TrimRight (); KKStr fieldName = parameterStr.ExtractToken2 ("="); fieldName.TrimLeft (); fieldName.TrimRight (); KKStr fieldValue = parameterStr.ExtractToken2 ("="); fieldValue.TrimLeft (); fieldValue.TrimRight (); if (fieldName.CompareIgnoreCase ("JobType") == 0) jobTypeStr = fieldValue; else if (fieldName.CompareIgnoreCase ("JobId") == 0) jobId = fieldValue.ToInt (); } if (jobTypeStr.Empty () || (jobId < 0)) { log.Level (-1) << endl << "KKJobManager::ProcessJobXmlBlockOfText ***ERROR*** StartStr[" << startStr << "]." << endl << " JobType and/or JobId were not provided." << endl << endl; return; } KKJobPtr j = jobs->LookUpByJobId (jobId); if (j == NULL) { // We do not have this job in memory yet. We will have to create it now. KKStr emptyStatusStr = "JobId\t" + StrFormatInt (jobId, "ZZZZ0"); j = KKJob::CallAppropriateConstructor (this, jobTypeStr, emptyStatusStr); } j->CompletedJobDataRead (i); } /* ProcessJobXmlBlockOfText */
bool RandomSplits::ProcessCmdLineParameter (char parmSwitchCode, KKStr parmSwitch, KKStr parmValue ) { KKStr parmValueUpper (parmValue); parmValueUpper.Upper (); parmSwitch.Upper (); if ((parmSwitch == "-CONFIGFILENAME") || (parmSwitch == "-C") || (parmSwitch == "-CONFIG")) { configFileName = parmValue; } else if ((parmSwitch == "-DATAFILE") || (parmSwitch == "-DF")) { dataFileName = parmValue; } else if ((parmSwitch == "-F") || (parmSwitch == "-FORMAT")) { format = FeatureFileIO::FileFormatFromStr (parmValue); if (!format) { log.Level (-1) << endl << endl << "ProcessCmdLineParameter ***ERROR*** No such format as[" << parmValue<< "]." << endl << endl; Abort (true); } } else if (parmSwitch.EqualIgnoreCase ("-NumFolds") || parmSwitch.EqualIgnoreCase ("-NF") || parmSwitch.EqualIgnoreCase ("-NumOfFolds") || parmSwitch.EqualIgnoreCase ("-NOF") ) { numFolds = parmValue.ToInt (); if ((numFolds != 0) && (numFolds < 2)) { log.Level (-1) << endl << "ProcessCmdLineParameter ***ERROR*** Invalid NumFolds[" << parmValue<< "]." << endl << " Must be '0' or greter than '1'." << endl << endl; Abort (true); } } else if ((parmSwitch == "-NUMSPLITS") || (parmSwitch == "-NS") || (parmSwitch == "-SPLITS")) { numSplits = parmValue.ToInt (); } else if ((parmSwitch == "-SPLITPERCENTAGE") || (parmSwitch == "-SP")) { bool percentage = false; if (parmValue.LastChar () == '%') { percentage = true; parmValue.ChopLastChar (); } splitFraction = parmValue.ToFloat (); if (percentage) splitFraction = splitFraction / 100.0f; else { if (splitFraction >= 1.0f) { log.Level (-1) << endl << endl << "ProcessCmdLineParameter ***ERROR*** Invalid Split Percentage[" << splitFraction << "]" << endl << endl << " If you want to enter as percentage include a '%' sign otherwise it is assumed to be a fraction." << endl << endl; } } } else if (parmSwitch.EqualIgnoreCase ("Restart")) { restart = true; } else { log.Level (-1) << endl << endl << "ProcessCmdLineParameter ***ERROR***" << endl << endl << " Invalid Parameter[" << parmSwitch << "]" << endl << endl; Abort (true); } return !Abort (); } /* ProcessCmdLineParameter */