Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2012-11-12 23:56:18 +0400
committerHieu Hoang <hieuhoang@gmail.com>2012-11-12 23:56:18 +0400
commit5e3ef23cef6101d2c098eb3445f562e8f595655b (patch)
treeb8c332b6fa82bae84ea4910967a10ba1b08a7107 /moses/MockHypothesis.cpp
parent8c785cff2b1be3cccd76ea9026f71b649762dfc3 (diff)
move moses/src/* to moses/
Diffstat (limited to 'moses/MockHypothesis.cpp')
-rw-r--r--moses/MockHypothesis.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/moses/MockHypothesis.cpp b/moses/MockHypothesis.cpp
new file mode 100644
index 000000000..e5314c6aa
--- /dev/null
+++ b/moses/MockHypothesis.cpp
@@ -0,0 +1,102 @@
+/***********************************************************************
+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
+***********************************************************************/
+
+
+
+#include "MockHypothesis.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include "TranslationOption.h"
+
+using namespace Moses;
+using namespace std;
+
+namespace MosesTest {
+
+
+MockHypothesisGuard::MockHypothesisGuard(
+ const string& sourceSentence,
+ const vector<Alignment>& alignments,
+ const vector<string>& targetSegments)
+: m_emptyTarget(),
+ m_sentence(),
+ m_system("mock",&m_wp,&m_uwp,&m_dist),
+ m_manager(0,m_sentence,Normal,&m_system)
+{
+ BOOST_CHECK_EQUAL(alignments.size(), targetSegments.size());
+
+ std::vector<Moses::FactorType> factors;
+ factors.push_back(0);
+
+ stringstream in(sourceSentence + "\n");
+ m_sentence.Read(in,factors);
+
+
+ //Initial empty hypothesis
+ m_manager.ResetSentenceStats(m_sentence);
+ m_hypothesis = Hypothesis::Create(m_manager, m_sentence, m_emptyTarget);
+
+ //create the chain
+ vector<Alignment>::const_iterator ai = alignments.begin();
+ vector<string>::const_iterator ti = targetSegments.begin();
+ for (; ti != targetSegments.end() && ai != alignments.end(); ++ti,++ai)
+ {
+ Hypothesis* prevHypo = m_hypothesis;
+ WordsRange wordsRange(ai->first,ai->second);
+ m_targetPhrases.push_back(TargetPhrase());
+ m_targetPhrases.back().CreateFromString(factors,*ti,"|");
+ m_toptions.push_back(new TranslationOption
+ (wordsRange,m_targetPhrases.back(),m_sentence));
+ m_hypothesis = Hypothesis::Create(*prevHypo,*m_toptions.back(),NULL);
+ }
+
+
+}
+
+MockHypothesisGuard::~MockHypothesisGuard()
+{
+ 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));
+}
+
+}
+