示例#1
0
文件: write.c 项目: Cyofanni/speect
static float get_word_end(const SItem *word, s_erc *error)
{
	const SItem *wordSylStructure;
	const SItem *lastSyllable;
	float end = 0.0;


	S_CLR_ERR(error);
	wordSylStructure = SItemAs(word, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_end",
				  "Call to \"SItemAs\" failed"))
		return 0.0;

	if (wordSylStructure == NULL) return end;
	lastSyllable = SItemLastDaughter(wordSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_end",
				  "Call to \"SItemLastDaughter\" failed"))
		return 0.0;

	if (lastSyllable == NULL) return end;
	end = get_syllable_end(lastSyllable, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_end",
				  "Call to \"get_syllable_end\" failed"))
		return 0.0;

	return end;
}
示例#2
0
文件: write.c 项目: Cyofanni/speect
static float get_word_start(const SItem *word, s_erc *error)
{
	const SItem *wordSylStructure;
	const SItem *firstSyllable;
	float start = 0.0;


	S_CLR_ERR(error);
	wordSylStructure = SItemAs(word, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_start",
				  "Call to \"SItemAs\" failed"))
		return 0.0;

	if (wordSylStructure == NULL) return start;
	firstSyllable = SItemDaughter(wordSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_start",
				  "Call to \"SItemDaughter\" failed"))
		return 0.0;

	if (firstSyllable == NULL) return start;
	start = get_syllable_start(firstSyllable, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_word_start",
				  "Call to \"get_syllable_start\" failed"))
		return 0.0;

	return start;
}
示例#3
0
文件: write.c 项目: Cyofanni/speect
static float get_syllable_end(const SItem *syllable, s_erc *error)
{
	const SItem *syllableSylStructure;
	const SItem *lastSegment;
	float end = 0.0;


	S_CLR_ERR(error);
	syllableSylStructure = SItemAs(syllable, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_syllable_end",
				  "Call to \"SItemAs\" failed"))
		return 0.0;

	lastSegment = SItemLastDaughter(syllableSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_syllable_end",
				  "Call to \"SItemLastDaughter\" failed"))
		return 0.0;

	end = get_segment_end(lastSegment, error);
	if (S_CHK_ERR(error, S_CONTERR,
					  "get_syllable_end",
					  "Call to \"get_segment_end\" failed"))
			return 0.0;

	return end;
}
示例#4
0
文件: write.c 项目: Cyofanni/speect
static float get_syllable_start(const SItem *syllable, s_erc *error)
{
	const SItem *syllableSylStructure;
	const SItem *firstSegment;
	float start = 0.0;


	S_CLR_ERR(error);
	syllableSylStructure = SItemAs(syllable, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_syllable_start",
				  "Call to \"SItemAs\" failed"))
		return 0.0;

	firstSegment = SItemDaughter(syllableSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_syllable_start",
				  "Call to \"SItemDaughter\" failed"))
		return 0.0;

	start = get_segment_start(firstSegment, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_syllable_start",
				  "Call to \"get_segment_start\" failed"))
		return 0.0;

	return start;
}
示例#5
0
static const char* setSentenceType(const SItem *phrase, SMap *puncMap, s_erc *error)
{
	S_CLR_ERR(error);

	const char* result = NULL;

	/* types: "decl, "excl", "interrog" */
	/* stop at sentence's last token */
	const SItem *wordFromCurrentPhrase = SItemPathToItem(phrase, "daughtern", 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);
	tokenItem = SItemNext(tokenItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "setSentenceType",
			  "Call to \"SItemNext\" failed"))
		return NULL;

	const char *punctStr = SItemGetName(tokenItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "setSentenceType",
			  "Call to \"SItemGetName\" failed"))
		return NULL;

	s_bool found= SMapObjectPresent(puncMap, punctStr, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "setSentenceType",
			  "Call to \"SMapObjectPresent\" failed"))
		return NULL;

	result = punctStr;


	if( found == TRUE)
	{
		result = SMapGetString ( puncMap, punctStr, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "setSentenceType",
				  "Call to \"SMapGetString\" failed"))
			return NULL;
	}
	else
	{
		result = NULL;
	}

	return result;
}
示例#6
0
static void s_compute_stresses ( const SFeatProcessor* proc, SItem* word, s_erc *error )
{
	S_CLR_ERR(error);
	SItem *wordAsSylStructure = SItemAs(word, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "s_compute_stresses",
		      "Call to \"SItemAs\" failed"))
		return;

	SItem *syllable = SItemDaughter(wordAsSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "s_compute_stresses",
		      "Call to \"SItemDaughter\" failed"))
		return;

	SObject* result = NULL;
	while (syllable != NULL)
	{
		result = SFeatProcessorRun ( proc, syllable, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_compute_stresses",
					  "Call to \"SItemPathToFeatProc\" failed"))
			goto s_compute_stresses_cleanup;

		const char* resultString = SObjectGetString ( result, error );
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_compute_stresses",
					  "Call to \"SObjectGetInt\" failed"))
			goto s_compute_stresses_cleanup;

		SItemSetString ( syllable, "stress", resultString, error );
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_compute_stresses",
					  "Call to \"SItemSetInt\" failed"))
			goto s_compute_stresses_cleanup;

		syllable = SItemNext ( syllable, error );
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_compute_stresses",
					  "Call to \"SItemNext\" failed"))
			goto s_compute_stresses_cleanup;
		if(result != NULL) {
			S_DELETE(result, "s_compute_stresses", error);
		}
	}
