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

MockHypothesis.cpp « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12527aee9cc94b63f6a3fb90e5adaf7bdf88bcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***********************************************************************
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 <boost/test/unit_test.hpp>
#include "MockHypothesis.h"
#include "TranslationOption.h"
#include "TranslationTask.h"
#include "Bitmaps.h"

using namespace Moses;
using namespace std;

namespace MosesTest
{

MockHypothesisGuard
::MockHypothesisGuard
( const string& sourceSentence,
  const vector<Alignment>& alignments,
  const vector<string>& targetSegments)
  : m_initialTransOpt(), m_wp("WordPenalty"),
    m_uwp("UnknownWordPenalty"), m_dist("Distortion")
{
  BOOST_CHECK_EQUAL(alignments.size(), targetSegments.size());
  std::vector<Moses::FactorType> factors(1,0);
  AllOptions const& opts = StaticData::Instance().options();
  m_sentence.reset(new Sentence(0, sourceSentence, opts, &factors));
  m_ttask = TranslationTask::create(m_sentence);
  m_manager.reset(new Manager(m_ttask));

  //Initial empty hypothesis
  Bitmaps bitmaps(m_sentence.get()->GetSize(), 
		  m_sentence.get()->m_sourceCompleted);
  m_manager->ResetSentenceStats(*m_sentence);

  const Bitmap &initBitmap = bitmaps.GetInitialBitmap();
  m_hypothesis = new Hypothesis(*m_manager, *m_sentence, m_initialTransOpt, 
				initBitmap);

  //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;
    Range range(ai->first,ai->second);
    const Bitmap &newBitmap = bitmaps.GetBitmap(prevHypo->GetWordsBitmap(), 
						range);

    m_targetPhrases.push_back(TargetPhrase(NULL));
    // m_targetPhrases.back().CreateFromString(Input, factors, *ti, "|", NULL);
    m_targetPhrases.back().CreateFromString(Input, factors, *ti, NULL);
    m_toptions.push_back(new TranslationOption
                         (range,m_targetPhrases.back()));
    m_hypothesis = new Hypothesis(*prevHypo, *m_toptions.back(), newBitmap);

  }


}

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));
}

}