This commit is contained in:
Hieu Hoang 2016-06-20 14:59:31 +01:00
parent 19b8bc50b7
commit fb2bbf99fc
51 changed files with 169 additions and 131 deletions

View File

@ -18,6 +18,7 @@
***********************************************************************/ ***********************************************************************/
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <sstream>
#include "AlignmentInfo.h" #include "AlignmentInfo.h"
#include "legacy/Util2.h" #include "legacy/Util2.h"
#include "util/exception.hh" #include "util/exception.hh"
@ -156,13 +157,15 @@ std::vector<size_t> AlignmentInfo::GetSourceIndex2PosMap() const
return ret; return ret;
} }
std::ostream &AlignmentInfo::Debug(std::ostream &out, const System &system) const std::string AlignmentInfo::Debug(const System &system) const
{ {
std::stringstream out;
AlignmentInfo::const_iterator iter; AlignmentInfo::const_iterator iter;
for (iter = begin(); iter != end(); ++iter) { for (iter = begin(); iter != end(); ++iter) {
out << iter->first << "-" << iter->second << " "; out << iter->first << "-" << iter->second << " ";
} }
return out; return out.str();
} }
} }

View File

@ -94,7 +94,7 @@ public:
m_nonTermIndexMap == rhs.m_nonTermIndexMap; m_nonTermIndexMap == rhs.m_nonTermIndexMap;
} }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
private: private:
//! AlignmentInfo objects should only be created by an AlignmentInfoCollection //! AlignmentInfo objects should only be created by an AlignmentInfoCollection

View File

@ -46,7 +46,7 @@ public:
virtual SCORE GetFutureScore() const = 0; virtual SCORE GetFutureScore() const = 0;
virtual void EvaluateWhenApplied() = 0; virtual void EvaluateWhenApplied() = 0;
virtual std::ostream &Debug(std::ostream &out, const System &system) const = 0; virtual std::string Debug(const System &system) const = 0;
protected: protected:
ManagerBase *m_mgr; ManagerBase *m_mgr;

View File

@ -5,12 +5,15 @@
* Author: hieu * Author: hieu
*/ */
#include <iostream> #include <iostream>
#include <sstream>
#include <algorithm> #include <algorithm>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include "HypothesisColl.h" #include "HypothesisColl.h"
#include "ManagerBase.h" #include "ManagerBase.h"
#include "System.h" #include "System.h"
using namespace std;
namespace Moses2 namespace Moses2
{ {
@ -124,14 +127,15 @@ void HypothesisColl::Clear()
m_coll.clear(); m_coll.clear();
} }
std::ostream &HypothesisColl::Debug(std::ostream &out, const System &system) const std::string HypothesisColl::Debug(const System &system) const
{ {
stringstream out;
BOOST_FOREACH (const HypothesisBase *hypo, m_coll) { BOOST_FOREACH (const HypothesisBase *hypo, m_coll) {
hypo->Debug(out, system); out << hypo->Debug(system);
out << std::endl << std::endl; out << std::endl << std::endl;
} }
return out; return out.str();
} }
} /* namespace Moses2 */ } /* namespace Moses2 */

View File

@ -63,7 +63,7 @@ public:
const ManagerBase &mgr, const ManagerBase &mgr,
ArcLists &arcLists) const; ArcLists &arcLists) const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
_HCType m_coll; _HCType m_coll;

View File

@ -9,6 +9,7 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <sstream>
#include <iostream> #include <iostream>
#include "Word.h" #include "Word.h"
#include "MemPool.h" #include "MemPool.h"
@ -94,19 +95,19 @@ public:
virtual SubPhrase<WORD> GetSubPhrase(size_t start, size_t size) const = 0; virtual SubPhrase<WORD> GetSubPhrase(size_t start, size_t size) const = 0;
virtual std::ostream &Debug(std::ostream &out, const System &system) const virtual std::string Debug(const System &system) const
{ {
std::stringstream out;
size_t size = GetSize(); size_t size = GetSize();
if (size) { if (size) {
(*this)[0].Debug(out, system); out << (*this)[0].Debug(system);
for (size_t i = 1; i < size; ++i) { for (size_t i = 1; i < size; ++i) {
const WORD &word = (*this)[i]; const WORD &word = (*this)[i];
out << " "; out << " " << word.Debug(system);
word.Debug(out, system);
} }
} }
return out; return out.str();
} }
virtual void OutputToStream(std::ostream &out) const virtual void OutputToStream(std::ostream &out) const

View File

