예제 #1
0
파일: test_token.cpp 프로젝트: AIDman/Kaldi
void TestToken::TestPrecNextGraph()
{
	SpeechSet* speechSet = new SpeechSet();
	Speech* speech = new Speech(speechSet);
	Segment* segment = Segment::CreateWithDuration(0, 10000, speech);
	/* initialize tokens with a graph like
	*     B
	*    / \
	* --A   D--
	*    \ /
	*     C
	*/
	Token* tokenA = Token::CreateWithDuration(0, 0, segment);
	tokenA->SetSourceText("A");
	Token* tokenB = Token::CreateWithDuration(0, 0, segment);
	tokenB->SetSourceText("B");
	Token* tokenC = Token::CreateWithDuration(0, 0, segment);
	tokenC->SetSourceText("C");
	Token* tokenD = Token::CreateWithDuration(0, 0, segment);
	tokenD->SetSourceText("D");
	tokenA->AddNextToken(tokenB);
	tokenA->AddNextToken(tokenC);
	tokenB->AddPrecToken(tokenA);
	tokenB->AddNextToken(tokenD);
	tokenC->AddPrecToken(tokenA);
	tokenC->AddNextToken(tokenD);
	tokenD->AddPrecToken(tokenB);
	tokenD->AddPrecToken(tokenC);     

	// a few basics assert
	assert(tokenA->GetNextToken(0)->GetNextToken(0) == tokenA->GetNextToken(1)->GetNextToken(0));
	assert(tokenD->GetPrecToken(0)->GetPrecToken(0) == tokenA->GetPrecToken(1)->GetPrecToken(0));

	//TODO need to be more complex
	delete tokenA;
	delete tokenB;
	delete tokenC;
	delete tokenD;
	delete segment;
	delete speech;
}
예제 #2
0
파일: test_token.cpp 프로젝트: AIDman/Kaldi
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;
}
예제 #3
0
파일: token.cpp 프로젝트: AIDman/Kaldi
Token* Token::CreateWithEndTime(const int& _startTime, const int& _endTime, Segment* parent, const string& _text)
{
  Token* token = Token::CreateWithEndTime(_startTime, _endTime, parent);
  token->SetSourceText(_text);
  return token;
}
예제 #4
0
파일: token.cpp 프로젝트: AIDman/Kaldi
Token* Token::CreateWithDuration(const int& _startTime, const int& _duration, Segment* parent, const string& _text)
{
  Token* token = Token::CreateWithDuration(_startTime, _duration, parent);
  token->SetSourceText(_text);
  return token;
}