static s_bool segment_is_pause(const SItem *item, s_erc *error) { const SVoice *voice; const SPhoneset *phoneset; s_bool is_pause; S_CLR_ERR(error); voice = SItemVoice(item, error); if (S_CHK_ERR(error, S_CONTERR, "segment_is_pause", "Call to \"SItemVoice\" failed")) return FALSE; if (voice == NULL) { S_CTX_ERR(error, S_FAILURE, "segment_is_pause", "Item voice is NULL, voice is required to get phoneset"); return FALSE; } phoneset = S_PHONESET(SVoiceGetData(voice, "phoneset", error)); if (S_CHK_ERR(error, S_CONTERR, "segment_is_pause", "Call to \"SVoiceGetData\" failed")) return FALSE; if (phoneset == NULL) { S_CTX_ERR(error, S_FAILURE, "segment_is_pause", "Phoneset is NULL, phoneset is required to get silence phone"); return FALSE; } is_pause = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset, SItemGetName(item, error), "pause", error); if (S_CHK_ERR(error, S_CONTERR, "segment_is_pause", "Call to \"phone_has_feature/SItemGetName\" failed")) return FALSE; return is_pause; }
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 *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 void s_compute_phonetic_features (SItem* word, s_erc *error ) { SItem *syllable; SItem * phone; char* position_in_syllable_string = NULL; /* Extract Phoneset from Voice*/ const SVoice* voice = SItemVoice (word, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemGetVoice\" failed")) return; const SPhoneset* phoneset = (SPhoneset*)SVoiceGetData(voice, "phoneset", error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SVoiceGetData\" failed")) return; SItem *wordAsSylStructure = SItemAs(word, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_stresses", "Call to \"SItemAs\" failed")) return; syllable = SItemDaughter(wordAsSylStructure, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_stresses", "Call to \"SItemDaughter\" failed")) return; while (syllable != NULL) { phone = SItemDaughter(syllable, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemDaughter\" failed")) return; s_bool nucleusFound = FALSE; while (phone != NULL) { const char* phone_value = SItemGetName(phone, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemGetName\" failed")) return; s_bool isVowel = S_PHONESET_CALL(phoneset, phone_has_feature) (phoneset, phone_value, "vowel", error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"phone_has_feature\" failed")) return; if( isVowel ) { nucleusFound = TRUE; position_in_syllable_string = "nucleus"; } else { if( nucleusFound == TRUE ) position_in_syllable_string = "coda"; else position_in_syllable_string = "onset"; } SItemSetString ( phone, "syllablepart", position_in_syllable_string, error ); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemSetString\" failed")) return; s_bool hasLong = S_PHONESET_CALL(phoneset, phone_has_feature) (phoneset, phone_value, "duration_long", error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"phone_has_feature\" failed")) return; s_bool hasShort = S_PHONESET_CALL(phoneset, phone_has_feature) (phoneset, phone_value, "duration_short", error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"phone_has_feature\" failed")) return; const char * feat = NULL; if( hasLong ) { feat = "+"; } else if( hasShort ) { feat = "-"; } if(feat != NULL) { SItemSetString ( phone, "duration", feat, error ); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemSetString\" failed")) return; } phone = SItemNext ( phone, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemNext\" failed")) return; } syllable = SItemNext (syllable, error); if (S_CHK_ERR(error, S_CONTERR, "s_compute_phonetic_features", "Call to \"SItemNext\" failed")) return; } }