@ -39,8 +39,9 @@ void Stacks::Init(const Manager &mgr, size_t numStacks)
} }
} }
std::ostream &Stacks::Debug(std::ostream &out, const System &system) const std::string Stacks::Debug(const System &system) const
{ {
stringstream out;
for (size_t i = 0; i < GetSize(); ++i) { for (size_t i = 0; i < GetSize(); ++i) {
const Stack *stack = m_stacks[i]; const Stack *stack = m_stacks[i];
if (stack) { if (stack) {
@ -50,7 +51,7 @@ std::ostream &Stacks::Debug(std::ostream &out, const System &system) const
out << "N "; out << "N ";
} }
} }
return out; return out.str();
} }
void Stacks::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle, void Stacks::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,

View File

@ -51,7 +51,7 @@ public:
void Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle, void Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
ArcLists &arcLists); ArcLists &arcLists);
std::ostream & Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
const Manager &m_mgr; const Manager &m_mgr;

View File

@ -91,10 +91,11 @@ CubeEdge::CubeEdge(Manager &mgr, const Hypotheses &hypos, const InputPath &path,
estimatedScore = mgr.GetEstimatedScores().CalcEstimatedScore(newBitmap); estimatedScore = mgr.GetEstimatedScores().CalcEstimatedScore(newBitmap);
} }
std::ostream &CubeEdge::Debug(std::ostream &out, const System &system) const std::string CubeEdge::Debug(const System &system) const
{ {
stringstream out;
out << newBitmap; out << newBitmap;
return out; return out.str();
} }
bool CubeEdge::SetSeenPosition(const size_t x, const size_t y, bool CubeEdge::SetSeenPosition(const size_t x, const size_t y,

View File

@ -88,7 +88,7 @@ public:
SeenPositions &seenPositions, SeenPositions &seenPositions,
std::deque<QueueItem*, MemPoolAllocator<QueueItem*> > &queueItemRecycler); std::deque<QueueItem*, MemPoolAllocator<QueueItem*> > &queueItemRecycler);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:

View File

@ -107,8 +107,10 @@ bool Hypothesis::operator==(const Hypothesis &other) const
return ret; return ret;
} }
std::ostream &Hypothesis::Debug(std::ostream &out, const System &system) const std::string Hypothesis::Debug(const System &system) const
{ {
stringstream out;
// coverage // coverage
out << GetBitmap() << " " << GetInputPath().range << " "; out << GetBitmap() << " " << GetInputPath().range << " ";
@ -122,12 +124,12 @@ std::ostream &Hypothesis::Debug(std::ostream &out, const System &system) const
} }
// string // string
Debug(out, m_mgr->system); //Debug(out, m_mgr->system);
out << " "; out << " ";
out << "fc=" << GetFutureScore() << " "; out << "fc=" << GetFutureScore() << " ";
GetScores().Debug(out, GetManager().system); out << GetScores().Debug(GetManager().system);
return out; return out.str();
} }
void Hypothesis::OutputToStream(std::ostream &out) const void Hypothesis::OutputToStream(std::ostream &out) const
@ -156,7 +158,7 @@ void Hypothesis::OutputToStream(std::ostream &out) const
out << m_path->range.GetStartPos() << "-" << m_path->range.GetEndPos() << ","; out << m_path->range.GetStartPos() << "-" << m_path->range.GetEndPos() << ",";
// score breakdown // score breakdown
m_scores->Debug(out, m_mgr->system); out << m_scores->Debug(m_mgr->system);
out << "| "; out << "| ";
} }

View File

@ -67,7 +67,7 @@ public:
return *m_targetPhrase; return *m_targetPhrase;
} }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
virtual void OutputToStream(std::ostream &out) const; virtual void OutputToStream(std::ostream &out) const;

View File

@ -4,11 +4,14 @@
* Created on: 23 Oct 2015 * Created on: 23 Oct 2015
* Author: hieu * Author: hieu
*/ */
#include <sstream>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include "InputPath.h" #include "InputPath.h"
#include "TargetPhrases.h" #include "TargetPhrases.h"
#include "../TranslationModel/PhraseTable.h" #include "../TranslationModel/PhraseTable.h"
using namespace std;
namespace Moses2 namespace Moses2
{ {
InputPath::InputPath(MemPool &pool, const SubPhrase<Moses2::Word> &subPhrase, InputPath::InputPath(MemPool &pool, const SubPhrase<Moses2::Word> &subPhrase,
@ -42,11 +45,13 @@ const TargetPhrases *InputPath::GetTargetPhrases(const PhraseTable &pt) const
return targetPhrases[ptInd]; return targetPhrases[ptInd];
} }
std::ostream &InputPath::Debug(std::ostream &out, const System &system) const std::string InputPath::Debug(const System &system) const
{ {
stringstream out;
out << range << " "; out << range << " ";
subPhrase.Debug(out, system); out << subPhrase.Debug(system);
return out; return out.str();
} }
} }

