Exemple #1
0
/* HTS_Question_load: Load questions from file */
static void HTS_Question_load(HTS_Question * question, FILE * fp)
{
   char buff[HTS_MAXBUFLEN];
   HTS_Pattern *pattern, *last_pattern;

   /* get question name */
   HTS_get_pattern_token(fp, buff);
   question->string = HTS_strdup(buff);
   question->head = NULL;
   /* get pattern list */
   HTS_get_pattern_token(fp, buff);
   last_pattern = NULL;
   if (strcmp(buff, "{") == 0) {
      while (1) {
         HTS_get_pattern_token(fp, buff);
         pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern));
         if (question->head)
            last_pattern->next = pattern;
         else                   /* first time */
            question->head = pattern;
         pattern->string = HTS_strdup(buff);
         pattern->next = NULL;
         HTS_get_pattern_token(fp, buff);
         if (!strcmp(buff, "}"))
            break;
         last_pattern = pattern;
      }
   }
}
Exemple #2
0
/* HTS_Tree_parse_pattern: parse pattern specified for each tree */
static void HTS_Tree_parse_pattern(HTS_Tree * tree, char *string)
{
   char *left, *right;
   HTS_Pattern *pattern, *last_pattern;

   tree->head = NULL;
   last_pattern = NULL;
   /* parse tree pattern */
   if ((left = strchr(string, '{')) != NULL) {  /* pattern is specified */
      string = left + 1;
      if (*string == '(')
         ++string;

      right = strrchr(string, '}');
      if (string < right && *(right - 1) == ')')
         --right;
      *right = ',';

      /* parse pattern */
      while ((left = strchr(string, ',')) != NULL) {
         pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern));
         if (tree->head) {
            last_pattern->next = pattern;
         } else {
            tree->head = pattern;
         }
         *left = '\0';
         pattern->string = HTS_strdup(string);
         string = left + 1;
         pattern->next = NULL;
         last_pattern = pattern;
      }
   }
}
Exemple #3
0
/* HTS_Label_load_from_strings: load label from strings */
void HTS_Label_load_from_strings(HTS_Label * label, size_t sampling_rate, size_t fperiod, char **lines, size_t num_lines)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   size_t i;
   size_t data_index;
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0) {
      HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n");
      return;
   }
   /* copy label */
   for (i = 0; i < num_lines; i++) {
      if (!isgraph((int) lines[i][0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      data_index = 0;
      if (isdigit_string(lines[i])) {   /* has frame infomation */
         HTS_get_token_from_string(lines[i], &data_index, buff);
         start = atof(buff);
         HTS_get_token_from_string(lines[i], &data_index, buff);
         end = atof(buff);
         HTS_get_token_from_string(lines[i], &data_index, buff);
         lstring->name = HTS_strdup(buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
         lstring->name = HTS_strdup(lines[i]);
      }
      lstring->next = NULL;
   }
   HTS_Label_check_time(label);
}
Exemple #4
0
/* HTS_Question_load: Load questions from file */
static HTS_Boolean HTS_Question_load(HTS_Question * question, HTS_File * fp)
{
   char buff[HTS_MAXBUFLEN];
   HTS_Pattern *pattern, *last_pattern;

   if (question == NULL || fp == NULL)
      return FALSE;

   /* get question name */
   if (HTS_get_pattern_token(fp, buff) == FALSE)
      return FALSE;
   question->string = HTS_strdup(buff);
   question->head = NULL;
   /* get pattern list */
   if (HTS_get_pattern_token(fp, buff) == FALSE) {
      free(question->string);
      question->string = NULL;
      return FALSE;
   }
   last_pattern = NULL;
   if (strcmp(buff, "{") == 0) {
      while (1) {
         if (HTS_get_pattern_token(fp, buff) == FALSE) {
            HTS_Question_clear(question);
            return FALSE;
         }
         pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern));
         if (question->head)
            last_pattern->next = pattern;
         else                   /* first time */
            question->head = pattern;
         pattern->string = HTS_strdup(buff);
         pattern->next = NULL;
         if (HTS_get_pattern_token(fp, buff) == FALSE) {
            HTS_Question_clear(question);
            return FALSE;
         }
         if (!strcmp(buff, "}"))
            break;
         last_pattern = pattern;
      }
   }
   return TRUE;
}
Exemple #5
0
/* HTS_Label_load: load label */
static void HTS_Label_load(HTS_Label * label, size_t sampling_rate, size_t fperiod, HTS_File * fp)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0) {
      HTS_error(1, "HTS_Label_load_from_fp: label is not initialized.\n");
      return;
   }

   /* parse label file */
   while (HTS_get_token_from_fp(fp, buff)) {
      if (!isgraph((int) buff[0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      if (isdigit_string(buff)) {       /* has frame infomation */
         start = atof(buff);
         HTS_get_token_from_fp(fp, buff);
         end = atof(buff);
         HTS_get_token_from_fp(fp, buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
      }
      lstring->next = NULL;
      lstring->name = HTS_strdup(buff);
   }
   HTS_Label_check_time(label);
}
/* HTS_Label_load_from_string: load label from string */
void HTS_Label_load_from_string(HTS_Label * label, int sampling_rate,
                                int fperiod, char *data)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   int data_index = 0;          /* data index */
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0)
      HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n");
   /* copy label */
   while (HTS_get_token_from_string(data, &data_index, buff)) {
      if (!isgraph(buff[0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next =
             (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      if (isdigit_string(buff)) {       /* has frame infomation */
         start = atof(buff);
         HTS_get_token_from_string(data, &data_index, buff);
         end = atof(buff);
         HTS_get_token_from_string(data, &data_index, buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
      }
      lstring->next = NULL;
      lstring->name = HTS_strdup(buff);
   }
   HTS_Label_check_time(label);
}