/* * this is for Georg's accent levels: * unaccented : FALSE * accented : TRUE */ static s_bool syl_is_accented(const SItem *syl, s_erc *error) { const char *accent_feat; S_CLR_ERR(error); accent_feat = SItemGetString(syl, "accent", error); if (S_CHK_ERR(error, S_CONTERR, "syl_is_accented", "Call to \"SItemGetString\" failed")) return FALSE; if (s_strcmp(accent_feat, "unaccented", error) == 0) { S_CHK_ERR(error, S_CONTERR, "syl_is_accented", "Call to \"s_strcmp\" failed"); return FALSE; } if (s_strcmp(accent_feat, "accented", error) == 0) { if (S_CHK_ERR(error, S_CONTERR, "syl_is_accented", "Call to \"s_strcmp\" failed")) return FALSE; return TRUE; } return FALSE; /* unknown */ }
/* * Content word's "cat" feature is 'content' */ static s_bool word_is_content(const SItem *word, s_erc *error) { const char *cat_feat; s_bool comp; S_CLR_ERR(error); cat_feat = SItemGetString(word, "cat", error); if (S_CHK_ERR(error, S_CONTERR, "word_is_content", "Call to \"SItemGetString\" failed")) return FALSE; comp = s_strcmp(cat_feat, "content", error); if (S_CHK_ERR(error, S_CONTERR, "syl_is_stressed", "Call to \"s_strcmp\" failed")) return FALSE; if (comp == 0) return TRUE; return FALSE; /* not content word */ }
/* * this is for Georg's stress levels: * unstressed : FALSE * primary : TRUE * secondary : TRUE */ static s_bool syl_is_stressed(const SItem *syl, s_erc *error) { const char *stress_feat; S_CLR_ERR(error); stress_feat = SItemGetString(syl, "stress", error); if (S_CHK_ERR(error, S_CONTERR, "syl_is_stressed", "Call to \"SItemGetString\" failed")) return FALSE; if (s_strcmp(stress_feat, "unstressed", error) == 0) { S_CHK_ERR(error, S_CONTERR, "syl_is_stressed", "Call to \"s_strcmp\" failed"); return FALSE; } if (s_strcmp(stress_feat, "primary", error) == 0) { if (S_CHK_ERR(error, S_CONTERR, "syl_is_stressed", "Call to \"s_strcmp\" failed")) return FALSE; return TRUE; } if (s_strcmp(stress_feat, "secondary", error) == 0) { if (S_CHK_ERR(error, S_CONTERR, "syl_is_stressed", "Call to \"s_strcmp\" failed")) return FALSE; return TRUE; } return FALSE; /* unknown */ }
/* setSentenceType should be made out of two parts: * 1) the first section searchs for the last punctuation element of the sentence * -> if it is a '.' --> set "decl" type (where should I set this feature value?) * -> if it is a '!' --> set "excl" type (where should I set this feature value?) * -> if it is a '?' --> set "interrog" type (where should I set this feature value?) * 2) if the first part decides for "interrog" type, there should be other controls * to establish the sentence's complete type * */ static char* setSentenceType(const SItem *phrase, SMap *prosSymbols, s_erc *error) { S_CLR_ERR(error); char* result = "decl"; /* types: "decl, "excl", "interrog" */ /* stop at sentence's last token */ const SItem *wordFromCurrentPhrase = SItemPathToItem(phrase, "daughter", error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemPathToItem\" failed")) return NULL; SItem *wordAsToken = SItemAs(wordFromCurrentPhrase, "Token", error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemAs\" failed")) return NULL; SItem *tokenItem = SItemParent(wordAsToken, error); SItem *firstTokenItem = tokenItem; s_bool isPunct = SItemFeatureIsPresent(tokenItem, "IsPunctuation", error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemFeatureIsPresent\" failed")) return NULL; s_bool isFinalPunct = FALSE; while (isFinalPunct == FALSE) { isPunct = SItemFeatureIsPresent(tokenItem, "IsPunctuation", error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemFeatureIsPresent\" failed")) return NULL; if (isPunct) { const char *punctStr = SItemGetName(tokenItem, error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemGetName\" failed")) return NULL; if (s_strcmp(punctStr, ".", error) == 0) { isFinalPunct = TRUE; result = "decl"; } else if (s_strcmp(punctStr, "!", error) == 0) { isFinalPunct = TRUE; result = "excl"; } else if (s_strcmp(punctStr, "?", error) == 0) { isFinalPunct = TRUE; const char *posValueStr = NULL; char *posValueStr_filtered = NULL; s_bool currPosInCurrList; s_bool have_symbols = FALSE; SMap* valueMap = NULL; have_symbols = SMapObjectPresent(prosSymbols, "firstPosInQuestionW", error); if (S_CHK_ERR(error, S_CONTERR, "SetSentenceType", "Call to \"SMapObjectPresent\" failed")) goto quit_error; if (have_symbols) { valueMap = S_CAST(SMapGetObject(prosSymbols, "firstPosInQuestionW", error), SMap, error); if (S_CHK_ERR(error, S_CONTERR, "SetSentenceType", "Call to \"SMapGetObject\" failed")) goto quit_error; } else goto quit_error; posValueStr = SItemGetString(firstTokenItem, "POS", error); if (S_CHK_ERR(error, S_CONTERR, "SetSentenceType", "Call to \"SItemGetString\" failed")) goto quit_error; /* filter the current POS tag, remember to free the memory * pointed to by 'posValueStr_filtered' pointer */ posValueStr_filtered = filterPosTag(posValueStr, error); if (S_CHK_ERR(error, S_CONTERR, "SetSentenceType", "Call to \"filterPosTag\" failed")) goto quit_error; currPosInCurrList = searchStringMap(valueMap, posValueStr_filtered, error); if (currPosInCurrList == TRUE) { result = "interrogW"; } else { result = "interrog"; } quit_error: if (posValueStr_filtered) { S_FREE(posValueStr_filtered); } break; } } tokenItem = SItemNext(tokenItem, error); if (S_CHK_ERR(error, S_CONTERR, "setSentenceType", "Call to \"SItemNext\" failed")) return NULL; if(tokenItem == NULL) { isFinalPunct = TRUE; } } return result; }
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 Save(const SObject *object, const char *path, s_erc *error) { int rc; SUtterance *utt = S_UTTERANCE(object); SDatasource *ds; xmlTextWriterPtr writer; xmlOutputBufferPtr out; const char * xsi = "http://www.w3.org/2001/XMLSchema-instance"; S_CLR_ERR(error); ds = SFilesourceOpenFile(path, "wt", error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SFilesourceOpenFile\" failed")) return; out = xmlOutputBufferCreateIO(_ds_write, _ds_close, ds, NULL); if (out == NULL) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlOutputBufferCreateIO\" failed"); return; } writer = xmlNewTextWriter(out); if (writer == NULL) { xmlOutputBufferClose(out); S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlNewTextWriter\" failed"); return; } /* Start Document */ rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, NULL); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterStartDocument\" failed"); goto s_write_utt_exit; } /* Write the maryxml namespace */ rc = xmlTextWriterStartElement(writer, BAD_CAST "xml"); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterStartElement\" failed"); goto s_write_utt_exit; } rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xsi", BAD_CAST xsi); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterWriteAttribute\" failed"); goto s_write_utt_exit; } rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "0.5"); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterWriteAttribute\" failed"); goto s_write_utt_exit; } // print labels /* get to the first syllable of the current word */ const SItem* itrSegments = SRelationHead(SUtteranceGetRelation(utt, "Segment", error), error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemPathToItem\" failed")) goto s_write_utt_exit; while (itrSegments != NULL) { /* get segment content */ const char* label = SItemGetString(itrSegments, "hts_label", error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemGetName\" failed")) goto s_write_utt_exit; /* get next segment */ itrSegments = SItemNext(itrSegments, error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemNext\" failed")) goto s_write_utt_exit; xmlTextWriterWriteElement(writer, BAD_CAST "label", BAD_CAST label); } /* Close the tag xml */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterEndDocument\" failed"); goto s_write_utt_exit; } /* Close the document */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterEndDocument\" failed"); goto s_write_utt_exit; } s_write_utt_exit: xmlFreeTextWriter(writer); }
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 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 const SPhoneset *_get_phoneset(const SItem *item, s_bool *multilingual, s_erc *error) { const SPhoneset *phoneset; const SVoice *voice; s_bool is_present; S_CLR_ERR(error); /* get the voice */ voice = SItemVoice(item, error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SItemVoice\" failed")) return NULL; if (voice == NULL) { S_CTX_ERR(error, S_FAILURE, "_get_phoneset", "Item voice is NULL, voice is required to get phoneset"); return NULL; } /* * do we have a 'voices' feature in the voice, * i.e. is this a multilingual voice */ is_present = SVoiceFeatureIsPresent(voice, "voices", error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SVoiceFeatureIsPresent\" failed")) return NULL; if (is_present) { /* This is a multilingual voice. * Get language feature of item, which is language feature * of item's token. */ const SItem *tokenItem; const char *lang; const SMap *voicesMap; const SVoice *thisVoice; (*multilingual) = TRUE; tokenItem = SItemPathToItem(item, "R:SylStructure.parent.R:Token.parent", error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SItemPathToItem\" failed")) return NULL; if (tokenItem == NULL) { S_CTX_ERR(error, S_FAILURE, "_get_phoneset", "Failed to find item's token, which is required to get language feature"); return NULL; } lang = SItemGetString(tokenItem, "lang", error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SItemGetString\" failed")) return NULL; /* now get the phoneset */ voicesMap = (const SMap*)SVoiceGetFeature(voice, "voices", error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SVoiceGetFeature\" failed")) return NULL; thisVoice = (const SVoice*)SMapGetObjectDef(voicesMap, lang, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SMapGetObjectDef\" failed")) return NULL; if (thisVoice == NULL) { S_CTX_ERR(error, S_FAILURE, "_get_phoneset", "Failed to find the voice for language '%s', which is required to get the phoneset", lang); return NULL; } phoneset = S_PHONESET(SVoiceGetData(thisVoice, "phoneset", error)); if (S_CHK_ERR(error, S_CONTERR, "_get_phoneset", "Call to \"SVoiceGetData\" failed")) return NULL; } else { /* not multilingual voice */ (*multilingual) = FALSE; 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, "_get_phoneset", "Item phoneset is NULL, required to extract phone features"); return NULL; } return phoneset; }