View File

@ -33,7 +33,7 @@ public:
return m_isUsed; return m_isUsed;
} }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
bool m_isUsed; bool m_isUsed;

View File

@ -232,7 +232,7 @@ std::string Manager::OutputNBest()
if (ok) { if (ok) {
out << transId << " |||"; out << transId << " |||";
path->Debug(out, system); out << path->Debug(system);
out << "\n"; out << "\n";
} }

View File

@ -39,8 +39,9 @@ void Stacks::Init(const Manager &mgr, size_t numStacks)
} }
} }
std::ostream &Stacks::Debug(std::ostream &out, const System &system) const std::string Stacks::Debug(const System &system) const
{ {
stringstream out;
for (size_t i = 0; i < GetSize(); ++i) { for (size_t i = 0; i < GetSize(); ++i) {
const Stack *stack = m_stacks[i]; const Stack *stack = m_stacks[i];
if (stack) { if (stack) {
@ -50,7 +51,7 @@ std::ostream &Stacks::Debug(std::ostream &out, const System &system) const
out << "N "; out << "N ";
} }
} }
return out; return out.str();
} }
void Stacks::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle, void Stacks::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,

View File

@ -51,7 +51,7 @@ public:
void Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle, void Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
ArcLists &arcLists); ArcLists &arcLists);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
const Manager &m_mgr; const Manager &m_mgr;

View File

@ -15,10 +15,11 @@ using namespace std;
namespace Moses2 namespace Moses2
{ {
std::ostream &Sentence::XMLOption::Debug(std::ostream &out, const System &system) const std::string Sentence::XMLOption::Debug(const System &system) const
{ {
stringstream out;
out << "[" << startPos << "," << phraseSize << "]=" << nodeName; out << "[" << startPos << "," << phraseSize << "]=" << nodeName;
return out; return out.str();
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -30,7 +30,7 @@ public:
std::string nodeName; std::string nodeName;
size_t startPos, phraseSize; size_t startPos, phraseSize;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
}; };

View File

@ -5,6 +5,7 @@
* Author: hieu * Author: hieu
*/ */
#include <sstream>
#include <stdlib.h> #include <stdlib.h>
#include "TargetPhraseImpl.h" #include "TargetPhraseImpl.h"
#include "../Scores.h" #include "../Scores.h"
@ -48,12 +49,12 @@ TargetPhraseImpl::~TargetPhraseImpl()
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
std::ostream &TargetPhraseImpl::Debug(std::ostream &out, const System &system) const std::string TargetPhraseImpl::Debug(const System &system) const
{ {
Phrase<Moses2::Word>::Debug(out, system); stringstream out;
out << " SCORES:"; out << Phrase<Moses2::Word>::Debug(system);
GetScores().Debug(out, system); out << " SCORES:" << GetScores().Debug(system);
return out; return out.str();
} }
} }

View File

@ -35,7 +35,7 @@ public:
virtual ~TargetPhraseImpl(); virtual ~TargetPhraseImpl();
virtual std::ostream &Debug(std::ostream &out, const System &system) const; virtual std::string Debug(const System &system) const;
protected: protected:
}; };

View File

@ -38,13 +38,14 @@ TargetPhrases::~TargetPhrases()
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
std::ostream &TargetPhrases::Debug(std::ostream &out, const System &system) const std::string TargetPhrases::Debug(const System &system) const
{ {
stringstream out;
BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, *this){ BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, *this){
tp->Debug(out, system); out << tp->Debug(system);
out << endl; out << endl;
} }
return out; return out.str();
} }
void TargetPhrases::SortAndPrune(size_t tableLimit) void TargetPhrases::SortAndPrune(size_t tableLimit)

View File

@ -55,7 +55,7 @@ public:
void SortAndPrune(size_t tableLimit); void SortAndPrune(size_t tableLimit);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
Coll m_coll; Coll m_coll;

View File

