mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
doesn't segfault at least
This commit is contained in:
parent
33fc7986de
commit
2b436c144d
@ -137,13 +137,15 @@ void Hypothesis::OutputToStream(std::ostream &out) const
|
||||
if (m_prevHypo) {
|
||||
m_prevHypo->OutputToStream(out);
|
||||
}
|
||||
//cerr << *this << endl;
|
||||
//cerr << "range=" << GetInputPath().range << endl;
|
||||
|
||||
const TargetPhrase<Moses2::Word> &tp = GetTargetPhrase();
|
||||
if (tp.GetSize()) {
|
||||
const SubPhrase<Moses2::Word> &subPhrase = static_cast<const InputPath&>(GetInputPath()).subPhrase;
|
||||
//cerr << "tp=" << tp.Debug(m_mgr->system) << endl;
|
||||
//cerr << "subPhrase=" << subPhrase.Debug(m_mgr->system) << endl;
|
||||
|
||||
tp.OutputToStream(subPhrase, m_mgr->system.options.input.placeholder_factor, out);
|
||||
tp.OutputToStream(m_mgr->system, subPhrase, out);
|
||||
}
|
||||
|
||||
if (m_path->range.GetStartPos() != NOT_FOUND) {
|
||||
|
@ -50,7 +50,7 @@ std::string InputPath::Debug(const System &system) const
|
||||
{
|
||||
stringstream out;
|
||||
|
||||
out << range << " ";
|
||||
out << range << " " << flush;
|
||||
out << subPhrase.Debug(system);
|
||||
return out.str();
|
||||
}
|
||||
|
@ -234,6 +234,7 @@ std::string Manager::OutputNBest()
|
||||
size_t maxIter = system.options.nbest.nbest_size * system.options.nbest.factor;
|
||||
size_t bestInd = 0;
|
||||
for (size_t i = 0; i < maxIter; ++i) {
|
||||
cerr << "nbest i=" << i << endl;
|
||||
if (bestInd > system.options.nbest.nbest_size || contenders.empty()) {
|
||||
break;
|
||||
}
|
||||
|
@ -49,12 +49,4 @@ TargetPhraseImpl::~TargetPhraseImpl()
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
std::string TargetPhraseImpl::Debug(const System &system) const
|
||||
{
|
||||
stringstream out;
|
||||
out << Phrase<Moses2::Word>::Debug(system);
|
||||
out << " SCORES:" << GetScores().Debug(system);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ public:
|
||||
virtual SCORE GetScoreForPruning() const
|
||||
{ return GetFutureScore(); }
|
||||
|
||||
virtual std::string Debug(const System &system) const;
|
||||
|
||||
protected:
|
||||
SCORE m_estimatedScore;
|
||||
|
||||
|
@ -105,15 +105,17 @@ void TrellisPath::OutputToStream(std::ostream &out, const System &system) const
|
||||
|
||||
std::string TrellisPath::OutputTargetPhrase(const System &system) const
|
||||
{
|
||||
//cerr << "path=" << this << " " << nodes.size() << endl;
|
||||
std::stringstream out;
|
||||
for (int i = nodes.size() - 1; i >= 0; --i) {
|
||||
const TrellisNode &node = nodes[i];
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(node.GetHypo());
|
||||
//cerr << "hypo=" << hypo << " " << *hypo << endl;
|
||||
const SubPhrase<Moses2::Word> &subPhrase = static_cast<const InputPath&>(hypo->GetInputPath()).subPhrase;
|
||||
for (int i = nodes.size() - 2; i >= 0; --i) {
|
||||
const TrellisNode &node = nodes[i];
|
||||
|
||||
hypo->GetTargetPhrase().OutputToStream(subPhrase, system.options.input.placeholder_factor, out);
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(node.GetHypo());
|
||||
const TargetPhrase<Moses2::Word> &tp = hypo->GetTargetPhrase();
|
||||
|
||||
const InputPath &path = static_cast<const InputPath&>(hypo->GetInputPath());
|
||||
const SubPhrase<Moses2::Word> &subPhrase = path.subPhrase;
|
||||
|
||||
tp.OutputToStream(system, subPhrase, out);
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "System.h"
|
||||
#include "Scores.h"
|
||||
#include "AlignmentInfoCollection.h"
|
||||
#include "TranslationModel/PhraseTable.h"
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
@ -85,48 +86,65 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void OutputToStream(const Phrase<Moses2::Word> &inputPhrase, FactorType placeholderFactor, std::ostream &out) const
|
||||
void OutputToStream(const System &system, const Phrase<Moses2::Word> &inputPhrase, std::ostream &out) const
|
||||
{
|
||||
// get placeholders
|
||||
FactorType placeholderFactor = system.options.input.placeholder_factor;
|
||||
std::map<size_t, const Factor*> placeholders;
|
||||
if (placeholderFactor != NOT_FOUND) {
|
||||
// creates map of target position -> factor for placeholders
|
||||
placeholders = GetPlaceholders(inputPhrase, placeholderFactor);
|
||||
placeholders = GetPlaceholders(system, inputPhrase);
|
||||
}
|
||||
|
||||
size_t size = PhraseImplTemplate<WORD>::GetSize();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
const WORD &word = (*this)[i];
|
||||
word.OutputToStream(out);
|
||||
out << " ";
|
||||
// output placeholder, if any
|
||||
std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(i);
|
||||
if (iter == placeholders.end()) {
|
||||
const WORD &word = (*this)[i];
|
||||
word.OutputToStream(out);
|
||||
}
|
||||
else {
|
||||
const Factor *factor = iter->second;
|
||||
out << *factor;
|
||||
}
|
||||
|
||||
out << " ";
|
||||
}
|
||||
}
|
||||
|
||||
std::map<size_t, const Factor*> GetPlaceholders(const System &system, const Phrase<WORD> &inputPhrase) const
|
||||
{
|
||||
FactorType placeholderFactor = system.options.input.placeholder_factor;
|
||||
std::map<size_t, const Factor*> ret;
|
||||
std::cerr << "inputPhrase=" << inputPhrase.Debug(system) << std::endl;
|
||||
|
||||
for (size_t sourcePos = 0; sourcePos < inputPhrase.GetSize(); ++sourcePos) {
|
||||
const Factor *factor = inputPhrase[sourcePos][placeholderFactor];
|
||||
if (factor) {
|
||||
std::cerr << "factor=" << factor << std::endl;
|
||||
std::set<size_t> targetPos = GetAlignTerm().GetAlignmentsForSource(sourcePos);
|
||||
UTIL_THROW_IF2(targetPos.size() != 1,
|
||||
"Placeholder should be aligned to 1, and only 1, word:" << targetPos.size() << "!=1");
|
||||
ret[*targetPos.begin()] = factor;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual std::string Debug(const System &system) const
|
||||
{
|
||||
std::stringstream out;
|
||||
out << Phrase<WORD>::Debug(system);
|
||||
out << " pt=" << pt.GetName() << " ";
|
||||
out << " SCORES:" << GetScores().Debug(system);
|
||||
out << " ALIGN-T:";
|
||||
out << GetAlignTerm().Debug(system);
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
std::map<size_t, const Factor*> GetPlaceholders(const Phrase<WORD> &inputPhrase, FactorType placeholderFactor) const
|
||||
{
|
||||
std::map<size_t, const Factor*> ret;
|
||||
|
||||
for (size_t sourcePos = 0; sourcePos < inputPhrase.GetSize(); ++sourcePos) {
|
||||
const Factor *factor = inputPhrase[sourcePos][placeholderFactor];
|
||||
if (factor) {
|
||||
std::set<size_t> targetPos = GetAlignTerm().GetAlignmentsForSource(sourcePos);
|
||||
UTIL_THROW_IF2(targetPos.size() != 1,
|
||||
"Placeholder should be aligned to 1, and only 1, word");
|
||||
ret[*targetPos.begin()] = factor;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected:
|
||||
Scores *m_scores;
|
||||
const AlignmentInfo *m_alignTerm;
|
||||
|
@ -88,6 +88,7 @@ void PhraseTableMemory::Load(System &system)
|
||||
target->GetScores().CreateFromString(toks[2], *this, system, true);
|
||||
//cerr << "created scores:" << *target << endl;
|
||||
|
||||
cerr << "alignstr=" << toks[3] << endl;
|
||||
target->SetAlignmentInfo(toks[3]);
|
||||
|
||||
// properties
|
||||
@ -101,6 +102,7 @@ void PhraseTableMemory::Load(System &system)
|
||||
//cerr << "EvaluateInIsolation:" << *target << endl;
|
||||
m_rootPb->AddRule(*source, target);
|
||||
|
||||
cerr << "target=" << target->Debug(system) << endl;
|
||||
}
|
||||
else {
|
||||
SCFG::PhraseImpl *source = SCFG::PhraseImpl::CreateFromString(tmpSourcePool, vocab, system,
|
||||
|
@ -42,6 +42,11 @@ void Word::CreateFromString(FactorCollection &vocab, const System &system,
|
||||
const Factor *factor = vocab.AddFactor(tok, system, false);
|
||||
m_factors[i] = factor;
|
||||
}
|
||||
|
||||
// null the rest
|
||||
for (size_t i = toks.size(); i < MAX_NUM_FACTORS; ++i) {
|
||||
m_factors[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Word::hash() const
|
||||
|
Loading…
Reference in New Issue
Block a user