示例#1
0
void cLibsvmSink::fetchConfig()
{
  cDataSink::fetchConfig();
  
  filename = getStr("filename");
  SMILE_DBG(3,"filename = '%s'",filename);

  lag = getInt("lag");
  SMILE_DBG(3,"lag = %i",lag);

  append = getInt("append");
  if (append) { SMILE_DBG(3,"append to file is enabled"); }

  timestamp = getInt("timestamp");
  if (append) { SMILE_DBG(3,"printing timestamp attribute (index 1) enabled"); }

  instanceBase = getStr("instanceBase");
  SMILE_DBG(3,"instanceBase = '%s'",instanceBase);

  instanceName = getStr("instanceName");
  SMILE_DBG(3,"instanceName = '%s'",instanceName);
  
  int i;
  nClasses = getArraySize("class");
  classname = (char**)calloc(1,sizeof(char*)*nClasses);
  for (i=0; i<nClasses; i++) {
    const char *tmp = getStr_f(myvprint("class[%i]",i));
    if (tmp!=NULL) classname[i] = strdup(tmp);
  }

  if (isSet("targetNumAll")) {
    targetNumAll = getInt("targetNumAll");
  }
  if (isSet("targetStrAll")) {
    if (nClasses <=0) COMP_ERR("cannt have 'targetStrAll' option if no class names have been defined using the 'class' option! (inst '%s')",getInstName());
    targetNumAll = getClassIndex(getStr("targetStrAll"));
  }
  nInst = getArraySize("targetNum");
  if (nInst > 0) {
    target = (int *)calloc(1,sizeof(int)*nInst);
    for (i=0; i<nInst; i++) {
      target[i] = getInt_f(myvprint("targetNum[%i]",i));
      if (target[i] < 0) COMP_ERR("invalid class index %i for instance %i (in 'targetNum' option of instance '%s')",target[i],i,getInstName());
    }
  } else {
    nInst = getArraySize("targetStr");
    if (nInst > 0) {
      if (nClasses <=0) COMP_ERR("cannt have 'targetStr' option if no class names have been defined using the 'class' option! (inst '%s')",getInstName());
      target = (int *)calloc(1,sizeof(int)*nInst);
      for (i=0; i<nInst; i++) {
        target[i] = getClassIndex(getStr_f(myvprint("targetStr[%i]",i)));
        if (target[i] < 0) COMP_ERR("invalid class index %i for instance %i (from class '%s' in 'targetStr' option of instance '%s')",target[i],i,getStr_f(myvprint("targetStr[%i]",i)),getInstName());
      }
    } else { nInst = 0; }
  }

}
示例#2
0
// formating of log message, save result in msg
void cSmileLogger::fmtLogMsg(const char *type, char *t, int level, const char *m)
{
  if (t == NULL) return;
  if (msg != NULL) {
    free(msg); msg = NULL;
  }
  if ((type != NULL)&&(m!=NULL)) {
    msg = myvprint("(%s) [%i] in %s : %s",type,level,m,t);
  } else if (type != NULL) {
    msg = myvprint("(%s) [%i] : %s",type,level,t);
  } else if (m != NULL) {
    msg = myvprint("(MSG) [%i] in %s : %s",level,m,t);
  } else {
    msg = myvprint("(MSG) [%i] : %s",level,t);
  }
}
// TODO: option for output of modspec frequencies!
const char* cFunctionalModulation::getValueName(long i)
{
  const char *n = cFunctionalComponent::getValueName(0);
  // append coefficient number
  if (tmpstr_ != NULL) free(tmpstr_);
  tmpstr_ = myvprint("%s%i", n, i);
  return tmpstr_;
}
示例#4
0
// main log message dispatcher
void cSmileLogger::logMsg(int itype, char *s, int level, const char *m)
{
  if (!silence) {
    // check loglevel and type
    const char *type=NULL;
    switch (itype) {
       case LOG_PRINT :
            if (level > ll_msg) { free(s); return; }
            type=NULL;
            break;
       case LOG_MESSAGE :
            if (level > ll_msg) { free(s); return; }
            type=NULL;
            break;
       case LOG_ERROR :
            if (level > ll_err) { free(s); return; }
            type="ERROR";
            break;
       case LOG_WARNING :
            if (level > ll_wrn) { free(s); return; }
            type="WARN";
            break;
       case LOG_DEBUG :
            if (level > ll_dbg) { free(s); return; }
            type="DBG";
            break;
       default: return;
    }

    smileMutexLock(logmsgMtx);
    // format log message
    if (itype == LOG_PRINT) {
      if (msg != NULL) {
        free(msg); msg = NULL;
      }
      msg = myvprint("%s",s);
      if (_enableLogPrint) {
        // write to file
        writeMsgToFile(1);
      }

    } else {
      fmtLogMsg(type,s,level,m);
      // write to file
      writeMsgToFile();
    }
    free(s);
    

    // print to console
    if ((stde)||(logf == NULL)||(itype==LOG_PRINT))
      printMsgToConsole();

    smileMutexUnlock(logmsgMtx);
  }
}
int cFunctionalsVecToVec::setupNamesForField(int idxi, const char*name, long nEl)
{
  // in a winToVecProcessor , nEl should always be 1!
  int i,j;
  for (i=0; i<nFunctionalsEnabled; i++) {
//        printf("sunames %i i=%i fni=%i foi=%i\n",idxi,i,functN[i],(long)functObj[i]);

    if ( (functN[i] > 0) && (functObj[i] != NULL) ) {
      for (j=0; j<functN[i]; j++) {
//          printf("j=%i functN[%i]=%i\n",j,i,functN[i]);
        char * newname = myvprint("%s_%s",name,functObj[i]->getValueName(j));
        writer->addField( newname );
        free( newname );
      }
    }
  }
  return nFunctValues;
}
int cFunctionalsVecToVec::myConfigureInstance()
{
  int i,j;

  cComponentManager *_compman = getCompMan();
  if (_compman != NULL) {
    int nTp = _compman->getNtypes();
    nFunctTp = 0;
    for (i=0; i<nTp; i++) {
      const char * tp = _compman->getComponentType(i,1);
      if (tp!=NULL) {
        if (!strncmp(tp,"cFunctional",11)&&strcmp(tp,COMPONENT_NAME_CFUNCTIONALSVECTOVEC)) {
           // find beginning "cFunctional" but not our own type (cFunctinals)
          const char *fn = tp+11;
          if (nFunctTpAlloc == nFunctTp) { // realloc:
            functTp = (char **)crealloc( functTp, sizeof(char*)*(nFunctTpAlloc+N_BLOCK_ALLOC), nFunctTpAlloc );
            functTpI = (int *)crealloc( functTpI, sizeof(int)*(nFunctTpAlloc+N_BLOCK_ALLOC), nFunctTpAlloc );
            functI = (int *)crealloc( functI, sizeof(int)*(nFunctTpAlloc+N_BLOCK_ALLOC), nFunctTpAlloc );
            functN = (int *)crealloc( functN, sizeof(int)*(nFunctTpAlloc+N_BLOCK_ALLOC), nFunctTpAlloc );
            functObj = (cFunctionalComponent **)crealloc( functObj, sizeof(cFunctionalComponent *)*(nFunctTpAlloc+N_BLOCK_ALLOC), nFunctTpAlloc );
            nFunctTpAlloc += N_BLOCK_ALLOC;
          }
          functTp[nFunctTp] = strdup(fn);
          functTpI[nFunctTp] = i;
          nFunctTp++;
        }
      }
    }
  }
  SMILE_DBG(2,"(inst '%s') found %i cFunctionalXXXX component types.",getInstName(),nFunctTp);

  // fetch enabled functionals list
  nFunctionalsEnabled = getArraySize("functionalsEnabled");
  nFunctValues = 0;
  requireSorted = 0;
  for (i=0; i<nFunctionalsEnabled; i++) {
    const char *fname = getStr_f(myvprint("functionalsEnabled[%i]",i));
    char *tpname = myvprint("cFunctional%s",fname);
    for (j=0; j<nFunctTp; j++) {
      if (!strcmp(functTp[j],fname)) {
        functI[i] = j;
        break;
      }
    }
// TODO: find duplicates in functionalsEnabled Array!!!

    if (j<nFunctTp) {
      // and create corresponding component instances...
        SMILE_DBG(3,"(inst '%s') creating Functional object 'cFunctional%s'.",fname);
        char *_tmp = myvprint("%s.%s",getInstName(),fname);
        cFunctionalComponent * tmp = (cFunctionalComponent *)(_compman->createComponent)(_tmp,tpname);
        free(_tmp);
        if (tmp==NULL) OUT_OF_MEMORY;
        tmp->setComponentEnvironment(_compman, -1, this);
        functN[i] = tmp->getNoutputValues();
        requireSorted += tmp->getRequireSorted();
        nFunctValues += functN[i];
        functObj[i] = tmp;
        //functTp[i]  = strdup(fname);
    } else {
      SMILE_ERR(1,"(inst '%s') Functional object '%s' specified in 'functionalsEnabled' array, however no type 'cFunctional%s' exists!",getInstName(),fname,fname);
      functObj[i] = NULL;
      functN[i] = 0;
      free(tpname);
      return 0;
      //functTp[i]  = NULL;
    }
    free(tpname);
  }
  if (requireSorted)
    SMILE_DBG(2,"%i Functional components require sorted data.",requireSorted);

  return cVectorProcessor::myConfigureInstance();

}
示例#7
0
void cArffSink::fetchConfig()
{
  cDataSink::fetchConfig();
  
  filename = getStr("filename");
  if (filename == NULL || *filename == 0 || (*filename == '?' && *(filename+1) == 0)) {
    SMILE_IMSG(2, "No filename given, disabling this sink component.");
    disabledSink_ = true;
    errorOnNoOutput_ = 0;
  }

  lag = getInt("lag");
  SMILE_IDBG(3,"lag = %i",lag);

  append = getInt("append");
  if (append) { SMILE_IDBG(3,"append to file is enabled"); }

  printDefaultClassDummyAttribute = getInt("printDefaultClassDummyAttribute");
  
  if (isSet("frameTime")) timestamp = getInt("frameTime");
  else timestamp = getInt("timestamp");
  if (timestamp) { SMILE_IDBG(3,"printing timestamp attribute enabled"); }

  if (isSet("frameIndex")) number = getInt("frameIndex");
  else number = getInt("number");
  if (number) { SMILE_IDBG(3,"printing instance number (=frame number) attribute enabled"); }

  frameLength = getInt("frameLength");

  relation = getStr("relation");
  SMILE_IDBG(3,"ARFF relation = '%s'",relation);

  instanceBase = getStr("instanceBase");
  SMILE_IDBG(3,"instanceBase = '%s'",instanceBase);

  instanceName = getStr("instanceName");
  SMILE_IDBG(3,"instanceName = '%s'",instanceName);
  
  int i;
  nClasses = getArraySize("class");
  //printf("nclasses: %i\n", nClasses);
  classname = (char**)calloc(1,sizeof(char*)*nClasses);
  classtype = (char**)calloc(1,sizeof(char*)*nClasses);
  for (i=0; i<nClasses; i++) {
    const char *tmp = getStr_f(myvprint("class[%i].name",i));
    if (tmp!=NULL) classname[i] = strdup(tmp);
    tmp = getStr_f(myvprint("class[%i].type",i));
    if (tmp!=NULL) classtype[i] = strdup(tmp);
  }
/*
    ConfigType * classType = new ConfigType("arffClass");
    classType->setField("name", "name of target", "class");
    classType->setField("type", "numeric, or nominal (= list of classes)", "numeric");
    ct->setField("class","definition of class target attributes (array for multiple targets/classes)", classType, ARRAY_TYPE);

    ConfigType * targetType = new ConfigType("arffTarget");
    targetType->setField("instance", "array containing targets for each instance", 0,ARRAY_TYPE);
    targetType->setField("all", "one common target for all processed instances", 0);
*/

  if (getArraySize("target") != nClasses) {
    SMILE_ERR(1,"number of targets (%i) is != number of class attributes (%i)!",getArraySize("target"),nClasses);
  } else {
    targetall = (char**)calloc(1,sizeof(char*)*nClasses);
    targetinst = (char***)calloc(1,sizeof(char**)*nClasses);
    nInst = -2;
    for (i=0; i<nClasses; i++) {
      char *tmp = myvprint("target[%i].instance",i);
      const char *t = getStr_f(myvprint("target[%i].all",i));
      if (t!=NULL) targetall[i] = strdup(t);
      long ni = getArraySize(tmp);
      if (nInst==-2) nInst = ni; // -1 if no array
      else {
        if (nInst != ni) COMP_ERR("number of instances in target[].instance array is not constant among all targets! %i <> %i",nInst,ni);
      }
      int j;
      if (nInst > 0) {
        targetinst[i] = (char**)calloc(1,sizeof(char*)*nInst);
        for (j=0; j<nInst; j++) {
          t = getStr_f(myvprint("%s[%i]",tmp,j));
          if (t!=NULL) targetinst[i][j] = strdup(t);
        }
      }
      free(tmp);
    }
  }

  instanceNameFromMetadata = getInt("instanceNameFromMetadata");
  SMILE_IDBG(2,"instanceNameFromMetadata = %i",instanceNameFromMetadata);
  useTargetsFromMetadata = getInt("useTargetsFromMetadata");
  SMILE_IDBG(2,"useTargetsFromMetadata = %i",useTargetsFromMetadata);
  frameTimeAdd= getDouble("frameTimeAdd");
//    ct->setField("target","targets (classes) for each target (class) attribute",targetType,ARRAY_TYPE);
}
  // returned string must be freed by caller
  char * serializeToJson(int detail = 99) {
    char msgtypeNullterminated[CMSG_typenameLen + 1];
    char msgnameNullterminated[CMSG_typenameLen + 1];
    strncpy(msgtypeNullterminated, msgtype, CMSG_typenameLen);
    strncpy(msgnameNullterminated, msgname, CMSG_typenameLen);
    msgtypeNullterminated[CMSG_typenameLen] = 0;
    msgnameNullterminated[CMSG_typenameLen] = 0;

    std::string floatDataString = "";
    int nUserData = CMSG_nUserData;
    if (detail < 10) {
      nUserData = 1;
    } else if (detail < 20) {
      nUserData = 4;
    }
    for (int i = 0; i < CMSG_nUserData; ++i) {
      char * tmp = NULL;
      if (i != (CMSG_nUserData-1)) {
        tmp = myvprint("  \"%i\": %e,\n", i, floatData[i]);
      } else {
        tmp = myvprint("  \"%i\": %e\n", i, floatData[i]);
      }
      floatDataString += tmp;
      free(tmp);
    }
    std::string intDataString = "";
    for (int i = 0; i < CMSG_nUserData; ++i) {
      char * tmp = NULL;
      if (i != (CMSG_nUserData-1)) {
        tmp = myvprint("  \"%i\": %ld,\n", i, intData[i]);
      } else {
        tmp = myvprint("  \"%i\": %ld\n", i, intData[i]);
      }
      intDataString += tmp;
      free(tmp);
    }
    char * custDataText = NULL; // custDataType
    char * custData2Text = NULL;
    if (detail >= 40) {
      if (custData != NULL) {
        if (custDataType == CUSTDATA_TEXT) {
          custDataText = (char *)custData;
        }
        else if (custDataType == CUSTDATA_CHAR) {
          custDataText = (char *)calloc(1, sizeof(char) * (custDataSize + 1));
          strncpy(custDataText, (char *)custData, sizeof(char) * custDataSize);
        }
      }
      if (custData2 != NULL) {
        if (custData2Type == CUSTDATA_TEXT) {
          custData2Text = (char *)custData2;
        }
        else if (custData2Type == CUSTDATA_CHAR) {
          custData2Text = (char *)calloc(1, sizeof(char) * (custData2Size + 1));
          strncpy(custData2Text, (char *)custData2, sizeof(char) * custData2Size);
        }
      }
    }
    char * json = NULL;
    if (detail < 30) {
      json = myvprint("{\n"
          "\"msgtype\": \"%s\",\n"
          "\"msgname\": \"%s\",\n"
          "\"sender\": \"%s\",\n"
          "\"smileTime\": %f,\n"
          "\"userTime1\": %f,\n"
          "\"msgid\": %ld,\n"
          "\"floatData\": {\n%s},\n"
          "\"intData\": {\n%s},\n"
          "\"msgtext\": \"%s\"\n}",
          msgtypeNullterminated,
          msgnameNullterminated,
          sender,
          smileTime,
          userTime1,
          msgid,
          floatDataString.c_str(),
          intDataString.c_str(),
          msgtext);
    } else {
      json = myvprint("{\n"
          "\"msgtype\": \"%s\",\n"
          "\"msgname\": \"%s\",\n"
          "\"sender\": \"%s\",\n"
          "\"smileTime\": %f,\n"
          "\"userTime1\": %f,\n"
          "\"userTime2\": %f,\n"
          "\"readerTime\": %f,\n"
          "\"msgid\": %ld,\n"
          "\"floatData\": {\n%s},\n"
          "\"intData\": {\n%s},\n"
          "\"msgtext\": \"%s\",\n"
          "\"userflag1\": %i,\n"
          "\"userflag2\": %i,\n"
          "\"userflag3\": %i,\n"
          "\"custData\": \"%s\",\n"
          "\"custData2\": \"%s\"\n}",
          msgtypeNullterminated,
          msgnameNullterminated,
          sender,
          smileTime,
          userTime1,
          userTime2,
          readerTime,
          msgid,
          floatDataString.c_str(),
          intDataString.c_str(),
          msgtext,
          userflag1,
          userflag2,
          userflag3,
          custDataText,
          custData2Text
      );
    }
    if (custDataText != NULL && custData && custDataType != CUSTDATA_TEXT) {
      free(custDataText);
    }
    if (custData2Text != NULL && custData2 && custData2Type != CUSTDATA_TEXT) {
      free(custData2Text);
    }
    return json;
  }
    TumFeatureExtractor::TumFeatureExtractor(cComponentManager *_cMan, cConfigManager *_conf) throw(CMSException) : 
      ComponentForSmile("TumFeatureExtractor",_cMan,_conf,true,false),
      callbackRecv(NULL), emmaSender(NULL), featureSender(NULL), callbackReceiver(NULL)
    {
      if (_conf->isSet_f(myvprint("semaine.callbackRecv[%s]",getName().c_str()))) callbackRecv = _conf->getStr_f(myvprint("semaine.callbackRecv[%s]",getName().c_str()));

      if ((topicR != NULL)) {
        // check for multiple read topics separated by topicR
        char * tr = strdup(topicR);
        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--; }

          // push-back a callback receiver
          callbackReceiver = new XMLReceiver(tmp);
          receivers.push_back(callbackReceiver);
          printf("Receiver: '%s' \n",tmp);

          // analyse next part of string, if present
          if (x != NULL) {
            tmp = x+1;
          }
        } while (x !=  NULL);
        free(tr);
      } else {
        SMILE_WRN(1,"topicR == NULL in TumFeatureExtractor, please check semaineCfg section in config file (no voice data will be read from speech output for echo compensation).");
      }

      int period = 10; // ms

      if (topicW != NULL) {
        featureSender = new FeatureSender(topicW, "", getName(), period);
        //	featureSender = new FeatureSender("semaine.data.analysis.features.voice", "", getName(), period);

        waitingTime = period;
        senders.push_back(featureSender);
      } else {
        // TODO: use semaine exception here...
        SMILE_WRN(1,"topicW == NULL in TumFeatureExtractor, please check semaineCfg section in config file (no features will be sent now!).");
      }

      if (topicEmma != NULL) {
        emmaSender = new EmmaSender(topicEmma, getName());
        senders.push_back(emmaSender);
      } else {
        // TODO: use semaine exception here...
        SMILE_WRN(1,"topicEmma == NULL in TumFeatureExtractor, please check semaineCfg section in config file (no emma XML messages will be sent!).");
      }

      // Marc, 21 Dec 08: Deactivated, because it leads to dropped messages when the ASR
      // is on a different machine where the clock time is not the same.
      //featureSender->setTimeToLive(100); // discard messages after 100 ms

    }