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

InputPath.cpp « SCFG « moses2 « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ebbbf327ad2c8d224a51f024d62bf94a3608f64 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * InputPath.cpp
 *
 *  Created on: 23 Oct 2015
 *      Author: hieu
 */
#include <boost/foreach.hpp>
#include "InputPath.h"
#include "TargetPhrases.h"
#include "ActiveChart.h"
#include "../TranslationModel/PhraseTable.h"
#include "../MemPoolAllocator.h"

using namespace std;

namespace Moses2
{
namespace SCFG
{

InputPath::InputPath(MemPool &pool, const SubPhrase<SCFG::Word> &subPhrase,
    const Range &range, size_t numPt, const InputPath *prefixPath)
:InputPathBase(pool, range, numPt, prefixPath)
,subPhrase(subPhrase)
,targetPhrases(MemPoolAllocator<Element>(pool))
{
  m_activeChart = pool.Allocate<ActiveChart>(numPt);
  for (size_t i = 0; i < numPt; ++i) {
    ActiveChart &memAddr = m_activeChart[i];
    new (&memAddr) ActiveChart(pool);
  }
}

InputPath::~InputPath()
{
  // TODO Auto-generated destructor stub
}

std::string InputPath::Debug(const System &system) const
{
  stringstream out;
  out << range << " ";
  out << subPhrase.Debug(system);
  out << " " << prefixPath << " ";

  const Vector<ActiveChartEntry*> &activeEntries = GetActiveChart(1).entries;
  out << "m_activeChart=" << activeEntries.size() << " ";

  for (size_t i = 0; i < activeEntries.size(); ++i) {
    const ActiveChartEntry &entry = *activeEntries[i];
    out << entry.GetSymbolBind().Debug(system);
    out << "| ";
  }

  // tps
  out << "tps=" << targetPhrases.size();

  out << " ";
  BOOST_FOREACH(const SCFG::InputPath::Coll::value_type &valPair, targetPhrases) {
    const SymbolBind &symbolBind = valPair.first;
    const SCFG::TargetPhrases &tps = *valPair.second;
    out << symbolBind.Debug(system);
    //out << "=" << tps.GetSize() << " ";
    out << tps.Debug(system);
  }

  return out.str();
}

void InputPath::AddTargetPhrasesToPath(
    MemPool &pool,
	const System &system,
    const PhraseTable &pt,
    const SCFG::TargetPhrases &tps,
    const SCFG::SymbolBind &symbolBind)
{
  targetPhrases.push_back(Element(symbolBind, &tps));
	/*
  Coll::iterator iterColl;
  iterColl = targetPhrases.find(symbolBind);
  assert(iterColl == targetPhrases.end());

  targetPhrases[symbolBind] = &tps;
  //cerr << "range=" << range << " symbolBind=" << symbolBind.Debug(system) << " tps=" << tps.Debug(system);
  */
  /*
  SCFG::TargetPhrases *tpsNew;
  tpsNew = new (pool.Allocate<SCFG::TargetPhrases>()) SCFG::TargetPhrases(pool);
  targetPhrases[symbolBind] = tpsNew;

  SCFG::TargetPhrases::const_iterator iter;
  for (iter = tps.begin(); iter != tps.end(); ++iter) {
    const SCFG::TargetPhraseImpl *tp = *iter;
    //cerr << "tpCast=" << *tp << endl;
    tpsNew->AddTargetPhrase(*tp);
  }
  cerr << "range=" << range << " symbolBind=" << symbolBind.Debug(system) << " tpsNew=" << tpsNew->Debug(system);
  */
}

void InputPath::AddActiveChartEntry(size_t ptInd, ActiveChartEntry *chartEntry)
{
  //cerr << "      added " << chartEntry << " " << range << " " << ptInd << endl;
  ActiveChart &activeChart = m_activeChart[ptInd];
  activeChart.entries.push_back(chartEntry);
}

size_t InputPath::GetNumRules() const
{
  size_t ret = 0;
  BOOST_FOREACH(const Coll::value_type &valPair, targetPhrases) {
    const SCFG::TargetPhrases &tps = *valPair.second;
    ret += tps.GetSize();
  }
  return ret;
}

}
}