Exemple #1
0
/** returns the cost between 2 coordinates generic way to compute */
int Graph::GetTransitionCostGenericWordBased(size_t* coordcurr, size_t* coordprev)
{
	size_t nbrchange = 0;
	vector<Token*> vectToken;
	vector<int> vectCounts;
	bool found, deletable;
	size_t index = 0;
	
	deletable = false;
	
	for(size_t i=0; i<GetDimension(); ++i)
	{
		if(coordcurr[i] != coordprev[i])
		{
			Token* aToken = m_TabVecHypRef[i][coordcurr[i]];
			deletable = aToken->IsOptional();
			
			found = false;
			
			for(size_t j=0; j<vectToken.size(); ++j)
			{
				if(aToken->IsEquivalentTo(vectToken[j]))
				{
					found = true;
					index = j;
				}
			}
			
			if(!found)
			{
				vectToken.push_back(aToken);
				vectCounts.push_back(1);
			}
			else
			{
				++(vectCounts[index]);
			}
			
			++nbrchange;
		}
	}
	
	vectToken.clear();
	
	int nbroccur = 0;
	
	for(size_t j=0; j<vectCounts.size(); ++j)
		if(vectCounts[j] > nbroccur)
			nbroccur = vectCounts[j];
	
	vectCounts.clear();
	
	return( GetCostInsertion(deletable)*( GetDimension() - nbrchange ) + GetCostTransition()*( nbrchange - nbroccur ) );
}
Exemple #2
0
int Graph::GetTransitionCostGenericTimeBased(size_t* coordcurr, size_t* coordprev)
{
	bool deletable = false;
	int mintime = -1;
	int maxtime = -1;
	int deletioncost = 0;
	int transitioncost = 0;
	
	for(size_t i=0; i<GetDimension(); ++i)
	{
		if(coordcurr[i] != coordprev[i])
		{
			Token* aToken = m_TabVecHypRef[i][coordcurr[i]];
			deletable = aToken->IsOptional();
			
			if( (mintime == -1) || (aToken->GetStartTime() < mintime) )
				mintime = aToken->GetStartTime();
			
			if( (maxtime == -1) || (aToken->GetEndTime() > maxtime) )
				maxtime = aToken->GetEndTime();
		}
	}

	for(size_t i=0; i<GetDimension(); ++i)
	{
		if(coordcurr[i] != coordprev[i])
		{
			Token* aToken = m_TabVecHypRef[i][coordcurr[i]];
			transitioncost = maxtime - aToken->GetEndTime() + aToken->GetStartTime() - mintime;
		}
		else
			deletioncost += maxtime - mintime;
	}
	
	return( (GetCostInsertion(deletable)*deletioncost + GetCostTransition()*transitioncost)/m_TimeBasedSafeDivider );
}		
Exemple #3
0
void TestToken::TestText()
{
	SpeechSet* speechSet = new SpeechSet();
	Speech* speech = new Speech(speechSet);
	Segment* segment = Segment::CreateWithDuration(0, 10000, speech);
	Token* token = Token::CreateWithDuration(0, 0, segment);
	token->SetSourceText("hop");
	assert(token->GetText() == "hop");

	//JGF Note: I only added the full test cases for optional frags for the SetProperty("align.optionally", "both") test
	Properties::SetProperty("align.optionally", "both");
		// (hop)
	token->SetSourceText("(hop)");
	assert(token->GetSourceText() == "(hop)");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	assert(token->IsOptional());
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop");
		// hop-
	Properties::SetProperty("align.fragment_are_correct", "false");
	token->SetSourceText("hop-");
	assert(token->GetSourceText() == "hop-");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::BEGIN_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop-");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
		// (hop-)
	Properties::SetProperty("align.fragment_are_correct", "false");
	token->SetSourceText("(hop-)");
	assert(token->GetSourceText() == "(hop-)");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::BEGIN_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop-");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
		// -hop
	Properties::SetProperty("align.fragment_are_correct", "false");
	token->SetSourceText("-hop");
	assert(token->GetSourceText() == "-hop");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::END_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "-hop");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
		// (-hop)
	Properties::SetProperty("align.fragment_are_correct", "false");
	token->SetSourceText("(-hop)");
	assert(token->GetSourceText() == "(-hop)");
	Properties::SetProperty("align.fragment_are_correct", "true");
		cout << "Get " << token->GetText() << endl;
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::END_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "-hop");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);

	Properties::SetProperty("align.optionally", "ref");
	speechSet->SetOrigin("ref");
	token->SetSourceText("(hop)");
	assert(token->GetSourceText() == "(hop)");
	assert(token->GetText() == "hop");
	assert(token->IsOptional());
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop");
	token->SetSourceText("(hop-)");
	assert(token->GetSourceText() == "(hop-)");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::BEGIN_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop-");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);

	Properties::SetProperty("align.optionally", "ref");
	speechSet->SetOrigin("hyp");
	token->SetSourceText("(hop)");
	assert(token->GetSourceText() == "(hop)");
	assert(token->GetText() == "(hop)");
	assert(!token->IsOptional());
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "(hop)");
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "(hop)");
	token->SetSourceText("(hop-)");
	assert(token->GetSourceText() == "(hop-)");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "(hop-)");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "(hop-)");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);

	Properties::SetProperty("align.optionally", "hyp");
	speechSet->SetOrigin("hyp");
	token->SetSourceText("(hop)");
	assert(token->GetSourceText() == "(hop)");
	assert(token->GetText() == "hop");
	assert(token->IsOptional());
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop");
	token->SetSourceText("(hop-)");
	assert(token->GetSourceText() == "(hop-)");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "hop");
	assert(token->GetFragmentStatus() == Token::BEGIN_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "hop-");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);

	Properties::SetProperty("align.optionally", "hyp");
	speechSet->SetOrigin("ref");
	token->SetSourceText("(hop)");
	assert(token->GetSourceText() == "(hop)");
	assert(token->GetText() == "(hop)");
	assert(!token->IsOptional());
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "(hop)");
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "(hop)");
	token->SetSourceText("(hop-)");
	assert(token->GetSourceText() == "(hop-)");
	Properties::SetProperty("align.fragment_are_correct", "true");
	assert(token->GetText() == "(hop-)");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);
	Properties::SetProperty("align.fragment_are_correct", "false");
	assert(token->GetText() == "(hop-)");
	assert(token->GetFragmentStatus() == Token::NOT_FRAGMENT);

	delete token;
	delete segment;
	delete speech;
	delete speechSet;
}