@ -16,10 +16,11 @@ using namespace std;
namespace Moses2 namespace Moses2
{ {
std::ostream &TrellisNode::Debug(std::ostream &out, const System &system) const std::string TrellisNode::Debug(const System &system) const
{ {
stringstream out;
out << "arcList=" << arcList->size() << " " << ind; out << "arcList=" << arcList->size() << " " << ind;
return out; return out.str();
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -75,17 +76,18 @@ SCORE TrellisPath::GetFutureScore() const
return m_scores->GetTotalScore(); return m_scores->GetTotalScore();
} }
std::ostream &TrellisPath::Debug(std::ostream &out, const System &system) const std::string TrellisPath::Debug(const System &system) const
{ {
stringstream out;
out << ToString(); out << ToString();
out << "||| "; out << "||| ";
GetScores().Debug(out, system); out << GetScores().Debug(system);
out << "||| "; out << "||| ";
out << GetScores().GetTotalScore(); out << GetScores().GetTotalScore();
return out; return out.str();
} }
std::string TrellisPath::ToString() const std::string TrellisPath::ToString() const

View File

@ -34,7 +34,7 @@ public:
return (*arcList)[ind]; return (*arcList)[ind];
} }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
}; };
@ -64,7 +64,7 @@ public:
} }
SCORE GetFutureScore() const; SCORE GetFutureScore() const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
std::string ToString() const; std::string ToString() const;
//! create a set of next best paths by wiggling 1 of the node at a time. //! create a set of next best paths by wiggling 1 of the node at a time.

View File

@ -57,14 +57,15 @@ std::vector<const SymbolBindElement*> SymbolBind::GetNTElements() const
return ret; return ret;
} }
std::ostream &SymbolBind::Debug(std::ostream &out, const System &system) const std::string SymbolBind::Debug(const System &system) const
{ {
stringstream out;
BOOST_FOREACH(const SymbolBindElement &ele, coll) { BOOST_FOREACH(const SymbolBindElement &ele, coll) {
out << "("<< *ele.range; out << "("<< *ele.range;
ele.word->Debug(out, system); out << ele.word->Debug(system);
out << ") "; out << ") ";
} }
return out; return out.str();
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@ -63,7 +63,7 @@ public:
bool operator==(const SymbolBind &compare) const bool operator==(const SymbolBind &compare) const
{ return coll == compare.coll; } { return coll == compare.coll; }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
}; };

View File

@ -29,15 +29,16 @@ SeenPosition::SeenPosition(MemPool &pool, const SCFG::TargetPhrases *vtps, size_
} }
} }
std::ostream &SeenPosition::Debug(std::ostream &out, const System &system) const std::string SeenPosition::Debug(const System &system) const
{ {
stringstream out;
out << tps << " " << tpInd << " "; out << tps << " " << tpInd << " ";
for (size_t i = 0; i < hypoIndColl.size(); ++i) { for (size_t i = 0; i < hypoIndColl.size(); ++i) {
out << hypoIndColl[i] << " "; out << hypoIndColl[i] << " ";
} }
return out; return out.str();
} }
bool SeenPosition::operator==(const SeenPosition &compare) const bool SeenPosition::operator==(const SeenPosition &compare) const
@ -178,14 +179,15 @@ void QueueItem::CreateNext(
} }
} }
std::ostream &QueueItem::Debug(std::ostream &out, const System &system) const std::string QueueItem::Debug(const System &system) const
{ {
stringstream out;
out << hypo << " " << &(*tps)[tpInd] << "(" << tps << " " << tpInd << ") "; out << hypo << " " << &(*tps)[tpInd] << "(" << tps << " " << tpInd << ") ";
for (size_t i = 0; i < hypoIndColl.size(); ++i) { for (size_t i = 0; i < hypoIndColl.size(); ++i) {
out << hypoIndColl[i] << " "; out << hypoIndColl[i] << " ";
} }
return out; return out.str();
} }
} }

View File

@ -34,7 +34,7 @@ public:
bool operator==(const SeenPosition &compare) const; bool operator==(const SeenPosition &compare) const;
size_t hash() const; size_t hash() const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
}; };
@ -86,7 +86,7 @@ public:
SeenPositions &seenPositions, SeenPositions &seenPositions,
const SCFG::InputPath &path); const SCFG::InputPath &path);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
typedef Vector<const Moses2::HypothesisColl *> HyposColl; typedef Vector<const Moses2::HypothesisColl *> HyposColl;

View File

