|
|
|
|
|
|
|
|
|
|
|
|
|
#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() |
|
{ |
|
|
|
} |
|
|
|
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 << "| "; |
|
} |
|
|
|
|
|
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.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)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
void InputPath::AddActiveChartEntry(size_t ptInd, ActiveChartEntry *chartEntry) |
|
{ |
|
|
|
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; |
|
} |
|
|
|
} |
|
} |
|
|
|
|