Esempio n. 1
0
static void rx_xml (XmlStream& stream, XmlObject& xml_obj)
{
    if (xml_obj.get_namespace() == xml::namespace_uxmpp_error) {
        if (xml_obj.get_tag_name() == "parse-error") {
            uxmpp_log_error ("main", "XML parse error: ", xml_obj.get_content());
        }
        else if (xml_obj.get_tag_name() == "rx-error") {
            uxmpp_log_error ("main", "RX faliure: ", xml_obj.get_attribute("errnum"));
            //stream.stop ();
        }
        else {
            uxmpp_log_error ("main", "RX faliure: ", xml_obj.get_tag_name());
        }
        //stream.stop ();
    }
    else if (xml_obj.get_namespace() == xml::namespace_uxmpp_timer) {
        if (xml_obj.get_tag_name() == "timeout") {
            uxmpp_log_info ("main", "Got timeout: ", xml_obj.get_attribute("name"));
        }
        stream.write (xml_obj);
        stream.stop ();
    }else{
        //stream.set_timeout ("stop", 500);
        //uxmpp_log_info ("main", "Receivec xml: ", to_string(xml_obj));
        stream.write (xml_obj);
    }
}
Esempio n. 2
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. 3
0
int main (int argc, char* argv[])
{

    uxmpp_set_log_level (LogLevel::debug);

    if (argc < 4) {
        cerr << "Usage: test_XmlStream <xml_input_file> <xml_output_file> <top_node_name> [top_node_namespace]" << endl;
        return 1;
    }

    FileConnection in_file (argv[1], O_RDONLY);
    FileConnection out_file (argv[2], O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG);
    XmlStream xs (XmlObject(argv[3], argc>4 ? argv[4] : ""));

    xs.set_rx_cb (rx_xml);
    xs.set_timeout ("stop", 800);
    xs.run (in_file, out_file);

    cerr << "done" << endl;

    return 0;
}
void  FeatureNumList::ReadXML (XmlStream&      s,
                               XmlTagConstPtr  tag,
                               VolConstBool&   cancelFlag,
                               RunLog&         log
                             )
{
  maxFeatureNum = (IntType)tag->AttributeValueInt32 ("MaxFeatureNum");
  auto expectedNumOfFeatures = (IntType)tag->AttributeValueInt32 ("NumOfFeatures");
  numOfFeatures = 0;

  XmlTokenPtr  t = s.GetNextToken (cancelFlag, log);
  while  (t  &&  (!cancelFlag))
  {
    if  (typeid (*t) == typeid(XmlContent))
    {
      XmlContentPtr c = dynamic_cast<XmlContentPtr> (t);
      if  (c  &&  (c->Content ()))
      {
        bool  valid = false;
        ParseToString (*(c->Content ()), valid);
      }
    }

    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }

  delete  t;
  t = NULL;

  if  (expectedNumOfFeatures != numOfFeatures)
  {
    log.Level (-1) << endl
      << "FeatureNumList::ReadXML   ***ERROR***   expectedNumOfFeatures["  << expectedNumOfFeatures << "]  not equal  numOfFeatures[" << numOfFeatures << "]" << endl
      << endl;
  }
}  /* ReadXML */
Esempio n. 5
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 */
Esempio n. 6
0
void  ModelUsfCasCor::ReadXML (XmlStream&      s,
                               XmlTagConstPtr  tag,
                               VolConstBool&   cancelFlag,
                               RunLog&         log
                              )
{
  delete  usfCasCorClassifier;
  usfCasCorClassifier = NULL;

  XmlTokenPtr  t = s.GetNextToken (cancelFlag, log);
  while  (t  &&  (!cancelFlag))
  {
    t = ReadXMLModelToken (t, log);
    if  (t)
    {
      if  (t->VarName ().EqualIgnoreCase ("UsfCasCorClassifier")  &&  (typeid (*t) == typeid(XmlElementUsfCasCor)))
      {
        delete usfCasCorClassifier;
        usfCasCorClassifier = dynamic_cast<XmlElementUsfCasCorPtr>(t)->TakeOwnership ();
      }
      else
      {
        KKStr  errMsg (128);
        errMsg << "ModelUsfCasCor::ReadXML   ***ERROR***   Unexpected Element: Section: " << t->SectionName () << " VarName:" << t->VarName ();
        log.Level (-1) << endl << errMsg << endl << endl;
        AddErrorMsg (errMsg, 0);
      }
    }
    delete  t;
    t = s.GetNextToken (cancelFlag, log);
  }

  delete  t;
  t = NULL;

  if  (!cancelFlag)
  {
    if  (!param)
      param = dynamic_cast<ModelParamUsfCasCorPtr> (Model::param);

    if  (Model::param == NULL)
    {
      KKStr errMsg (128);
      errMsg << "ModelUsfCasCor::ReadXML  ***ERROR***  Base class 'Model' does not have 'param' defined.";
      AddErrorMsg (errMsg, 0);
      log.Level (-1) << endl << errMsg << endl << endl;
    }

    else if  (typeid (*Model::param) != typeid(ModelParamUsfCasCor))
    {
      KKStr errMsg (128);
      errMsg << "ModelUsfCasCor::ReadXML  ***ERROR***  Base class 'Model' param parameter is of the wrong type;  found: " << Model::param->ModelParamTypeStr ();
      AddErrorMsg (errMsg, 0);
      log.Level (-1) << endl << errMsg << endl << endl;
    }

    else
    {
      param = dynamic_cast<ModelParamUsfCasCorPtr> (Model::param);
    }

    ReadXMLModelPost (log);
  }
}  /* ReadXML */