static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error) { SCrfSuiteUttProc *crfsuiteProc = (SCrfSuiteUttProc*)self; const SObject* filepath; S_CLR_ERR(error); s_bool isPresent = SUttProcessorFeatureIsPresent (self, "model_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SUtteranceFeatureIsPresent\" failed")) return; if (isPresent) { const SObject * vcfgObject = SVoiceGetFeature(voice, "config_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SVoiceGetFeature\" failed, failed to get voice config file")) return; const char * voice_base_path = s_get_base_path(SObjectGetString(vcfgObject, error), error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_get_base_path/SObjectGetString\" failed")) return; filepath = SUttProcessorGetFeature (self, "model_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SUtteranceGetFeature\" failed")) return; const char * path = SObjectGetString (filepath, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SObjectGetString\" failed")) return; crfsuiteProc->model_file = s_path_combine(voice_base_path, path, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_path_combine\" failed")) return; } else { S_CTX_ERR(error, S_FAILURE, "Initialize", "Failed to load the CRFSuite model."); return; } return; S_UNUSED(voice); }
static void Destroy(void *obj, s_erc *error) { SCrfSuiteUttProc *self = obj; S_CLR_ERR(error); S_UNUSED(self); }
static void Save(const SObject *object, const char *path, s_erc *error) { S_CTX_ERR(error, S_FAILURE, "Save", "Failed to save lexicon to file '%s', save method not implemented", path); S_UNUSED(object); }
static SObject *Load(const char *path, s_erc *error) { S_CTX_ERR(error, S_FAILURE, "Load", "Failed to load data from file '%s', load method not implemented", path); return NULL; S_UNUSED(path); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; char* type; SPhraseTypeFeatProc *castSelf = S_CAST(self, SPhraseTypeFeatProc, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to S_CAST failed")) goto quit_error; type = setSentenceType(item, castSelf->symbols, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SetSentenceType\" failed")) goto quit_error; if( type == NULL ) goto quit_error; extractedFeat = SObjectSetString( type, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetString\" failed")) goto quit_error; return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); S_UNUSED(item); }
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error) { S_CLR_ERR(error); /* get tokenization symbols defined in voicefile, now as features * of this utterance processor. If none, then defaults are used. */ s_get_tokenizer_symbols(S_UTTBREAK_UTTPROC(self), self->features, error); S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_get_tokenizer_symbols\" failed"); S_UNUSED(voice); }
/* helper function, see S_ITERATOR_GET macro in container.h */ S_API SIterator *_s_container_get_iterator_check(const void *self, s_erc *error) { const SContainer *tmp; S_CLR_ERR(error); tmp = S_CAST(S_OBJECT(self), SContainer, error); if (S_CHK_ERR(error, S_CONTERR, "_s_container_get_iterator_check", "Failed to cast given object to 'SContainer'")) return NULL; return SContainerGetIterator(S_CONTAINER(self), error); S_UNUSED(tmp); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itrItem; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; itrItem = item; count = -1; while (itrItem != NULL) { count++; itrItem = SItemPrev(itrItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static void InitWindow(SWinFunc **self, sint32 size, sint32 centre, s_erc *error) { uint32 i; S_CLR_ERR(error); if (size <= 0) { S_CTX_ERR(error, S_FAILURE, "InitWindow", "Window function given a 0 or negative size (%d)", size); goto quit_error; } /* nothing to do, window is correct */ if ((uint32)size == (*self)->num_samples) return; if ((*self)->samples != NULL) S_FREE((*self)->samples); (*self)->samples = S_MALLOC(float, size); if ((*self)->samples == NULL) { S_FTL_ERR(error, S_MEMERROR, "InitWindow", "Failed to allocate memory for 'float' object"); goto quit_error; } (*self)->num_samples = size; for (i = 0; i < (*self)->num_samples; i++) (*self)->samples[i] = 1.0; quit_error: S_DELETE(*self, "InitWindow", error); *self = NULL; S_UNUSED(centre); }
/* differs from create_B_context in that all is "x", pause does not * have a syllable */ static char *create_B_context_pause(const SItem *item, s_erc *error) { char *b_context; const char *all_x = "/B:x-x-x@x-x&x-x#x-x$x-x!x-x;x-x|x"; S_CLR_ERR(error); b_context = s_strdup(all_x, error); if (S_CHK_ERR(error, S_CONTERR, "create_B_context_pause", "Call to \"s_strdup\" failed")) { return NULL; } return b_context; S_UNUSED(item); }
/* differs from create_phone_syl_context in that all is "x", pause does not * have a syllable */ static char *create_syl_context_pause(const SItem *item, s_erc *error) { char *syl_context; const char *all_x = "x_x"; S_CLR_ERR(error); syl_context = s_strdup(all_x, error); if (S_CHK_ERR(error, S_CONTERR, "create_syl_context_pause", "Call to \"s_strdup\" failed")) { return NULL; } return syl_context; S_UNUSED(item); }
static void relation_items_table_free_fp(void *key, void *data, s_erc *error) { uint32 *item_node_number; S_CLR_ERR(error); item_node_number = key; /* * data are items. As soon as get_item is called (the item is * either retrieved from the table or created and added to the table) * then the item is also connected to the relation. So we do not need * to delete the item, as when we delete the relation the item will go * as well. */ if (item_node_number != NULL) S_FREE(item_node_number); S_UNUSED(data); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itrItem; sint32 count; SWordsToNextPuncFeatProc *castSelf = S_CAST(self, SWordsToNextPuncFeatProc, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to S_CAST failed")) goto quit_error; S_CLR_ERR(error); if (item == NULL) return NULL; itrItem = SItemPathToItem (item, "R:Token.parent", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) goto quit_error; SMap* posPunctuation = S_CAST( SMapGetObject ( castSelf->symbols, "pos punctuation", error ), SMap, error ); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SMapGetObject\" failed")) goto quit_error; if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_CAST\" failed")) goto quit_error; count = -1; s_bool found = FALSE; while (found == FALSE && itrItem != NULL) { count++; s_bool hasPos = SItemFeatureIsPresent ( itrItem, "POS", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemFeatureIsPresent\" failed")) goto quit_error; if (hasPos) { const char* keyPos = SItemGetString (itrItem, "POS", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetString\" failed")) goto quit_error; found= SMapObjectPresent(posPunctuation, keyPos, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SMapObjectPresent\" failed")) goto quit_error; } itrItem = SItemNext(itrItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; S_UNUSED(self); /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; }
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error) { const SObject *tmp; const SMap *syllInfo; const char *plugin_name; const char *class_name; SPlugin *sylPlugin; SSyllabification *syllab; S_CLR_ERR(error); /* check if a syllabification function is defined as a feature, * and if so, create the syllabification object */ tmp = SMapGetObjectDef(self->features, "syllabification function", NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapGetObjectDef\" failed")) return; /* nothing, return */ if (tmp == NULL) return; syllInfo = S_CAST(tmp, SMap, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"S_CAST (SMap)\" failed")) return; plugin_name = SMapGetString(syllInfo, "plug-in", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapGetString\" failed")) return; if (plugin_name == NULL) return; class_name = SMapGetString(syllInfo, "class", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapGetString\" failed")) return; if (class_name == NULL) return; /* load the plug-in */ sylPlugin = s_pm_load_plugin(plugin_name, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_pm_load_plugin\" failed")) return; /* create a syllabification object */ syllab = (SSyllabification*)S_NEW_FROM_NAME(class_name, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Failed to create new '%s' object", class_name)) { S_DELETE(sylPlugin, "Initialize", error); return; } /* add them to the features */ SMapSetObject(self->features, "_syll_func_plugin", S_OBJECT(sylPlugin), error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapSetObject\" failed")) { S_DELETE(syllab, "Initialize", error); S_DELETE(sylPlugin, "Initialize", error); return; } SMapSetObject(self->features, "_syll_func", S_OBJECT(syllab), error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapSetObject\" failed")) { /* plugin will be deleted when utt processor is deleted */ S_DELETE(syllab, "Initialize", error); return; } S_UNUSED(voice); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *phraseItem; const SItem *wordItem; const SItem *sylStructWordItem; const SItem *syllableItem; sint32 num_accented = 0; s_bool is_current_syl = FALSE; S_CLR_ERR(error); if (item == NULL) return NULL; /* get current phrase */ phraseItem = SItemPathToItem(item, "R:SylStructure.parent.R:Phrase.parent", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) goto quit_error; if (phraseItem == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get phrase of given syllable"); goto quit_error; } /* last word in phrase */ wordItem = SItemLastDaughter(phraseItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemLastDaughter\" failed")) goto quit_error; while (wordItem != NULL) { sylStructWordItem = SItemAs(wordItem, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; /* get syllables */ syllableItem = SItemLastDaughter(sylStructWordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemLastDaughter\" failed")) goto quit_error; while (syllableItem != NULL) { s_bool is_accented; is_current_syl = SItemEqual(syllableItem, item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemEqual\" failed")) goto quit_error; if (is_current_syl) break; is_accented = syl_is_accented(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"syl_is_accented\" failed")) goto quit_error; if (is_accented) num_accented++; syllableItem = SItemPrev(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; } if (is_current_syl) break; wordItem = SItemPrev(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(num_accented, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; char *hts_label = NULL; char *tmp = NULL; const SItem *segItem; s_bool is_pause; S_CLR_ERR(error); if (item == NULL) return NULL; segItem = SItemAs(item, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (segItem == NULL) return NULL; is_pause = segment_is_pause(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"segment_is_pause\" failed")) goto quit_error; /* get phone context */ tmp = create_phone_context(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_phone_context\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); if (is_pause) { /* syllable context */ tmp = create_syl_context_pause(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_syl_context_pause\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* A context */ tmp = create_A_context_pause(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_A_context_pause\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* B context */ tmp = create_B_context_pause(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_B_context_pause\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* C context */ tmp = create_C_context_pause(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_C_context_pause\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); } else { /* syllable context */ tmp = create_syl_context(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_syl_context\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* A context */ tmp = create_A_context(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_A_context\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* B context */ tmp = create_B_context(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_B_context\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); /* C context */ tmp = create_C_context(segItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"create_C_context\" failed")) goto quit_error; s_sappend(&hts_label, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_sappend\" failed")) goto quit_error; S_FREE(tmp); } extractedFeat = SObjectSetString(hts_label, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetString\" failed")) goto quit_error; S_FREE(hts_label); /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (tmp != NULL) S_FREE(tmp); if (hts_label != NULL) S_FREE(hts_label); if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; s_bool found = FALSE; SItem *boundary = SItemLastDaughter ( item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemLastDaughter\" failed")) goto quit_error; boundary = SItemAs (boundary, "Boundaries", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; SItem * boundaryNext = SItemNext (boundary, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; if (boundaryNext != NULL) boundary = boundaryNext; while (!found && boundary != NULL) { found = SItemFeatureIsPresent( boundary, "tobi_endtone", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemFeatureIsPresent\" failed")) goto quit_error; if (!found) { boundary = SItemPrev(boundary, error ); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; } } if ( found ) { const char* tone = SItemGetString( boundary, "tobi_endtone", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetFeature\" failed")) goto quit_error; extractedFeat = SObjectSetString( tone, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetString\" failed")) goto quit_error; } return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); S_UNUSED(item); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *syllableItem; sint32 num_syls = 1; /* include current syllable */ S_CLR_ERR(error); if (item == NULL) return NULL; /* get the syllable as in syllable relation */ syllableItem = SItemAs(item, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (syllableItem == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get the syllable as it is in the 'Syllable' relation"); goto quit_error; } /* start with the next syllable w.r.t the given one */ syllableItem = SItemNext(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; while (syllableItem != NULL) { s_bool is_stressed; is_stressed = syl_is_stressed(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"syl_is_stressed\" failed")) goto quit_error; if (is_stressed) break; else num_syls++; syllableItem = SItemNext(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(num_syls, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSylStructRel; const SItem *segment; const SItem *prevItem; float start = 0.0; S_CLR_ERR(error); if (item == NULL) return NULL; itemInSylStructRel = SItemAs(item, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; segment = SItemDaughter(itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemDaughter\" failed")) goto quit_error; /* the rest is the same as the segment start feature processor */ prevItem = SItemPrev(segment, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; if (prevItem == NULL) { /* there is no previous item, start is 0. */ extractedFeat = SObjectSetFloat(start, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetFloat\" failed")) goto quit_error; } else { start = SItemGetFloat(prevItem, "end", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetFloat\" failed")) goto quit_error; extractedFeat = SObjectSetFloat(start, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetFloat\" failed")) goto quit_error; } /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSentenceRel; const SItem *itr; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; itemInSentenceRel = SItemAs(item, "Sentence", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemRelation\" failed")) goto quit_error; SItem * sentenceItem = SItemParent (itemInSentenceRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemParent\" failed")) goto quit_error; itr = SItemLastDaughter (sentenceItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; count = 0; while (itr != NULL) { s_bool is_equal; is_equal = SItemEqual(itr, itemInSentenceRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemEqual\" failed")) goto quit_error; if (is_equal) break; count++; itr = SItemPrev(itr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static void Run(const SUttProcessor *self, SUtterance *utt, s_erc *error) { SCrfSuiteUttProc *crfsuiteProc = (SCrfSuiteUttProc*)self; crfsuite_model_t * ptr_model = malloc (sizeof(crfsuite_tagger_t)); crfsuite_tagger_t * ptr_tagger = malloc (sizeof(crfsuite_tagger_t)); crfsuite_dictionary_t * ptr_attrs = malloc (sizeof(crfsuite_dictionary_t)); crfsuite_dictionary_t * ptr_labels = malloc (sizeof(crfsuite_dictionary_t)); crfsuite_instance_t * instance = malloc (sizeof(crfsuite_instance_t)); /* Initialize model object */ if ( crfsuite_create_instance_from_file( crfsuiteProc->model_file, (void**)&ptr_model ) != 0 ) { goto exit_cleanup; } const SRelation* phrase = SUtteranceGetRelation(utt, "Phrase", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) return; SItem* itrPhrase = SRelationHead( phrase, error ); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) return; while ( itrPhrase != NULL ) { /* Obtain the dictionary interface representing the labels in the model. */ if ( ptr_model->get_labels(ptr_model, &ptr_labels) != 0) { goto exit_cleanup; } /* Obtain the dictionary interface representing the attributes in the model. */ if ( ptr_model->get_attrs(ptr_model, &ptr_attrs) != 0) { goto exit_cleanup; } /* Obtain the tagger interface. */ if ( ptr_model->get_tagger(ptr_model, &ptr_tagger) != 0) { goto exit_cleanup; } instance = create_phrase_instance ( itrPhrase, ptr_attrs, ptr_labels, error ); int *output = calloc(sizeof(int), instance->num_items); floatval_t score = 0; /* Set the instance to the tagger. */ if ( ptr_tagger->set(ptr_tagger, instance) != 0) { goto exit_cleanup; } /* Obtain the viterbi label sequence. */ if (ptr_tagger->viterbi(ptr_tagger, output, &score) != 0) { goto exit_cleanup; } /* Extract the output and insert in the POS attribute */ const SItem* tokenTMP = SItemPathToItem ( itrPhrase, "daughter.R:Token", error ); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) return; SItem* token = SItemParent (tokenTMP, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemParent\" failed")) return; const SItem* lastToken = SItemPathToItem ( itrPhrase, "n.daughter.R:Token.parent", error ); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) return; int i = 0; while ( token != NULL && token != lastToken ) { const char * str = malloc (sizeof (char)*16); ptr_labels->to_string (ptr_labels, output[i], &str); i += 1; SItemSetString (token, "POS", str, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetString\" failed")) return; token = SItemNext(token, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) return; } free(output); crfsuite_instance_finish(instance); itrPhrase = SItemNext(itrPhrase, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) return; } /* here all is OK */ S_UNUSED(utt); exit_cleanup: if ( ptr_model != NULL ) free ( ptr_model ); if ( ptr_tagger != NULL ) free ( ptr_tagger ); if ( ptr_attrs != NULL ) free ( ptr_attrs ); if ( ptr_labels != NULL ) free ( ptr_labels ); if ( instance != NULL ) free ( instance ); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SUtterance *utt; const SRelation *sylRel; const SItem *itr; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; /* get utterance */ utt = SItemUtterance(item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemUtterance\" failed")) goto quit_error; if (utt == NULL) return NULL; /* get Syllable relation */ sylRel = SUtteranceGetRelation(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) goto quit_error; if (sylRel == NULL) return NULL; itr = SRelationHead(sylRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; count = 0; while (itr != NULL) { count++; itr = SItemNext(itr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *wordItem; sint32 num_words = 1; /* include current word */ S_CLR_ERR(error); if (item == NULL) return NULL; /* get the word as in the word relation */ wordItem = SItemAs(item, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (wordItem == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get given word as in 'Word' relation"); goto quit_error; } /* start with next word */ wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; while (wordItem != NULL) { s_bool is_content; is_content = word_is_content(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"word_is_content\" failed")) goto quit_error; if (is_content) break; else num_words++; wordItem= SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(num_words, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *phraseItem; const SItem *wordItem; sint32 num_content = 0; S_CLR_ERR(error); if (item == NULL) return NULL; /* get current phrase */ phraseItem = SItemPathToItem(item, "R:Phrase.parent", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) goto quit_error; if (phraseItem == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get phrase of given word"); goto quit_error; } wordItem = SItemDaughter(phraseItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemDaughter\" failed")) goto quit_error; while (wordItem != NULL) { s_bool is_content; s_bool is_current_word; is_current_word = SItemEqual(wordItem, item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemEqual\" failed")) goto quit_error; if (is_current_word) break; is_content = word_is_content(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"word_is_content\" failed")) goto quit_error; if (is_content) num_content++; wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(num_content, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSylStructRel; const SItem *itrItem = NULL; const SObject* feature = NULL; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; itemInSylStructRel = SItemAs(item, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (itemInSylStructRel == NULL) { extractedFeat = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; } else { itrItem = SItemDaughter(itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemDaughter\" failed")) goto quit_error; } count = 0; while (itrItem != NULL) { feature = SItemPathToFeatProc(itrItem, "syllable_num_phones", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToFeatProc\" failed")) goto quit_error; if(feature == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Call to \"SItemPathToFeatProc\" returned null"); goto quit_error; } count += SObjectGetInt(feature, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectGetInt\" failed")) goto quit_error; itrItem = SItemNext(itrItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSylStructRel; const SItem *segment; const SPhoneset *phoneset; s_bool multilingual = FALSE; S_CLR_ERR(error); if (item == NULL) return NULL; /* get the phoneset */ phoneset = _get_phoneset(item, &multilingual, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"_get_phoneset\" failed")) return NULL; itemInSylStructRel = SItemAs(item, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; segment = SItemDaughter(itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemDaughter\" failed")) goto quit_error; while (segment != NULL) { s_bool is_vowel; const char *item_name; item_name = SItemGetName(segment, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetName\" failed")) goto quit_error; if (item_name == NULL) continue; is_vowel = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset, item_name, "vowel", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"phone_has_feature\" failed")) goto quit_error; if (is_vowel) { if (multilingual) { extractedFeat = SItemPathToFeatProc(segment, "segment_name_multilingual", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToFeatProc\" failed")) goto quit_error; } else { extractedFeat = SObjectSetString(item_name, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetString\" failed")) goto quit_error; } return extractedFeat; } segment = SItemNext(segment, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } /* did not find a vowel */ extractedFeat = SObjectSetString("novowel", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetString\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSegRel; const SItem *prevItem; float start = 0.0; float end = 0.0; S_CLR_ERR(error); if (item == NULL) return NULL; itemInSegRel = SItemAs(item, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; prevItem = SItemPrev(itemInSegRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; if (prevItem != NULL) { start = SItemGetFloat(prevItem, "end", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetFloat\" failed")) goto quit_error; } end = SItemGetFloat(item, "end", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetFloat\" failed")) goto quit_error; extractedFeat = SObjectSetFloat((float)((end - start)/2.0), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetFloat\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *syllWord; const SItem *itemInSylStructRel; const SItem *wordInPhrase; const SItem *phrase; const SItem *itr; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; /* syllable as in SylStructure */ itemInSylStructRel = SItemAs(item, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (itemInSylStructRel == NULL) goto quit_null; /* syllable's word */ syllWord = SItemParent(itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemParent\" failed")) goto quit_error; if (syllWord == NULL) goto quit_null; /* as in phrase structure */ wordInPhrase = SItemAs(syllWord, "Phrase", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (wordInPhrase == NULL) goto quit_null; /* get phrase */ phrase = SItemParent(wordInPhrase, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemParent\" failed")) goto quit_error; if (phrase == NULL) goto quit_null; itr = SItemLastDaughter(phrase, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemLastDaughter\" failed")) goto quit_error; count = 0; while (itr != NULL) { s_bool is_equal; is_equal = SItemEqual(itr, syllWord, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemEqual\" failed")) goto quit_error; if (is_equal) break; count += word_num_syls(itr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"word_num_syls\" failed")) goto quit_error; itr = SItemPrev(itr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPrev\" failed")) goto quit_error; } count += syll_pos_word_rev(item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"syll_pos_word_rev\" failed")) goto quit_error; extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; /* return 0 */ quit_null: extractedFeat = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; return extractedFeat; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SItem *itemInSylStructRel; const SItem *syllableItem; const SItem *itr; sint32 count; S_CLR_ERR(error); if (item == NULL) return NULL; itemInSylStructRel = SItemAs(item, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAs\" failed")) goto quit_error; if (itemInSylStructRel == NULL) { extractedFeat = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; return extractedFeat; } syllableItem = SItemParent(itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemParent\" failed")) goto quit_error; if (syllableItem == NULL) { extractedFeat = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; return extractedFeat; } itr = SItemDaughter(syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemDaughter\" failed")) goto quit_error; count = 0; while (itr != NULL) { s_bool is_equal; is_equal = SItemEqual(itr, itemInSylStructRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemEqual\" failed")) goto quit_error; if (is_equal) break; count++; itr = SItemNext(itr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } extractedFeat = SObjectSetInt(count, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) goto quit_error; /* all OK here */ return extractedFeat; /* error cleanup */ quit_error: if (extractedFeat != NULL) S_DELETE(extractedFeat, "Run", error); return NULL; S_UNUSED(self); }
static SObject *Run(const SFeatProcessor *self, const SItem *item, s_erc *error) { SObject *extractedFeat = NULL; const SVoice *voice; const SPhoneset *phoneset; const char *feature; const char *begin; const char *token; s_bool feature_value; S_CLR_ERR(error); if (item == NULL) return NULL; voice = SItemVoice(item, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemVoice\" failed")) return NULL; if (voice == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Item voice is NULL, voice is required to get phoneset"); return NULL; } phoneset = S_PHONESET(SVoiceGetData(voice, "phoneset", error)); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SVoiceGetData\" failed")) return NULL; if (phoneset == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Phoneset is NULL, phoneset is required to get phone feature"); return NULL; } token = SItemGetString(item, "_phoneset_feature", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemGetString\" failed")) return NULL; /* get part of token (actual feature), after _ */ begin = s_strchr(token, '_', error); if (S_CHK_ERR(error, S_CONTERR, "SItemPath", "Call to \"s_strchr\" failed")) return NULL; if (begin != NULL) { feature = begin + 1; } else { /* no feature */ return NULL; } feature_value = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset, SItemGetName(item, error), feature, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"phone_has_feature/SItemGetName\" failed")) return NULL; if (feature_value == TRUE) { extractedFeat = SObjectSetInt(1, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) return NULL; } else { extractedFeat = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectSetInt\" failed")) return NULL; } return extractedFeat; return NULL; S_UNUSED(self); }