Example #1
0
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;
}
Example #2
0
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;
}
Example #3
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);
	}

}
Example #4
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;
}
Example #5
0
static float get_phrase_start(const SItem *phrase, s_erc *error)
{
	const SItem *firstWord;
	float start = 0.0;


	S_CLR_ERR(error);
	firstWord = SItemDaughter(phrase, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_phrase_start",
				  "Call to \"SItemDaughter\" failed"))
		return 0.0;

	start = get_word_start(firstWord, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_phrase_start",
				  "Call to \"get_word_start\" failed"))
		return 0.0;

	return start;
}
Example #6
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);
}
Example #7
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);
}
Example #8
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);
}
Example #9
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_stressed = 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;
	}

	wordItem = SItemDaughter(phraseItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemDaughter\" 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 = SItemDaughter(sylStructWordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemDaughter\" failed"))
			goto quit_error;

		while (syllableItem != NULL)
		{
			s_bool is_stressed;


			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_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)
				num_stressed++;

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

		if (is_current_syl)
			break;

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

	extractedFeat = SObjectSetInt(num_stressed, 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);
}
Example #10
0
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);
}
Example #11
0
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);
}
Example #12
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;
	}

}