2010-10-15 01:52:35 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
#include "MockHypothesis.h"
|
2015-03-26 21:25:54 +03:00
|
|
|
#include "TranslationOption.h"
|
|
|
|
#include "TranslationTask.h"
|
2010-10-15 01:52:35 +04:00
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Moses;
|
|
|
|
using namespace std;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace MosesTest
|
|
|
|
{
|
2010-10-15 01:52:35 +04:00
|
|
|
|
2015-03-26 21:25:54 +03:00
|
|
|
MockHypothesisGuard
|
|
|
|
::MockHypothesisGuard
|
2015-04-30 08:05:11 +03:00
|
|
|
( const string& sourceSentence,
|
2013-05-29 21:16:15 +04:00
|
|
|
const vector<Alignment>& alignments,
|
|
|
|
const vector<string>& targetSegments)
|
2015-04-30 08:05:11 +03:00
|
|
|
: m_initialTransOpt(), m_wp("WordPenalty"),
|
2015-03-26 21:25:54 +03:00
|
|
|
m_uwp("UnknownWordPenalty"), m_dist("Distortion")
|
2010-10-15 01:52:35 +04:00
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(alignments.size(), targetSegments.size());
|
2015-03-26 21:25:54 +03:00
|
|
|
std::vector<Moses::FactorType> factors(1,0);
|
|
|
|
m_sentence.reset(new Sentence(0, sourceSentence, &factors));
|
|
|
|
m_ttask = TranslationTask::create(m_sentence);
|
|
|
|
m_manager.reset(new Manager(m_ttask));
|
2010-10-15 01:52:35 +04:00
|
|
|
|
|
|
|
//Initial empty hypothesis
|
2015-03-26 21:25:54 +03:00
|
|
|
m_manager->ResetSentenceStats(*m_sentence);
|
|
|
|
m_hypothesis = Hypothesis::Create(*m_manager, *m_sentence, m_initialTransOpt);
|
2010-10-15 01:52:35 +04:00
|
|
|
|
|
|
|
//create the chain
|
|
|
|
vector<Alignment>::const_iterator ai = alignments.begin();
|
|
|
|
vector<string>::const_iterator ti = targetSegments.begin();
|
2013-05-29 21:16:15 +04:00
|
|
|
for (; ti != targetSegments.end() && ai != alignments.end(); ++ti,++ai) {
|
2010-10-15 01:52:35 +04:00
|
|
|
Hypothesis* prevHypo = m_hypothesis;
|
|
|
|
WordsRange wordsRange(ai->first,ai->second);
|
2014-08-04 22:28:04 +04:00
|
|
|
m_targetPhrases.push_back(TargetPhrase(NULL));
|
2014-05-31 17:33:31 +04:00
|
|
|
// m_targetPhrases.back().CreateFromString(Input, factors, *ti, "|", NULL);
|
|
|
|
m_targetPhrases.back().CreateFromString(Input, factors, *ti, NULL);
|
2010-10-15 01:52:35 +04:00
|
|
|
m_toptions.push_back(new TranslationOption
|
2013-05-29 21:16:15 +04:00
|
|
|
(wordsRange,m_targetPhrases.back()));
|
2013-09-17 17:06:17 +04:00
|
|
|
m_hypothesis = Hypothesis::Create(*prevHypo,*m_toptions.back());
|
2010-10-15 01:52:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
MockHypothesisGuard::~MockHypothesisGuard()
|
2010-10-15 01:52:35 +04:00
|
|
|
{
|
|
|
|
RemoveAllInColl(m_toptions);
|
|
|
|
while (m_hypothesis) {
|
|
|
|
Hypothesis* prevHypo = const_cast<Hypothesis*>(m_hypothesis->GetPrevHypo());
|
|
|
|
delete m_hypothesis;
|
|
|
|
m_hypothesis = prevHypo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HypothesisFixture::HypothesisFixture()
|
|
|
|
{
|
|
|
|
string source = "je ne sais pas . ";
|
|
|
|
vector<string> target;
|
|
|
|
vector<Alignment> alignments;
|
|
|
|
m_empty.reset(new MockHypothesisGuard(source,alignments,target));
|
|
|
|
target.push_back("i");
|
|
|
|
target.push_back("do not");
|
|
|
|
alignments.push_back(Alignment(0,0));
|
|
|
|
alignments.push_back(Alignment(3,3));
|
|
|
|
m_partial.reset(new MockHypothesisGuard(source,alignments,target));
|
|
|
|
target.push_back("know");
|
|
|
|
target.push_back(".");
|
|
|
|
alignments.push_back(Alignment(1,2));
|
|
|
|
alignments.push_back(Alignment(4,4));
|
|
|
|
m_full.reset(new MockHypothesisGuard(source,alignments,target));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|