@ -131,16 +131,16 @@ void Hypothesis::OutputToStream(std::ostream &out) const
} }
} }
std::ostream &Hypothesis::Debug(std::ostream &out, const System &system) const std::string Hypothesis::Debug(const System &system) const
{ {
stringstream out;
out << this; out << this;
out << " RANGE:"; out << " RANGE:";
out << m_path->range; out << m_path->range;
// score // score
out << " SCORE:"; out << " SCORE:" << GetScores().Debug(GetManager().system);
GetScores().Debug(out, GetManager().system);
/* /*
out << " m_prevHypos=" << m_prevHypos.size() << " "; out << " m_prevHypos=" << m_prevHypos.size() << " ";
@ -149,16 +149,16 @@ std::ostream &Hypothesis::Debug(std::ostream &out, const System &system) const
} }
*/ */
m_targetPhrase->Debug(out, GetManager().system); out << m_targetPhrase->Debug(GetManager().system);
// recursive // recursive
for (size_t i = 0; i < m_prevHypos.size(); ++i) { for (size_t i = 0; i < m_prevHypos.size(); ++i) {
const Hypothesis &prevHypo = *m_prevHypos[i]; const Hypothesis &prevHypo = *m_prevHypos[i];
out << endl; out << endl;
prevHypo.Debug(out, system); out << prevHypo.Debug(system);
} }
return out; return out.str();
} }
} // namespaces } // namespaces

View File

@ -44,7 +44,7 @@ public:
void OutputToStream(std::ostream &out) const; void OutputToStream(std::ostream &out) const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
const SCFG::TargetPhraseImpl *m_targetPhrase; const SCFG::TargetPhraseImpl *m_targetPhrase;

View File

@ -37,10 +37,11 @@ InputPath::~InputPath()
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
std::ostream &InputPath::Debug(std::ostream &out, const System &system) const std::string InputPath::Debug(const System &system) const
{ {
stringstream out;
out << range << " "; out << range << " ";
subPhrase.Debug(out, system); out << subPhrase.Debug(system);
out << " " << prefixPath << " "; out << " " << prefixPath << " ";
const Vector<ActiveChartEntry*> &activeEntries = *GetActiveChart(1).entries; const Vector<ActiveChartEntry*> &activeEntries = *GetActiveChart(1).entries;
@ -48,7 +49,7 @@ std::ostream &InputPath::Debug(std::ostream &out, const System &system) const
for (size_t i = 0; i < activeEntries.size(); ++i) { for (size_t i = 0; i < activeEntries.size(); ++i) {
const ActiveChartEntry &entry = *activeEntries[i]; const ActiveChartEntry &entry = *activeEntries[i];
entry.GetSymbolBind().Debug(out, system); out << entry.GetSymbolBind().Debug(system);
out << "| "; out << "| ";
} }
@ -59,12 +60,12 @@ std::ostream &InputPath::Debug(std::ostream &out, const System &system) const
BOOST_FOREACH(const SCFG::InputPath::Coll::value_type &valPair, *targetPhrases) { BOOST_FOREACH(const SCFG::InputPath::Coll::value_type &valPair, *targetPhrases) {
const SymbolBind &symbolBind = valPair.first; const SymbolBind &symbolBind = valPair.first;
const SCFG::TargetPhrases &tps = *valPair.second; const SCFG::TargetPhrases &tps = *valPair.second;
symbolBind.Debug(out, system); out << symbolBind.Debug(system);
//out << "=" << tps.GetSize() << " "; //out << "=" << tps.GetSize() << " ";
tps.Debug(out, system); out << tps.Debug(system);
} }
return out; return out.str();
} }
void InputPath::AddTargetPhrase( void InputPath::AddTargetPhrase(

View File

@ -52,7 +52,7 @@ public:
size_t GetNumRules() const; size_t GetNumRules() const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
ActiveChart *m_activeChart; ActiveChart *m_activeChart;

View File

@ -67,19 +67,20 @@ void InputPaths::Init(const InputType &input, const ManagerBase &mgr)
} }
std::ostream &InputPaths::Debug(std::ostream &out, const System &system) const std::string InputPaths::Debug(const System &system) const
{ {
stringstream out;
const Matrix<InputPath*> &matrix = GetMatrix(); const Matrix<InputPath*> &matrix = GetMatrix();
for (size_t i = 0; i < matrix.GetRows(); ++i) { for (size_t i = 0; i < matrix.GetRows(); ++i) {
for (size_t j = 0; j < matrix.GetCols(); ++j) { for (size_t j = 0; j < matrix.GetCols(); ++j) {
SCFG::InputPath *path = matrix.GetValue(i, j); SCFG::InputPath *path = matrix.GetValue(i, j);
if (path) { if (path) {
path->Debug(out, system); out << path->Debug(system);
out << endl; out << endl;
} }
} }
} }
return out; return out.str();
} }
} }

View File

@ -31,7 +31,7 @@ public:
return *m_matrix; return *m_matrix;
} }
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
Matrix<InputPath*> *m_matrix; Matrix<InputPath*> *m_matrix;

View File

