static void SetFeature(const SCostFunction *self, SItem *item, s_erc *error) { SObject *extractedFeature = NULL; S_CLR_ERR(error); if (item == NULL) { S_CTX_ERR(error, S_ARGERROR, "SetFeature", "Argument \"item\" is NULL"); goto quit_error; } extractedFeature = SItemPathToFeatProc(item, "R:SylStructure.parent.parent.word_num_syls", error); if (S_CHK_ERR(error, S_CONTERR, "SetFeature", "Call to \"SItemPathToFeatProc\" failed")) goto quit_error; if (extractedFeature == NULL) { /* segment item might not have a word, e.g inserted silences. */ extractedFeature = SObjectSetInt(0, error); if (S_CHK_ERR(error, S_CONTERR, "SetFeature", "Call to \"SObjectSetInt\" failed")) goto quit_error; } SItemSetObject(item, self->feature_name, extractedFeature, error); if (S_CHK_ERR(error, S_CONTERR, "SetFeature", "Call to \"SItemSetObject\" failed")) goto quit_error; /* all OK here */ return; /* errors be here */ quit_error: if (extractedFeature != NULL) S_DELETE(extractedFeature, "SetFeature", error); }
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 SObject *CopyInt(const SObject *self, s_erc *error) { SObject *newInt; sint32 i; S_CLR_ERR(error); i = ((SInt*)self)->i; newInt = SObjectSetInt(i, error); if (S_CHK_ERR(error, S_FAILURE, "CopyInt", "Call to \"SObjectSetInt\" failed")) { if (newInt != NULL) S_DELETE(newInt, "CopyInt", error); return NULL; } return newInt; }
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 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 *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 *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 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; 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); }
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 *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 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); }
int main() { s_erc error = S_SUCCESS; SList *list = NULL; SIterator *itr; SObject *a = NULL; SObject *b = NULL; SObject *c = NULL; PyObject *speectModule = NULL; /* for SWIG functions to work */ /* Initialize the Python interpreter. Required. */ Py_Initialize(); /* import speect python module */ speectModule = PyImport_ImportModule("speect"); if (speectModule == NULL) { char *py_error = s_get_python_error_str(); if (py_error) { S_CTX_ERR(&error, S_FAILURE, "main", "Call to \"PyImport_ImportModule\" failed. Reported error: %s", py_error); S_FREE(py_error); } else { S_CTX_ERR(&error, S_FAILURE, "main", "Call to \"PyImport_ImportModule\" failed"); } goto quit; } /* * initialize speect python native module */ error = s_python_native_objects_init(); if (error != S_SUCCESS) { printf("Failed to initialize Speect Python native module\n"); goto quit; } /* Create and populate Python list */ list = create_and_populate_py_list(&error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"create_and_populate_py_list\" failed")) goto quit; /* * get iterator to list, should be NULL as there are no objects * in the list */ itr = S_ITERATOR_GET(list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get iterator to list")) goto quit; /* Create some objects and put the into the list */ a = SObjectSetInt(10, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set int object")) goto quit; b = SObjectSetFloat(3.14, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set float object")) goto quit; c = SObjectSetString("python list test", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set string object")) goto quit; SListPush(list, a, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else a = NULL; /* object belongs to list now, we don't want to * delete it directly. */ SListPush(list, b, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else b = NULL; /* object belongs to list now, we don't want to * delete it directly. */ SListPush(list, c, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else c = NULL; /* object belongs to list now, we don't want to * delete it directly. */ /* * get iterator to list, should not be NULL as there are now * objects in the list */ itr = S_ITERATOR_GET(list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get iterator to list")) goto quit; /* iterate through list objects and print them to stdout */ for (/* NOP */; itr != NULL; itr = SIteratorNext(itr)) { char *buf; const SObject *tmp; tmp = SIteratorObject(itr, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get list iterator object")) goto quit; buf = SObjectPrint(tmp, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to print object")) goto quit; printf("list object = %s\n", buf); S_FREE(buf); } quit: if (list != NULL) S_DELETE(list, "main", &error); if (itr != NULL) S_DELETE(itr, "main", &error); if (a != NULL) S_DELETE(a, "main", &error); if (b != NULL) S_DELETE(b, "main", &error); if (c != NULL) S_DELETE(c, "main", &error); Py_XDECREF(speectModule); Py_Finalize(); return 0; }
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 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); }