コード例 #1
0
// start = 1: speaking status changed to start, start = 0: status changed to stop
void cSemaineUserinfoSender::sendOffTalk( cComponentMessage *msg )
{
  char strtmp[CMSG_textLen];
  sprintf(strtmp,"%ld", smileTimeToSemaineTime(msg->userTime1));
  std::string startTm(strtmp);

  std::string talk_dir = "unknown";
  if (msg->msgtext != NULL) {
    if (msg->msgtext[0] == 'o') {
      talk_dir = "on";
    } else if (msg->msgtext[0] == 'n') {
      talk_dir = "off";
    }
  }
  
  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, "0");
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * offtalk = XMLTool::appendChildElement(interpretation, SemaineML::E_OFFTALK, SemaineML::namespaceURI);
  XMLTool::setAttribute(offtalk, SemaineML::A_DIRECTION, talk_dir);
  XMLTool::setPrefix(offtalk, "semaine");

  // Now send it
  sendDocument(document);
}
コード例 #2
0
// start = 1: speaking status changed to start, start = 0: status changed to stop
void cSemaineUserinfoSender::sendSpeakingStatus( cComponentMessage *_msg, int start )
{
  const char *strtmp = "stop";
  if (start) strtmp = "start";
  
  std::string statusStr(strtmp);

  char strtmp2[50];
  sprintf(strtmp2,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp2);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, "0");
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * speaking = XMLTool::appendChildElement(interpretation, SemaineML::E_SPEAKING, SemaineML::namespaceURI);
  XMLTool::setAttribute(speaking, SemaineML::A_STATUS_CHANGE, strtmp);
  XMLTool::setPrefix(speaking, "semaine");

  // Now send it
  sendDocument(document);
}
コード例 #3
0
void cSemaineUserinfoSender::sendGender( cComponentMessage *_msg )
{
/*
<emma:emma version="1.0" xmlns:emma="http://www.w3.org/2003/04/emma">
    <emma:interpretation  emma:offset-to-start="12345" emma:confidence="0.3">

      <semaine:gender name="female" xmlns:semaine="http://www.semaine-project.eu/semaineml"/>

    </emma:interpretation>
</emma:emma>
*/
  
  const char *strtmp = "female";

  // manage gender result history buffer
  if (_msg->msgtext[0] == 'M') {
    gender[gPtr] = GENDER_M;
  } else {
    gender[gPtr] = GENDER_F;
  }

  gPtr++; 
  if (gPtr >= N_GENDER_HISTORY) gPtr = 0;

  // count # male/female in gender result history
  int m=0,f=0;
  int i;
  for (i=0; i<N_GENDER_HISTORY; i++) {
    if (gender[i] == GENDER_M) m++;
    else if (gender[i] == GENDER_F) f++;
  }

  // majority vote on gender
  if (m>f) { strtmp = "male"; }


  // fill XML document
  std::string genderStr(strtmp);

  char strtmp2[50];
  sprintf(strtmp2,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp2);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, "0");
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * gender = XMLTool::appendChildElement(interpretation, SemaineML::E_GENDER, SemaineML::namespaceURI);
  XMLTool::setAttribute(gender, SemaineML::A_NAME, strtmp);
  XMLTool::setPrefix(gender, "semaine");

  // Now send it
  sendDocument(document);
}
コード例 #4
0
void cSemaineEmmaSender::sendPitchDirection( cComponentMessage *_msg )
{
/*
<emma:emma version="1.0" xmlns:emma="http://www.w3.org/2003/04/emma">
    <emma:interpretation  emma:offset-to-start="12345" emma:duration="444" emma:confidence="0.3">

        <semaine:pitch xmlns:semaine="http://www.semaine-project.eu/semaineml" direction="rise"/>

    </emma:interpretation>
</emma:emma>
*/
  const char *strtmp = "rise"; // _msg->intData[0] == 0
  if (_msg->intData[0] == 1) strtmp = "fall";
  else if (_msg->intData[0] == 2) strtmp = "rise-fall";
  else if (_msg->intData[0] == 3) strtmp = "fall-rise";
  std::string pitchStr(strtmp);

  char strtmp2[50];
  sprintf(strtmp2,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp2);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, "0");
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * pitchDir = XMLTool::appendChildElement(interpretation, SemaineML::E_PITCH, SemaineML::namespaceURI);
  XMLTool::setAttribute(pitchDir, SemaineML::A_DIRECTION, strtmp);
  XMLTool::setPrefix(pitchDir, "semaine");

  // Now send it
  sendDocument(document);
}
コード例 #5
0
void cSemaineEmmaSender::sendSingleEmotionDim( cComponentMessage *_msg, const char * set, std::string dim )
{
  char strtmp[50];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string valStr(strtmp);

  sprintf(strtmp,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, duration);
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * emotion = XMLTool::appendChildElement(interpretation, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setPrefix(emotion, "emotion");

  XERCESC_NS::DOMElement * dimensions = XMLTool::appendChildElement(emotion, EmotionML::E_DIMENSIONS, EmotionML::namespaceURI);
  XMLTool::setAttribute(dimensions, EmotionML::A_SET, set);
  XMLTool::setPrefix(dimensions, "emotion");

  XERCESC_NS::DOMElement * dimension = XMLTool::appendChildElement(dimensions, dim, EmotionML::namespaceURI);
  XMLTool::setAttribute(dimension, EmotionML::A_VALUE, valStr);
  XMLTool::setPrefix(dimension, "emotion");

  // Now send it
  sendDocument(document);
}
コード例 #6
0
void cSemaineUserinfoSender::sendSpeakerId( cComponentMessage *msg )
{
/*
<emma:emma version="1.0" xmlns:emma="http://www.w3.org/2003/04/emma">
    <emma:interpretation  emma:offset-to-start="12345" emma:confidence="0.3">

      <semaine:speakerid id="1" name="spkA" modality="" xmlns:semaine="http://www.semaine-project.eu/semaineml"/>

    </emma:interpretation>
</emma:emma>
*/
  
  // fill XML document
  std::string idStr = "unknown";
  std::string idStrInt = "0";
  char strtmp2[50];
  if (msg->msgtext != NULL) {
    idStr = msg->msgtext;
  }
  sprintf(strtmp2, "%ld", msg->intData[0]);
  idStrInt = strtmp2;

  sprintf(strtmp2,"%ld",smileTimeToSemaineTime(msg->userTime1));
  std::string startTm(strtmp2);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, "0");
  XMLTool::setPrefix(interpretation, "emma");

  XERCESC_NS::DOMElement * id = XMLTool::appendChildElement(interpretation, SemaineML::E_SPEAKER, SemaineML::namespaceURI);
  XMLTool::setAttribute(id, SemaineML::A_NAME, idStr);
  XMLTool::setAttribute(id, SemaineML::A_VALUE, idStrInt);
  if (msg->msgname[0] == 'a') {  // audio
    XMLTool::setAttribute(id, SemaineML::A_MODALITY, "audio");
  } else if (msg->msgname[0] == 'v') {  // video
    XMLTool::setAttribute(id, SemaineML::A_MODALITY, "video");
  }
  XMLTool::setPrefix(id, "semaine");

  // Now send it
  sendDocument(document);
}
コード例 #7
0
void cSemaineEmotionSender::sendDimension( cComponentMessage *_msg, std::string dimensionStr, std::string dimensionVoc )
{
  // range check:
  if (_msg->floatData[0] < 0) _msg->floatData[0] = 0.0;
  if (_msg->floatData[0] > 1) _msg->floatData[0] = 1.0;
  //--

  char strtmp[50];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string dimVal(strtmp);

  sprintf(strtmp,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  sprintf(strtmp,"%s",(const char *)(_msg->custData2));
  std::string codername(strtmp);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, duration);
  XMLTool::setAttribute(interpretation, EMMA::A_CONFIDENCE, "1.0");
  XMLTool::setPrefix(interpretation, "emma");
  
  XERCESC_NS::DOMElement * emotion = XMLTool::appendChildElement(interpretation, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setAttribute(emotion, EmotionML::A_DIMENSION_VOCABULARY, dimensionVoc);
  XMLTool::setPrefix(emotion, "emotion");

  XERCESC_NS::DOMElement * dimension = XMLTool::appendChildElement(emotion, EmotionML::E_DIMENSION, EmotionML::namespaceURI);
  XMLTool::setAttribute(dimension, EmotionML::A_NAME, dimensionStr);
  XMLTool::setAttribute(dimension, EmotionML::A_VALUE, dimVal);
  XMLTool::setPrefix(dimension, "emotion");

  XERCESC_NS::DOMElement * info = XMLTool::appendChildElement(emotion, EmotionML::E_INFO);
  XERCESC_NS::DOMElement * coder = XMLTool::appendChildElement(info, "predictor");
  XMLTool::setAttribute(coder, "value", codername);
  XMLTool::setPrefix(coder, "emotion");
  XMLTool::setPrefix(info, "emotion");

  sendDocument(document);
}
コード例 #8
0
    void TumOpenSMILE::react(SEMAINEMessage * m) throw (std::exception) 
    {
      // use amqsource->writer to save data to dataMemory  (if configured to use source..)
      /*
      if (amqsource == NULL) {
      // TODO: use semaine exception here...
      SMILE_WRN(1,"amqsource == NULL in TumFeatureExtractor, please check semaineCfg section in config file (discarding received data!).");
      return;
      }
      */

      /*
      cDataWriter *writer = amqsource->getWriter();
      cVector *vec = amqsource->getVec();
      */

      // TOOD: parse Semaine Message and write features to dataMemory...
      // Problem: featureNames.....!! We must assign generic names like "feature01" to "featureNN" and update them after the first message.... yet, we also don't know how many features we will be receiving, if we have not received the first message... BIG PROBLEM!!

      printf("GOT MESSAGE '%i'\n",m); fflush(stdout);

        /*printf("y\n"); fflush(stdout);
        std::string a = m->getText();
        printf("b\n"); fflush(stdout);
        const char *ctype = a.c_str();
        printf("a\n"); fflush(stdout);
        printf("msg e type='%s'\n",ctype); fflush(stdout);*/

      SEMAINEXMLMessage * xm = dynamic_cast<SEMAINEXMLMessage *>(m);
      if (xm == NULL) {
        printf("xml message err '%s'\n",std::string(typeid(*m).name()));
        throw MessageFormatException("expected XML message, got "+std::string(typeid(*m).name()));
      }

      XERCESC_NS::DOMDocument * doc = xm->getDocument();
      XERCESC_NS::DOMElement * callback = doc->getDocumentElement();
      if (XMLTool::getNamespaceURI(callback) != SemaineML::namespaceURI ||
        XMLTool::getLocalName(callback) != "callback") {
          // check for userPresence message
          if (XMLTool::getNamespaceURI(callback) == SemaineML::namespaceURI ||
            XMLTool::getLocalName(callback) == "situational-context") {
              printf("userPresence msg\n");
              XERCESC_NS::DOMElement * user = XMLTool::getChildElementByLocalNameNS(callback, SemaineML::E_USER, SemaineML::namespaceURI);
              if (user != NULL) {
                std::string status = XMLTool::getAttribute(user, "status");
                const char *ctype = status.c_str();
                printf("msg type='%s'\n",ctype);
                //char *ctime = timeString.cStr();
                cComponentMessage callbackMsg("semaineCallback",ctype);
                callbackMsg.sender = "TumFeatureExtractor";
                cMan->sendComponentMessage(callbackRecv,&callbackMsg);

              }
          } else {
            // else:
            printf("xml message err, exp callback \n");
            throw MessageFormatException("Expected callback message, but found "+ XMLTool::getLocalName(callback) + " element in namespace " + XMLTool::getNamespaceURI(callback));
          }

      } else { // process callback

        XERCESC_NS::DOMElement * event = XMLTool::getChildElementByLocalNameNS(callback, SemaineML::E_EVENT, SemaineML::namespaceURI);
        if (event != NULL) {
          std::string type = XMLTool::getAttribute(event, "type");
          std::string timeString = XMLTool::getAttribute(event, SemaineML::A_TIME);
          const char *ctype = type.c_str();
          printf("msg type='%s'\n",ctype);
          //char *ctime = timeString.cStr();
          cComponentMessage callbackMsg("semaineCallback",ctype);
          callbackMsg.sender = "TumFeatureExtractor";
          cMan->sendComponentMessage(callbackRecv,&callbackMsg);

        }

      }

      /*
      SEMAINEFeatureMessage * fm = dynamic_cast<SEMAINEFeatureMessage *>(m);
      if (fm != NULL) {
      std::vector<float> features = fm->getFeatureVector();
      // TODO: get vecsize!!

      int i;
      for (i=0; i<vec->N; i++) { // limit to vecsize! !! TODO
      mat->dataF[i] = (FLOAT_DMEM)(features[i]);
      }
      writer->setNextFrame(vec);
      //TODO??
      }
      */	

    }
コード例 #9
0
void cSemaineWordSender::sendKeywords( cComponentMessage *_msg )
{
  int i;
  juliusResult *k = (juliusResult *)(_msg->custData);
  if (k==NULL) return;

  int nW = 0;
  for (i=0; i<k->numW; i++) {
    // check for non-verbals.... and remove them, only preceed if words are left
    if (k->word[i][0] != '*') nW++;
  }
  if (nW == 0) return;

  char strtmp[150];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string valStr(strtmp);
  long long startTime = smileTimeToSemaineTime(_msg->userTime1);
  sprintf(strtmp,"%ld",startTime);
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  // Create and fill a simple EMMA document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * sequence = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_SEQUENCE);
  XMLTool::setAttribute(sequence, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(sequence, EMMA::A_DURATION, duration);
  XMLTool::setPrefix(sequence, "emma");

  for (i=0; i<k->numW; i++) {

    // split combined keywords (TALK_TO_POPPY) etc. at the special character "_" and put them in individual tags
    /*
    char * tr = strdup(k->word[i]);
    char * tmp = tr;
    char * x = NULL;
    do {
      x = (char *)strchr(tmp, '_');
      // separate at '_'
      if (x!=NULL) {
        *x = 0;
      }

      // remove spaces
      //while (*tmp==' ') { tmp++; }
      //size_t l = strlen(tmp);
      //while (tmp[l-1] == ' ') { tmp[l-1] = 0; l--; }

      // append an xml keyword tag
      XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(sequence, EMMA::E_INTERPRETATION);
      sprintf(strtmp,"%ld",startTime + (long long)round((k->start[i])*1000.0));
      std::string offs(strtmp);
      sprintf(strtmp,"%s",tmp);
      std::string keyword(strtmp);
      sprintf(strtmp,"%.3f",k->conf[i]);
      std::string confidence(strtmp);
      XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, offs);
      XMLTool::setAttribute(interpretation, EMMA::A_TOKENS, keyword);
      XMLTool::setAttribute(interpretation, EMMA::A_CONFIDENCE, confidence);
      XMLTool::setPrefix(interpretation, "emma");


      // analyse next part of string, if present
      if (x != NULL) {
        tmp = x+1;
      }
    } while (x !=  NULL);
    free(tr);


*/
    // one word:
    
    if (k->word[i][0] != '*') {

      XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(sequence, EMMA::E_INTERPRETATION);
      sprintf(strtmp,"%ld",startTime + (long long)round((k->start[i])*1000.0));
      std::string offs(strtmp);
      sprintf(strtmp,"%s",k->word[i]);
      std::string keyword(strtmp);
      sprintf(strtmp,"%.3f",k->conf[i]);
      std::string confidence(strtmp);
      XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, offs);
      XMLTool::setAttribute(interpretation, EMMA::A_TOKENS, keyword);
      XMLTool::setAttribute(interpretation, EMMA::A_CONFIDENCE, confidence);
      XMLTool::setPrefix(interpretation, "emma");

    }
  }


  // Now send it
  sendDocument(document);
}
コード例 #10
0
void cSemaineEmmaSender::sendInterestC( cComponentMessage *_msg )
{
  char strtmp[50];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string interestStr(strtmp);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);

  sprintf(strtmp,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  XERCESC_NS::DOMElement * oneof = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_ONEOF);
  XMLTool::setAttribute(oneof, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(oneof, EMMA::A_DURATION, duration);
  XMLTool::setPrefix(oneof, "emma");

  XERCESC_NS::DOMElement * interpretation0 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);
  sprintf(strtmp,"%.3f",((double*)(_msg->custData))[0]);
  std::string conf0(strtmp);
  XMLTool::setAttribute(interpretation0, EMMA::A_CONFIDENCE, conf0);
  XMLTool::setPrefix(interpretation0, "emma");

  XERCESC_NS::DOMElement * emotion0 = XMLTool::appendChildElement(interpretation0, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setPrefix(emotion0, "emotion");
  XERCESC_NS::DOMElement * category0 = XMLTool::appendChildElement(emotion0, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category0, EmotionML::A_SET, "interestLevels");
  XMLTool::setAttribute(category0, EmotionML::A_NAME, "bored");
  XMLTool::setPrefix(category0, "emotion");

  XERCESC_NS::DOMElement * interpretation1 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);
  sprintf(strtmp,"%.3f",((double*)(_msg->custData))[1]);
  std::string conf1(strtmp);
  XMLTool::setAttribute(interpretation1, EMMA::A_CONFIDENCE, conf1);
  XMLTool::setPrefix(interpretation1, "emma");

  XERCESC_NS::DOMElement * emotion1 = XMLTool::appendChildElement(interpretation1, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setPrefix(emotion1, "emotion");
  XERCESC_NS::DOMElement * category1 = XMLTool::appendChildElement(emotion1, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category1, EmotionML::A_SET, "interestLevels");
  XMLTool::setAttribute(category1, EmotionML::A_NAME, "neutral");
  XMLTool::setPrefix(category1, "emotion");
  
  XERCESC_NS::DOMElement * interpretation2 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);
  sprintf(strtmp,"%.3f",((double*)(_msg->custData))[2]);
  std::string conf2(strtmp);
  XMLTool::setAttribute(interpretation2, EMMA::A_CONFIDENCE, conf2);
  XMLTool::setPrefix(interpretation2, "emma");

  XERCESC_NS::DOMElement * emotion2 = XMLTool::appendChildElement(interpretation2, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setPrefix(emotion2, "emotion");
  XERCESC_NS::DOMElement * category2 = XMLTool::appendChildElement(emotion2, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category2, EmotionML::A_SET, "interestLevels");
  XMLTool::setAttribute(category2, EmotionML::A_NAME, "interested");
  XMLTool::setPrefix(category2, "emotion");

  // Now send it
  sendDocument(document);
}
コード例 #11
0
void cSemaineEmotionSender::sendInterestC( cComponentMessage *_msg )
{
  char strtmp[50];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string interestStr(strtmp);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  sprintf(strtmp,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  XERCESC_NS::DOMElement * oneof = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_ONEOF);
  XMLTool::setAttribute(oneof, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(oneof, EMMA::A_DURATION, duration);
  XMLTool::setPrefix(oneof, "emma");

  double v = 0.0;
  //TODO: update this to new classification result message!  check that probEstim is not NULL....!
  XERCESC_NS::DOMElement * interpretation0 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);

  if (_msg->custData != NULL) v = ((double*)(_msg->custData))[0];
  sprintf(strtmp,"%.3f",v);
  std::string conf0(strtmp);
  XMLTool::setAttribute(interpretation0, EMMA::A_CONFIDENCE, conf0);
  XMLTool::setPrefix(interpretation0, "emma");

  XERCESC_NS::DOMElement * emotion0 = XMLTool::appendChildElement(interpretation0, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setAttribute(emotion0, EmotionML::A_CATEGORY_VOCABULARY , EmotionML::VOC_SEMAINE_INTEREST_CATEGORY_DEFINITION);
  XMLTool::setPrefix(emotion0, "emotion");
  
  XERCESC_NS::DOMElement * category0 = XMLTool::appendChildElement(emotion0, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category0, EmotionML::A_NAME, "bored");
  XMLTool::setPrefix(category0, "emotion");

  XERCESC_NS::DOMElement * interpretation1 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);
  if (_msg->custData != NULL) v = ((double*)(_msg->custData))[1];
  else v = 0;
  sprintf(strtmp,"%.3f",v);
  std::string conf1(strtmp);
  XMLTool::setAttribute(interpretation1, EMMA::A_CONFIDENCE, conf1);
  XMLTool::setPrefix(interpretation1, "emma");

  XERCESC_NS::DOMElement * emotion1 = XMLTool::appendChildElement(interpretation1, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setAttribute(emotion1, EmotionML::A_CATEGORY_VOCABULARY , EmotionML::VOC_SEMAINE_INTEREST_CATEGORY_DEFINITION);
  XMLTool::setPrefix(emotion1, "emotion");
  XERCESC_NS::DOMElement * category1 = XMLTool::appendChildElement(emotion1, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category1, EmotionML::A_NAME, "neutral");
  XMLTool::setPrefix(category1, "emotion");
  
  XERCESC_NS::DOMElement * interpretation2 = XMLTool::appendChildElement(oneof, EMMA::E_INTERPRETATION);
  if (_msg->custData != NULL) v = ((double*)(_msg->custData))[2];
  else v = 0;
  sprintf(strtmp,"%.3f",v);
  std::string conf2(strtmp);
  XMLTool::setAttribute(interpretation2, EMMA::A_CONFIDENCE, conf2);
  XMLTool::setPrefix(interpretation2, "emma");

  XERCESC_NS::DOMElement * emotion2 = XMLTool::appendChildElement(interpretation2, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setAttribute(emotion2, EmotionML::A_CATEGORY_VOCABULARY , EmotionML::VOC_SEMAINE_INTEREST_CATEGORY_DEFINITION);
  XMLTool::setPrefix(emotion2, "emotion");
  XERCESC_NS::DOMElement * category2 = XMLTool::appendChildElement(emotion2, EmotionML::E_CATEGORY, EmotionML::namespaceURI);
  XMLTool::setAttribute(category2, EmotionML::A_NAME, "interested");
  XMLTool::setPrefix(category2, "emotion");

  // Now send it
  sendDocument(document);
}
コード例 #12
0
void cSemaineEmotionSender::sendDimensionsFSRE_I( cComponentMessage *_msg )
{
  // range check:
  //if (_msg->floatData[0] < 0) _msg->floatData[0] = 0.0;
  //if (_msg->floatData[0] > 1) _msg->floatData[0] = 1.0;
  //--

  char strtmp[50];
  sprintf(strtmp,"%.2f",_msg->floatData[0]);
  std::string dimVal(strtmp);

  sprintf(strtmp,"%ld",smileTimeToSemaineTime(_msg->userTime1));
  std::string startTm(strtmp);
  sprintf(strtmp,"%ld",(long long)round((_msg->userTime2 - _msg->userTime1)*1000.0));
  std::string duration(strtmp);

  sprintf(strtmp,"%s",(const char *)(_msg->msgname));
  std::string codername(strtmp);

  // Create and fill a simple EMMA EmotionML document
  XERCESC_NS::DOMDocument * document = XMLTool::newDocument(EMMA::E_EMMA, EMMA::namespaceURI, EMMA::version);
  XMLTool::setPrefix(document->getDocumentElement(), "emma");

  XERCESC_NS::DOMElement * interpretation = XMLTool::appendChildElement(document->getDocumentElement(), EMMA::E_INTERPRETATION);
  XMLTool::setAttribute(interpretation, EMMA::A_OFFSET_TO_START, startTm);
  XMLTool::setAttribute(interpretation, EMMA::A_DURATION, duration);
  XMLTool::setAttribute(interpretation, EMMA::A_CONFIDENCE, "1.0");
  XMLTool::setPrefix(interpretation, "emma");
  
  XERCESC_NS::DOMElement * emotion = XMLTool::appendChildElement(interpretation, EmotionML::E_EMOTION, EmotionML::namespaceURI);
  XMLTool::setAttribute(emotion, EmotionML::A_DIMENSION_VOCABULARY, EmotionML::VOC_FSRE_DIMENSION_DEFINITION);
  XMLTool::setAttribute(emotion, EmotionML::A_MODALITY, "voice");
  XMLTool::setPrefix(emotion, "emotion");

  int i; int intIdx = -1;
  sClassifierResults * re = ((sClassifierResults*)(_msg->custData));
  for (i=0; i<re->nFilled; i++) {
    if (!strcmp(re->resnameA[i],intensityStr)) {
      intIdx = i; continue;
    }

    char strtmp[50];
    if (!strcmp(re->resnameA[i],unpredictabilityStr)) {
      re->res[i] = (1.0 - re->res[i])/2.0;   //// not nice hack...
    } else {
      re->res[i] = (re->res[i] + 1.0)/2.0;
    } 
    if (re->res[i] < 0.0) re->res[i] = 0.0;
    if (re->res[i] > 1.0) re->res[i] = 1.0;

    sprintf(strtmp,"%.2f",re->res[i]);
    std::string dimVal(strtmp);
    sprintf(strtmp,"%s",re->resnameA[i]);
    std::string dimStr(strtmp);

    XERCESC_NS::DOMElement * dimension = XMLTool::appendChildElement(emotion, EmotionML::E_DIMENSION, EmotionML::namespaceURI);
    XMLTool::setAttribute(dimension, EmotionML::A_NAME, dimStr); // dimensionStr
    XMLTool::setAttribute(dimension, EmotionML::A_VALUE, dimVal);
    XMLTool::setPrefix(dimension, "emotion");
  }

  XERCESC_NS::DOMElement * info = XMLTool::appendChildElement(emotion, EmotionML::E_INFO);
  XERCESC_NS::DOMElement * coder = XMLTool::appendChildElement(info, "predictor");
  XMLTool::setAttribute(coder, "value", codername);
  XMLTool::setPrefix(coder, "emotion");
  XMLTool::setPrefix(info, "emotion");

  if (intIdx >= 0) {
    XERCESC_NS::DOMElement * intensity = XMLTool::appendChildElement(interpretation, EmotionML::E_EMOTION, EmotionML::namespaceURI);
    XMLTool::setAttribute(intensity, EmotionML::A_DIMENSION_VOCABULARY, EmotionML::VOC_SEMAINE_INTENSITY_DIMENSION_DEFINITON);
    XMLTool::setAttribute(intensity, EmotionML::A_MODALITY, "voice");
    XMLTool::setPrefix(emotion, "emotion");

    sprintf(strtmp,"%.2f",re->res[intIdx]);
    std::string dimVal(strtmp);
    sprintf(strtmp,"%s",re->resnameA[intIdx]);
    std::string dimStr(strtmp);

    XERCESC_NS::DOMElement * idim = XMLTool::appendChildElement(intensity, EmotionML::E_DIMENSION, EmotionML::namespaceURI);
    XMLTool::setAttribute(idim, EmotionML::A_NAME, dimStr); // dimensionStr
    XMLTool::setAttribute(idim, EmotionML::A_VALUE, dimVal);
    XMLTool::setPrefix(idim, "emotion");

    XERCESC_NS::DOMElement * iinfo = XMLTool::appendChildElement(intensity, EmotionML::E_INFO);
    XERCESC_NS::DOMElement * icoder = XMLTool::appendChildElement(iinfo, "predictor");
    XMLTool::setAttribute(icoder, "value", codername);
    XMLTool::setPrefix(icoder, "emotion");
    XMLTool::setPrefix(iinfo, "emotion");
  }

  sendDocument(document);
}