@ -62,9 +62,9 @@ void Manager::Decode()
cerr << endl << "startPos=" << startPos << endl; cerr << endl << "startPos=" << startPos << endl;
SCFG::InputPath &initPath = *m_inputPaths.GetMatrix().GetValue(startPos, 0); SCFG::InputPath &initPath = *m_inputPaths.GetMatrix().GetValue(startPos, 0);
//cerr << "BEFORE path=" << m_inputPaths << endl; cerr << "BEFORE InitActiveChart=" << initPath.Debug(system) << endl;
InitActiveChart(initPath); InitActiveChart(initPath);
cerr << "AFTER path=" << endl; cerr << "AFTER InitActiveChart=" << initPath.Debug(system) << endl;
int maxPhraseSize = inputSize - startPos + 1; int maxPhraseSize = inputSize - startPos + 1;
for (int phraseSize = 1; phraseSize < maxPhraseSize; ++phraseSize) { for (int phraseSize = 1; phraseSize < maxPhraseSize; ++phraseSize) {
@ -73,14 +73,14 @@ void Manager::Decode()
Stack &stack = m_stacks.GetStack(startPos, phraseSize); Stack &stack = m_stacks.GetStack(startPos, phraseSize);
cerr << "BEFORE LOOKUP path=" << endl; cerr << "BEFORE LOOKUP path=" << path.Debug(system) << endl;
Lookup(path); Lookup(path);
cerr << "AFTER LOOKUP path=" << endl; cerr << "AFTER LOOKUP path=" << path.Debug(system) << endl;
Decode(path, stack); Decode(path, stack);
cerr << "AFTER DECODE path=" << endl; cerr << "AFTER DECODE path=" << path.Debug(system) << endl;
LookupUnary(path); LookupUnary(path);
//cerr << "AFTER LookupUnary path=" << path << endl; cerr << "AFTER LookupUnary path=" << path.Debug(system) << endl;
//cerr << "#rules=" << path.GetNumRules() << endl; //cerr << "#rules=" << path.GetNumRules() << endl;
} }
@ -317,7 +317,7 @@ std::string Manager::OutputBest() const
bestHypo->OutputToStream(out); bestHypo->OutputToStream(out);
cerr << "BEST TRANSLATION: "; cerr << "BEST TRANSLATION: ";
bestHypo->Debug(cerr, system); cerr << bestHypo->Debug(system);
cerr << " " << out.str() << endl; cerr << " " << out.str() << endl;
} }
else { else {

View File

@ -104,19 +104,19 @@ const Hypothesis *Stack::GetBestHypo(
return ret; return ret;
} }
std::ostream &Stack::Debug(std::ostream &out, const System &system) const std::string Stack::Debug(const System &system) const
{ {
stringstream out;
BOOST_FOREACH (const SCFG::Stack::Coll::value_type &valPair, m_coll) { BOOST_FOREACH (const SCFG::Stack::Coll::value_type &valPair, m_coll) {
const SCFG::Word &lhs = valPair.first; const SCFG::Word &lhs = valPair.first;
const Moses2::HypothesisColl &hypos = *valPair.second; const Moses2::HypothesisColl &hypos = *valPair.second;
out << "lhs="; out << "lhs=" << lhs.Debug(system);
lhs.Debug(out, system);
out << "=" << hypos.GetSize() << endl; out << "=" << hypos.GetSize() << endl;
hypos.Debug(out, system); out << hypos.Debug(system);
out << endl; out << endl;
} }
return out; return out.str();
} }
} }

View File

@ -39,7 +39,7 @@ public:
const Manager &mgr, const Manager &mgr,
ArcLists &arcLists) const; ArcLists &arcLists) const;
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
const Manager &m_mgr; const Manager &m_mgr;

View File

@ -63,24 +63,23 @@ TargetPhraseImpl::~TargetPhraseImpl()
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
std::ostream &TargetPhraseImpl::Debug(std::ostream &out, const System &system) const std::string TargetPhraseImpl::Debug(const System &system) const
{ {
lhs.Debug(out, system); stringstream out;
out << lhs.Debug(system);
out << " -> "; out << " -> ";
for (size_t i = 0; i < GetSize(); ++i) { for (size_t i = 0; i < GetSize(); ++i) {
const SCFG::Word &word = (*this)[i]; const SCFG::Word &word = (*this)[i];
word.Debug(out, system); out << word.Debug(system) << " ";
out << " ";
} }
out << "pt=" << pt.GetName(); out << "pt=" << pt.GetName();
out << " SCORES:"; out << " SCORES:" << GetScores().Debug(system);
GetScores().Debug(out, system);
out << " ALIGN:"; out << " ALIGN:";
GetAlignTerm().Debug(out, system); out << GetAlignTerm().Debug(system);
out << " "; out << " ";
GetAlignNonTerm().Debug(out, system); out << GetAlignNonTerm().Debug(system);
return out; return out.str();
} }
void TargetPhraseImpl::SetAlignmentInfo(const std::string &alignString) void TargetPhraseImpl::SetAlignmentInfo(const std::string &alignString)