s_compute_stresses_cleanup:
	if(result != NULL) {
		S_DELETE(result, "s_compute_stresses", error);
	}

}
示例#7
0
static sint32 word_num_syls(const SItem *item, s_erc *error)
{
	const SItem *itemInSylStructRel;
	const SItem *itrItem;
	sint32 count;


	S_CLR_ERR(error);

	if (item == NULL)
		return 0;

	itemInSylStructRel = SItemAs(item, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		return 0;

	if (itemInSylStructRel == NULL)
		return 0;

	itrItem = SItemDaughter(itemInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemDaughter\" failed"))
		return 0;

	count = 0;
	while (itrItem != NULL)
	{
		count++;
		itrItem = SItemNext(itrItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			return 0;
	}

	/* all OK here */
	return count;
}
示例#8
0
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);
}
示例#9
0
static sint32 syll_pos_word_rev(const SItem *item, s_erc *error)
{
	const SItem *itemInSylStructRel;
	const SItem *wordItem;
	const SItem *itr;
	sint32 count;


	S_CLR_ERR(error);

	if (item == NULL)
		return 0;

	itemInSylStructRel = SItemAs(item, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		return 0;

	if (itemInSylStructRel == NULL)
		return 0;

	wordItem = SItemParent(itemInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemParent\" failed"))
		return 0;

	if (wordItem == NULL)
		return 0;

	itr = SItemLastDaughter(wordItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemLastDaughter\" failed"))
		return 0;

	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"))
			return 0;

		if (is_equal)
			break;

		count++;
		itr = SItemPrev(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemPrev\" failed"))
			return 0;
	}

	/* all OK here */
	return count;
}
示例#10
0
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;
	}

}
示例#11
0
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);
}
示例#12
0
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);
}
示例#13
0
/* 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;
}
示例#14
0
文件: hts_labels.c 项目: Oghma/speect
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);
}
示例#15
0
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);
}
示例#16
0
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);
}
示例#17
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);
}
示例#18
0
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);
}
示例#19
0
static void Run(const SUttProcessor *self, SUtterance *utt,
				s_erc *error)
{
	const SRelation *wordRel;
	SItem *wordItem;
	const SItem *tokenItem;
	s_bool is_present;
	const char *end_punc;
	SRelation *phraseRelation = NULL;
	SItem *phraseItem = NULL;
	const char *post_punc;
	SRelation *sentenceRelation = NULL;
	SItem *sentenceItem = NULL;


	S_CLR_ERR(error);

	/* we require the word relation */
	is_present = SUtteranceRelationIsPresent(utt, "Word", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceRelationIsPresent\" failed"))
		goto quit_error;

	if (!is_present)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Run",
				  "Failed to find 'Word' relation in utterance");
		goto quit_error;
	}

	wordRel = SUtteranceGetRelation(utt, "Word", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceGetRelation\" failed"))
		goto quit_error;

	/* get phrasing symbols */
	s_get_phrasing_symbols(self, &end_punc, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"s_get_phrasing_symbols\" failed"))
		goto quit_error;

	/* create Phrase relation */
	phraseRelation = SUtteranceNewRelation(utt, "Phrase", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceNewRelation\" failed"))
		goto quit_error;

	/* create Sentence relation */
	sentenceRelation = SUtteranceNewRelation(utt, "Sentence", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceNewRelation\" failed"))
		goto quit_error;

	/* start at the first item in the word relation, cast away
	 * const, we want to add daughter items
	 */
	wordItem = (SItem*)SRelationHead(wordRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SRelationHead\" failed"))
		goto quit_error;

	while (wordItem != NULL)
	{
		SItem *lastWordInToken;
		SItem *wordAsToken;


		if (phraseItem == NULL)
		{
			/* if phrase item is NULL, create a new phrase item (NULL
			 * shared content) that is appended to phrase
			 * relation. Will happen in first pass.
			 */
			sentenceItem = SRelationAppend(sentenceRelation, NULL, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SRelationAppend\" failed"))
				goto quit_error;

			/* Added on top a sentence item, for now is one on one with the phrase item
			 * */
			phraseItem = SRelationAppend(phraseRelation, NULL, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SRelationAppend\" failed"))
				goto quit_error;

			/* add an item name, NB, no break */
			SItemSetString(phraseItem, "name", "NB", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemSetString\" failed"))
				goto quit_error;

			SItemAddDaughter(sentenceItem, phraseItem, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemAddDaughter\" failed"))
				goto quit_error;
		}

		/* Create a daughter item for the phrase item. Shared content
		 * is the word item.
		 */
		SItemAddDaughter(phraseItem, wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemAddDaughter\" failed"))
			goto quit_error;

		/* get word as in Token relation */
		wordAsToken = SItemAs(wordItem, "Token", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Failed to get word item's as in Token relation"))
			goto quit_error;

		/*
		 * get word's token which is the parent of wordAsToken.
		 */
		tokenItem = SItemParent(wordAsToken, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Failed to get word item's token item"))
			goto quit_error;

		/* get last word in token */
		lastWordInToken = SItemLastDaughter(tokenItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
			"Run",
		"Failed to get last daughter of token item"))
			goto quit_error;

		/* check if the next token is punctuation */
		is_present = FALSE;
		tokenItem = SItemNext(tokenItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
		if (tokenItem != NULL)
		{
			is_present = SItemFeatureIsPresent(tokenItem, "IsPunctuation", error);
			if (S_CHK_ERR(error, S_CONTERR,
						"Run",
						"Call to \"SItemFeatureIsPresent\" failed"))
				goto quit_error;
			if (is_present)
			{
				sint32 value = SItemGetInt(tokenItem, "IsPunctuation", error);
				if (S_CHK_ERR(error, S_CONTERR,
							"Run",
							"Call to \"SItemGetInt\" failed"))
					goto quit_error;
				is_present = (value > 0);
			}
		}

		if ((is_present) && (wordAsToken == lastWordInToken))
		{
			char *ptr;


			post_punc = SItemGetName(tokenItem, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemGetName\" failed"))
				goto quit_error;

			/* check if it is in the end_punc list */
			ptr = s_strpbrk(post_punc, end_punc, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"s_strpbrk\" failed"))
				goto quit_error;

			if (ptr != NULL)
			{
				/* add a phrase break */
				SItemSetString(phraseItem, "name", "BB", error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SItemSetString\" failed"))
					goto quit_error;

				/* set to NULL so that a new phrase item is created */
				phraseItem = NULL;
			}
		}

		wordItem = SItemNext(wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
	}

	/* here all is OK */
	return;

	/* error clean-up code */
quit_error:
	if (phraseRelation != NULL)
	{
		SUtteranceDelRelation(utt, "Phrase", error);
		S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceDelRelation\" failed");
	}
}
示例#20
0
文件: seg_mid.c 项目: Cyofanni/speect
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);
}
示例#21
0
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);
}
示例#22
0
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);
}
示例#23
0
文件: syl_vowel.c 项目: Oghma/speect
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);
}