Esempio n. 1
0
void  ModelParamUsfCasCor::ReadXML (XmlStream&      s,
                                    XmlTagConstPtr  tag,
                                    VolConstBool&   cancelFlag,
                                    RunLog&         log
                                   )
{
  XmlTokenPtr  t = s.GetNextToken (cancelFlag, log);
  while  (t  &&  (!cancelFlag))
  {
    t = ReadXMLModelParamToken (t);
    if  ((t != NULL)  &&  (t->TokenType () == XmlToken::TokenTypes::tokElement))
    {
      XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
      const KKStr&  varName = e->VarName ();

      if  (varName.EqualIgnoreCase ("in_limit"))
        in_limit =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("number_of_rounds"))
        number_of_rounds =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("number_of_trials"))
        number_of_trials =  dynamic_cast<XmlElementInt32Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("random_seed"))
        random_seed =  dynamic_cast<XmlElementInt64Ptr> (e)->Value ();

      else if  (varName.EqualIgnoreCase ("useCache"))
        useCache =  dynamic_cast<XmlElementBoolPtr> (e)->Value ();

      else
      {
        log.Level (-1) << endl
          << "ModelParamUsfCasCor::ReadXM   ***ERROR***   Unexpected Element: " << e->NameTag ()->ToString () << endl
          << endl;
      }
    }
    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }
  delete  t;
  t = NULL;

  bool  validFormat = false;
}  /* ReadXML */
Esempio n. 2
0
void  FeatureEncoder::ReadXML (XmlStream&      s,
                               XmlTagConstPtr  tag,
                               VolConstBool&   cancelFlag,
                               RunLog&         log
                              )
{
  XmlTokenPtr t = s.GetNextToken (cancelFlag,  log);
  while  (t  &&  (!cancelFlag))
  {
    if  (t->TokenType () == XmlToken::TokenTypes::tokElement)
    {
      XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
      if  (e)
      {
        KKStr varName = e->VarName ();

        if  (varName.EqualIgnoreCase ("CodedNumOfFeatures"))
          codedNumOfFeatures= e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("C_Param"))
          c_Param = e->ToDouble ();

        else if  (varName.EqualIgnoreCase ("NumEncodedFeatures"))
          numEncodedFeatures = e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("NumOfFeatures"))
          numOfFeatures = e->ToInt32 ();

        else if  (varName.EqualIgnoreCase ("xSpaceNeededPerExample"))
          xSpaceNeededPerExample = e->ToInt32 ();

        else if  (typeid (*e) == typeid (XmlElementArrayInt32))
        {
          XmlElementArrayInt32Ptr xmlArray = dynamic_cast<XmlElementArrayInt32Ptr> (e);
          kkuint32 count = xmlArray->Count ();
          if  (count != numOfFeatures)
          {
            log.Level (-1) << endl
              << "FeatureEncoder::ReadXML   ***ERROR***  Variable[" << varName << "]  Invalid Length[" << count << "]  Expected[" << numOfFeatures << "]" << endl
              << endl;
          }
          else
          {
            if  (varName.EqualIgnoreCase ("CardinalityDest"))
            {
              delete  cardinalityDest;
              cardinalityDest = xmlArray->TakeOwnership ();
            }

            else if  (varName.EqualIgnoreCase ("DestFeatureNums"))
            {
              delete  destFeatureNums;
              destFeatureNums = xmlArray->TakeOwnership ();
            }

            else if  (varName.EqualIgnoreCase ("SrcFeatureNums"))
            {
              delete  srcFeatureNums;
              srcFeatureNums = xmlArray->TakeOwnership ();
            }
          }
        }

        else if  (varName.EqualIgnoreCase ("Class1"))
          class1 = MLClass::CreateNewMLClass (e->ToKKStr (), -1);

        else if  (varName.EqualIgnoreCase ("Class2"))
          class2 = MLClass::CreateNewMLClass (e->ToKKStr (), -1);

        else if  (varName.EqualIgnoreCase ("FileDesc")  &&  (typeid (*e) == typeid (XmlElementFileDesc)))
          fileDesc = dynamic_cast<XmlElementFileDescPtr> (e)->Value ();

        else if  (varName.EqualIgnoreCase ("DestFileDesc")  &&  (typeid (*e) == typeid (XmlElementFileDesc)))
          destFileDesc = dynamic_cast<XmlElementFileDescPtr> (e)->Value ();

        else if  (varName.EqualIgnoreCase ("DestWhatToDo")  &&  (typeid (*e) == typeid (XmlElementVectorInt32)))
        {
          XmlElementVectorInt32Ptr  xmlVect = dynamic_cast<XmlElementVectorInt32Ptr> (e);
          if  (xmlVect  &&  xmlVect->Value ())
          {
            const VectorInt32&  v = *(xmlVect->Value ());
            if  (v.size () != numOfFeatures)
            {
              log.Level (-1) << endl
                << "FeatureEncoder::ReadXML   ***ERROR***   Variable[" << varName << "]  Invalid Size[" << v.size () << "]  Expected[" << numOfFeatures << "]." << endl
                << endl;
            }
            else
            {
              delete  destWhatToDo;
              destWhatToDo = new FeWhatToDo[v.size ()];
              for  (kkuint32 x = 0;  x < v.size ();  ++x)
                destWhatToDo[x] = (FeWhatToDo)v[x];
            }
          }
        }

        else if  (varName.EqualIgnoreCase ("EncodingMethod"))
          encodingMethod = EncodingMethodFromStr (e->ToKKStr ());

        else
        {
          log.Level (-1) << "XmlElementTrainingClassList   ***ERROR***   Un-expected Section Element[" << e->SectionName () << "]" << endl;
        }
      }
    }

    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }
  delete  t;
  t = NULL;
}  /* ReadXML */