View File

@ -67,7 +67,7 @@ public:
void SetAlignmentInfo(const std::string &alignString); void SetAlignmentInfo(const std::string &alignString);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
//mutable void *chartState; //mutable void *chartState;
protected: protected:

View File

@ -6,6 +6,7 @@
*/ */
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <sstream>
#include <algorithm> #include <algorithm>
#include "TargetPhrases.h" #include "TargetPhrases.h"
#include "TargetPhraseImpl.h" #include "TargetPhraseImpl.h"
@ -49,13 +50,15 @@ void TargetPhrases::SortAndPrune(size_t tableLimit)
//cerr << "TargetPhrases=" << GetSize() << endl; //cerr << "TargetPhrases=" << GetSize() << endl;
} }
std::ostream &TargetPhrases::Debug(std::ostream &out, const System &system) const std::string TargetPhrases::Debug(const System &system) const
{ {
std::stringstream out;
BOOST_FOREACH(const SCFG::TargetPhraseImpl *tp, m_coll) { BOOST_FOREACH(const SCFG::TargetPhraseImpl *tp, m_coll) {
out << std::endl; out << std::endl;
tp->Debug(out, system); out << tp->Debug(system);
} }
return out; return out.str();
} }
} }

View File

@ -55,7 +55,7 @@ public:
void SortAndPrune(size_t tableLimit); void SortAndPrune(size_t tableLimit);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
protected: protected:
Coll m_coll; Coll m_coll;

View File

@ -75,16 +75,17 @@ void Word::OutputToStream(std::ostream &out) const
} }
} }
std::ostream &Word::Debug(std::ostream &out, const System &system) const std::string Word::Debug(const System &system) const
{ {
stringstream out;
if (isNonTerminal) { if (isNonTerminal) {
out << "["; out << "[";
} }
Moses2::Word::Debug(out, system); out << Moses2::Word::Debug(system);
if (isNonTerminal) { if (isNonTerminal) {
out << "]"; out << "]";
} }
return out; return out.str();
} }
} }

View File

@ -40,7 +40,7 @@ public:
size_t hash() const; size_t hash() const;
virtual void OutputToStream(std::ostream &out) const; virtual void OutputToStream(std::ostream &out) const;
virtual std::ostream &Debug(std::ostream &out, const System &system) const; virtual std::string Debug(const System &system) const;
protected: protected:
}; };

View File

@ -243,8 +243,9 @@ void Scores::CreateFromString(const std::string &str,
PlusEquals(system, featureFunction, scores); PlusEquals(system, featureFunction, scores);
} }
std::ostream &Scores::Debug(std::ostream &out, const System &system) const std::string Scores::Debug(const System &system) const
{ {
stringstream out;
out << "total=" << m_total; out << "total=" << m_total;
if (system.options.nbest.nbest_size) { if (system.options.nbest.nbest_size) {
@ -257,7 +258,7 @@ std::ostream &Scores::Debug(std::ostream &out, const System &system) const
} }
} }
return out; return out.str();
} }
// static functions to work out estimated scores // static functions to work out estimated scores

View File

@ -65,7 +65,7 @@ public:
void Assign(const System &system, const FeatureFunction &featureFunction, void Assign(const System &system, const FeatureFunction &featureFunction,
const std::vector<SCORE> &scores); const std::vector<SCORE> &scores);
std::ostream &Debug(std::ostream &out, const System &system) const; std::string Debug(const System &system) const;
// static functions to work out estimated scores // static functions to work out estimated scores
static SCORE CalcWeightedScore(const System &system, static SCORE CalcWeightedScore(const System &system,

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <sstream>
#include "Phrase.h" #include "Phrase.h"
#include "Word.h" #include "Word.h"
#include "SCFG/Word.h" #include "SCFG/Word.h"
@ -29,18 +30,18 @@ public:
return ret; return ret;
} }
virtual std::ostream &Debug(std::ostream &out, const System &system) const virtual std::string Debug(const System &system) const
{ {
std::stringstream out;
if (GetSize()) { if (GetSize()) {
(*this)[0].Debug(out, system); out << (*this)[0].Debug(system);
for (size_t i = 1; i < GetSize(); ++i) { for (size_t i = 1; i < GetSize(); ++i) {
const WORD &word = (*this)[i]; const WORD &word = (*this)[i];
out << " "; out << " " << word.Debug(system);
word.Debug(out, system);
} }
} }
return out; return out.str();
} }
protected: protected:

