Example #1
0
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 */
Example #3
0
void  Configuration::LoadFile (RunLog&  log)
{
  log.Level (10) << "Configuration::LoadFile: " << fileName << endl;

  kkint32  lastLineNum = 0;

  if  (fileName == "")
  {
    log.Level (-1) << endl
                   << "Configuration::LoadFile   ***ERROR***   File-Name is blank"  << endl
                   << endl;
    FormatGood (false);
    return;
  }

  FILE*  inFile = osFOPEN (fileName.Str (), "r");

  if  (!inFile)
  {
    log.Level (-1) << endl
                   << "Configuration::LoadFile   ***ERROR***    Opening File: " << fileName << endl
                   << endl;

    FormatGood (false);
    return;
  }

  char  buff[10240];
  kkint32 lineCount = 0;

  curSectionName = "";
  ConfSectionPtr  curSection = NULL;

  while  (fgets (buff, sizeof (buff), inFile))
  {
    lastLineNum++;
    KKStr  line (buff);
    line.TrimRight ();
    line.TrimLeft ();

    StripOutAnyComments (line);

    log.Level (70) << line << endl;
    
    StripOutAnyComments (line);

    if  (line.Empty ())            
    {
      // If we have a blank line, we do nothing.
    }

    else if  (line.FirstChar () == '[')
    {
      // Looks like definition of new section. 

      if  (line.LastChar () == ']')
      {
        curSectionName = line.SubStrPart (1, line.Len () - 2);
        curSectionName.TrimLeft ();
        curSectionName.TrimRight ();
        curSectionName.Upper ();

        curSection = new ConfSection (curSectionName, lastLineNum);
        sections->AddConfSection (curSection);
        log.Level (30) << "LoadFile   SectionName[" << curSectionName << "]." << endl;
      }
      else
      {
        log.Level (-1) << endl
                       << "Configuration::LoadFile   ***ERROR***    LineNumber[" << lastLineNum << "]  Improper Section Name[" << line << "]." << endl
                       << endl;
        formatGood = false;
      }
    }

    else
    {
      if  (!curSection)
      {
        log.Level (-1) << endl
                       << "Configuration::LoadFile   ***ERROR***  Format Error LineNumber[" << lastLineNum << "]" << endl
                       << "                            No Section Defined."  << endl 
                       << endl;
     
        formatGood = false;

        curSectionName = "GLOBAL";
        curSection = new ConfSection (curSectionName, lastLineNum);
        sections->AddConfSection (curSection);
      }

      kkint32  equalIdx = line.LocateCharacter ('=');

      if  (equalIdx < 0)
      {
        // We have a improperly formated line.
        log.Level (-1) << endl
                       << "Configuration::LoadFile   ***ERROR***   LineNumber[" << lastLineNum << "] Improperly Formated Line[" << line << "]." 
                       << endl;
        formatGood = false;
      }

      else
      {
        KKStr  settingName (line.SubStrPart (0, equalIdx - 1));
        settingName.TrimLeft ();
        settingName.TrimRight ();
        settingName.Upper ();

        KKStr  settingValue (line.SubStrPart (equalIdx + 1));
        settingValue.TrimLeft ();
        settingValue.TrimRight ();

        log.Level (30) << "LoadFile   SectionName[" << curSectionName << "], "
                       << "Setting[" << settingName << "], Value[" << settingValue   << "]."
                       << endl;

        curSection->AddSetting (settingName, settingValue, lastLineNum);
      }

      lineCount++;
    }
  }

  fclose (inFile);
}  /* LoadFile */
Example #4
0
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 */
Example #5
0
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 */