mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-04 09:56:33 +03:00
correct string output
This commit is contained in:
parent
955e4156f6
commit
e1fd84b864
@ -24,16 +24,15 @@ NBestCandidate::NBestCandidate(const SCFG::Manager &mgr, const ArcList &varcList
|
|||||||
:arcList(&varcList)
|
:arcList(&varcList)
|
||||||
,ind(vind)
|
,ind(vind)
|
||||||
{
|
{
|
||||||
const HypothesisBase *hypoBase = varcList[ind];
|
const SCFG::Hypothesis &hypo = GetHypo();
|
||||||
|
|
||||||
// copy scores from best hypo
|
// copy scores from best hypo
|
||||||
MemPool &pool = mgr.GetPool();
|
MemPool &pool = mgr.GetPool();
|
||||||
m_scores = new (pool.Allocate<Scores>())
|
m_scores = new (pool.Allocate<Scores>())
|
||||||
Scores(mgr.system, pool, mgr.system.featureFunctions.GetNumScores(), hypoBase->GetScores());
|
Scores(mgr.system, pool, mgr.system.featureFunctions.GetNumScores(), hypo.GetScores());
|
||||||
|
|
||||||
// children
|
// children
|
||||||
const ArcLists &arcLists = mgr.arcLists;
|
const ArcLists &arcLists = mgr.arcLists;
|
||||||
const SCFG::Hypothesis &hypo = *static_cast<const SCFG::Hypothesis*>(hypoBase);
|
|
||||||
//const SCFG::TargetPhraseImpl &tp = hypo.GetTargetPhrase();
|
//const SCFG::TargetPhraseImpl &tp = hypo.GetTargetPhrase();
|
||||||
|
|
||||||
const Vector<const Hypothesis*> &prevHypos = hypo.GetPrevHypos();
|
const Vector<const Hypothesis*> &prevHypos = hypo.GetPrevHypos();
|
||||||
@ -45,8 +44,43 @@ NBestCandidate::NBestCandidate(const SCFG::Manager &mgr, const ArcList &varcList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NBestCandidate::OutputToStream(const SCFG::Manager &mgr, std::stringstream &strm)
|
const SCFG::Hypothesis &NBestCandidate::GetHypo() const
|
||||||
{
|
{
|
||||||
|
const HypothesisBase *hypoBase = (*arcList)[ind];
|
||||||
|
const SCFG::Hypothesis &hypo = *static_cast<const SCFG::Hypothesis*>(hypoBase);
|
||||||
|
return hypo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NBestCandidate::OutputToStream(
|
||||||
|
const SCFG::Manager &mgr,
|
||||||
|
std::stringstream &strm,
|
||||||
|
const NBestColl &nbestColl) const
|
||||||
|
{
|
||||||
|
const SCFG::TargetPhraseImpl &tp = GetHypo().GetTargetPhrase();
|
||||||
|
|
||||||
|
for (size_t pos = 0; pos < tp.GetSize(); ++pos) {
|
||||||
|
const SCFG::Word &word = tp[pos];
|
||||||
|
//cerr << "word " << pos << "=" << word << endl;
|
||||||
|
if (word.isNonTerminal) {
|
||||||
|
//cerr << "is nt" << endl;
|
||||||
|
// non-term. fill out with prev hypo
|
||||||
|
size_t nonTermInd = tp.GetAlignNonTerm().GetNonTermIndexMap()[pos];
|
||||||
|
|
||||||
|
UTIL_THROW_IF2(nonTermInd >= children.size(), "Out of bounds:" << nonTermInd << ">=" << children.size());
|
||||||
|
|
||||||
|
const Child &child = children[nonTermInd];
|
||||||
|
UTIL_THROW_IF2(child.first == NULL, "ArcList == NULL");
|
||||||
|
|
||||||
|
const NBestCandidates &nbests = nbestColl.GetNBestCandidates(*child.first);
|
||||||
|
const NBestCandidate &nbest = nbests[child.second];
|
||||||
|
nbest.OutputToStream(mgr, strm, nbestColl);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//cerr << "not nt" << endl;
|
||||||
|
word.OutputToStream(strm);
|
||||||
|
strm << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +91,7 @@ void NBestColl::Add(const SCFG::Manager &mgr, const ArcList &arcList)
|
|||||||
m_candidates[&arcList].push_back(candidate);
|
m_candidates[&arcList].push_back(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NBestCandidates &NBestColl::GetNBestCandidates(const ArcList &arcList)
|
const NBestCandidates &NBestColl::GetNBestCandidates(const ArcList &arcList) const
|
||||||
{
|
{
|
||||||
Coll::const_iterator iter = m_candidates.find(&arcList);
|
Coll::const_iterator iter = m_candidates.find(&arcList);
|
||||||
UTIL_THROW_IF2(iter == m_candidates.end(), "Can't find arclist");
|
UTIL_THROW_IF2(iter == m_candidates.end(), "Can't find arclist");
|
||||||
@ -117,9 +151,9 @@ void KBestExtractor::OutputToStream(std::stringstream &strm)
|
|||||||
BOOST_FOREACH(const NBestCandidate &deriv, nbestVec) {
|
BOOST_FOREACH(const NBestCandidate &deriv, nbestVec) {
|
||||||
strm << m_mgr.GetTranslationId() << " ||| ";
|
strm << m_mgr.GetTranslationId() << " ||| ";
|
||||||
//cerr << "1" << flush;
|
//cerr << "1" << flush;
|
||||||
//strm << path->Output();
|
deriv.OutputToStream(m_mgr, strm, m_nbestColl);
|
||||||
//cerr << "2" << flush;
|
//cerr << "2" << flush;
|
||||||
strm << " ||| ";
|
strm << "||| ";
|
||||||
deriv.GetScores().OutputBreakdown(strm, m_mgr.system);
|
deriv.GetScores().OutputBreakdown(strm, m_mgr.system);
|
||||||
//cerr << "3" << flush;
|
//cerr << "3" << flush;
|
||||||
strm << "||| ";
|
strm << "||| ";
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include "../ArcLists.h"
|
#include "../ArcLists.h"
|
||||||
|
#include "TargetPhraseImpl.h"
|
||||||
|
|
||||||
namespace Moses2
|
namespace Moses2
|
||||||
{
|
{
|
||||||
@ -18,6 +19,7 @@ namespace SCFG
|
|||||||
{
|
{
|
||||||
class Manager;
|
class Manager;
|
||||||
class Hypothesis;
|
class Hypothesis;
|
||||||
|
class NBestColl;
|
||||||
|
|
||||||
class NBestCandidate
|
class NBestCandidate
|
||||||
{
|
{
|
||||||
@ -34,10 +36,15 @@ public:
|
|||||||
const Scores &GetScores() const
|
const Scores &GetScores() const
|
||||||
{ return *m_scores; }
|
{ return *m_scores; }
|
||||||
|
|
||||||
void OutputToStream(const SCFG::Manager &mgr, std::stringstream &strm);
|
void OutputToStream(
|
||||||
|
const SCFG::Manager &mgr,
|
||||||
|
std::stringstream &strm,
|
||||||
|
const NBestColl &nbestColl) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Scores *m_scores;
|
Scores *m_scores;
|
||||||
|
|
||||||
|
const SCFG::Hypothesis &GetHypo() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
@ -48,7 +55,7 @@ class NBestColl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Add(const SCFG::Manager &mgr, const ArcList &arcList);
|
void Add(const SCFG::Manager &mgr, const ArcList &arcList);
|
||||||
const NBestCandidates &GetNBestCandidates(const ArcList &arcList);
|
const NBestCandidates &GetNBestCandidates(const ArcList &arcList) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef boost::unordered_map<const ArcList*, NBestCandidates> Coll;
|
typedef boost::unordered_map<const ArcList*, NBestCandidates> Coll;
|
||||||
|
Loading…
Reference in New Issue
Block a user