View File

@ -6,6 +6,7 @@
*/ */
#pragma once #pragma once
#include <sstream>
#include "PhraseImplTemplate.h" #include "PhraseImplTemplate.h"
#include "System.h" #include "System.h"
#include "Scores.h" #include "Scores.h"
@ -45,13 +46,13 @@ public:
SCORE *GetScoresProperty(int propertyInd) const SCORE *GetScoresProperty(int propertyInd) const
{ return scoreProperties ? scoreProperties + propertyInd : NULL; } { return scoreProperties ? scoreProperties + propertyInd : NULL; }
virtual std::ostream &Debug(std::ostream &out, const System &system) const virtual std::string Debug(const System &system) const
{ {
Phrase<WORD>::Debug(out, system); std::stringstream out;
out << " SCORES:"; out << Phrase<WORD>::Debug(system);
GetScores().Debug(out, system); out << " SCORES:" << GetScores().Debug(system);
return out; return out.str();
} }
protected: protected:

View File

@ -405,7 +405,7 @@ void ProbingPT::InitActiveChart(
const SCFG::Manager &mgr, const SCFG::Manager &mgr,
SCFG::InputPath &path) const SCFG::InputPath &path) const
{ {
cerr << "InitActiveChart=" << path.Debug(cerr, mgr.system) << endl; //cerr << "InitActiveChart=" << path.Debug(cerr, mgr.system) << endl;
size_t ptInd = GetPtInd(); size_t ptInd = GetPtInd();
ActiveChartEntryProbing *chartEntry = new (pool.Allocate<ActiveChartEntryProbing>()) ActiveChartEntryProbing(pool); ActiveChartEntryProbing *chartEntry = new (pool.Allocate<ActiveChartEntryProbing>()) ActiveChartEntryProbing(pool);
path.AddActiveChartEntry(ptInd, chartEntry); path.AddActiveChartEntry(ptInd, chartEntry);
@ -417,7 +417,7 @@ void ProbingPT::Lookup(MemPool &pool,
const SCFG::Stacks &stacks, const SCFG::Stacks &stacks,
SCFG::InputPath &path) const SCFG::InputPath &path) const
{ {
cerr << "Lookup=" << endl; //cerr << "Lookup=" << endl;
if (path.range.GetNumWordsCovered() > maxChartSpan) { if (path.range.GetNumWordsCovered() > maxChartSpan) {
return; return;
} }
@ -521,9 +521,12 @@ void ProbingPT::LookupGivenNode(
SCFG::InputPath &outPath) const SCFG::InputPath &outPath) const
{ {
std::pair<bool, uint64_t> key = prevEntry.GetKey(wordSought, *this); std::pair<bool, uint64_t> key = prevEntry.GetKey(wordSought, *this);
//cerr << "wordSought=" << wordSought.Debug(cerr, mgr.system) << " " << key.first << endl;
cerr << "wordSought=" << wordSought.Debug(mgr.system) << endl;
//cerr << "HELLO" << endl;
if (!key.first) { if (!key.first) {
// should only happen when looking up unary rules // should only occasionally happen when looking up unary rules
return; return;
} }

View File

@ -71,8 +71,9 @@ bool Word::operator<(const Word &compare) const
return (cmp < 0); return (cmp < 0);
} }
std::ostream &Word::Debug(std::ostream &out, const System &system) const std::string Word::Debug(const System &system) const
{ {
stringstream out;
bool outputAlready = false; bool outputAlready = false;
for (size_t i = 0; i < MAX_NUM_FACTORS; ++i) { for (size_t i = 0; i < MAX_NUM_FACTORS; ++i) {
const Factor *factor = m_factors[i]; const Factor *factor = m_factors[i];
@ -85,7 +86,7 @@ std::ostream &Word::Debug(std::ostream &out, const System &system) const
} }
} }
return out; return out.str();
} }
void Word::OutputToStream(std::ostream &out) const void Word::OutputToStream(std::ostream &out) const

View File

@ -53,7 +53,7 @@ public:
} }
virtual void OutputToStream(std::ostream &out) const; virtual void OutputToStream(std::ostream &out) const;
virtual std::ostream &Debug(std::ostream &out, const System &system) const; virtual std::string Debug(const System &system) const;
std::string GetString(const FactorList &factorTypes) const; std::string GetString(const FactorList &factorTypes) const;
protected: protected: