move options out of Hypothesis

This commit is contained in:
David Madl 2015-11-13 17:56:16 +00:00
parent 73ab44c126
commit 5fea16a9a6
7 changed files with 30 additions and 37 deletions

View File

@ -241,7 +241,7 @@ PrintHypothesis() const
void
Hypothesis::
CleanupArcList()
CleanupArcList(size_t nBestSize, bool distinctNBest)
{
// point this hypo's main hypo to itself
SetWinningHypo(this);
@ -253,11 +253,6 @@ CleanupArcList()
* so we'll keep all of arc list if nedd distinct n-best list
*/
const StaticData &staticData = StaticData::Instance();
AllOptions const& opts = m_manager.options();
size_t nBestSize = opts.nbest.nbest_size;
bool distinctNBest = opts.NBestDistinct();
if (!distinctNBest && m_arcList->size() > nBestSize * 5) {
// prune arc list only if there too many arcs
NTH_ELEMENT4(m_arcList->begin(), m_arcList->begin() + nBestSize - 1,
@ -351,7 +346,7 @@ GetTargetPhraseStringRep() const
void
Hypothesis::
OutputAlignment(std::ostream &out) const
OutputAlignment(std::ostream &out, WordAlignmentSort sortOrder) const
{
std::vector<const Hypothesis *> edges;
const Hypothesis *currentHypo = this;
@ -360,7 +355,7 @@ OutputAlignment(std::ostream &out) const
currentHypo = currentHypo->GetPrevHypo();
}
OutputAlignment(out, edges, m_manager.options().output.WA_SortOrder);
OutputAlignment(out, edges, sortOrder);
}
@ -426,13 +421,13 @@ OutputInput(std::ostream& os) const
void
Hypothesis::
OutputBestSurface(std::ostream &out, const std::vector<FactorType> &outputFactorOrder,
char reportSegmentation, bool reportAllFactors) const
const ReportingOptions &options) const
{
if (m_prevHypo) {
// recursively retrace this best path through the lattice, starting from the end of the hypothesis sentence
m_prevHypo->OutputBestSurface(out, outputFactorOrder, reportSegmentation, reportAllFactors);
m_prevHypo->OutputBestSurface(out, outputFactorOrder, options);
}
OutputSurface(out, *this, outputFactorOrder, reportSegmentation, reportAllFactors);
OutputSurface(out, *this, outputFactorOrder, options);
}
//////////////////////////////////////////////////////////////////////////
@ -443,14 +438,15 @@ void
Hypothesis::
OutputSurface(std::ostream &out, const Hypothesis &edge,
const std::vector<FactorType> &outputFactorOrder,
char reportSegmentation, bool reportAllFactors) const
const ReportingOptions &options) const
{
UTIL_THROW_IF2(outputFactorOrder.size() == 0,
"Must specific at least 1 output factor");
const TargetPhrase& phrase = edge.GetCurrTargetPhrase();
// TODO: slay the rest of StaticData here and move stuff into ReportingOptions
bool markUnknown = GetManager().options().unk.mark;
// = StaticData::Instance().GetMarkUnknown();
if (reportAllFactors == true) {
bool featureLabels = StaticData::Instance().options().nbest.include_feature_labels;
if (options.ReportAllFactors == true) {
out << phrase;
} else {
FactorType placeholderFactor
@ -498,23 +494,21 @@ OutputSurface(std::ostream &out, const Hypothesis &edge,
}
// trace ("report segmentation") option "-t" / "-tt"
if (reportSegmentation > 0 && phrase.GetSize() > 0) {
if (options.ReportSegmentation > 0 && phrase.GetSize() > 0) {
const Range &sourceRange = edge.GetCurrSourceWordsRange();
const int sourceStart = sourceRange.GetStartPos();
const int sourceEnd = sourceRange.GetEndPos();
out << "|" << sourceStart << "-" << sourceEnd; // enriched "-tt"
if (reportSegmentation == 2) {
WordAlignmentSort waso = m_manager.options().output.WA_SortOrder;
if (options.ReportSegmentation == 2) {
out << ",wa=";
const AlignmentInfo &ai = edge.GetCurrTargetPhrase().GetAlignTerm();
Hypothesis::OutputAlignment(out, ai, 0, 0, waso);
Hypothesis::OutputAlignment(out, ai, 0, 0, options.WA_SortOrder);
out << ",total=";
out << edge.GetScore() - edge.GetPrevHypo()->GetScore();
out << ",";
ScoreComponentCollection scoreBreakdown(edge.GetScoreBreakdown());
scoreBreakdown.MinusEquals(edge.GetPrevHypo()->GetScoreBreakdown());
bool with_labels = m_manager.options().nbest.include_feature_labels;
scoreBreakdown.OutputAllFeatureScores(out, with_labels);
scoreBreakdown.OutputAllFeatureScores(out, featureLabels);
}
out << "| ";
}

View File

@ -50,6 +50,7 @@ class FFState;
class StatelessFeatureFunction;
class StatefulFeatureFunction;
class Manager;
class ReportingOptions;
typedef std::vector<Hypothesis*> ArcList;
@ -201,7 +202,7 @@ public:
}
void AddArc(Hypothesis *loserHypo);
void CleanupArcList();
void CleanupArcList(size_t nBestSize, bool distinctNBest);
//! returns a list alternative previous hypotheses (or NULL if n-best support is disabled)
inline const ArcList* GetArcList() const {
@ -239,7 +240,7 @@ public:
}
void
OutputAlignment(std::ostream &out) const;
OutputAlignment(std::ostream &out, WordAlignmentSort sortOrder) const;
static void
OutputAlignment(std::ostream &out,
@ -254,9 +255,9 @@ public:
void OutputInput(std::ostream& os) const;
static void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo);
void OutputBestSurface(std::ostream &out, const std::vector<Moses::FactorType> &outputFactorOrder, char reportSegmentation, bool reportAllFactors) const;
void OutputBestSurface(std::ostream &out, const std::vector<Moses::FactorType> &outputFactorOrder, const ReportingOptions &options) const;
void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<FactorType> &outputFactorOrder,
char reportSegmentation, bool reportAllFactors) const;
const ReportingOptions &options) const;
// creates a map of TARGET positions which should be replaced by word using placeholder
std::map<size_t, const Moses::Factor*> GetPlaceholders(const Moses::Hypothesis &hypo, Moses::FactorType placeholderFactor) const;
@ -267,8 +268,8 @@ public:
#ifdef HAVE_XMLRPC_C
// these are implemented in moses/server/Hypothesis_4server.cpp !
void OutputWordAlignment(std::vector<xmlrpc_c::value>& out) const;
void OutputLocalWordAlignment(std::vector<xmlrpc_c::value>& dest) const;
void OutputWordAlignment(std::vector<xmlrpc_c::value>& out, const ReportingOptions &options) const;
void OutputLocalWordAlignment(std::vector<xmlrpc_c::value>& dest, const ReportingOptions &options) const;
#endif
bool beats(Hypothesis const& b) const;

View File

@ -244,7 +244,7 @@ void HypothesisStackCubePruning::CleanupArcList()
iterator iter;
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {
Hypothesis *mainHypo = *iter;
mainHypo->CleanupArcList();
mainHypo->CleanupArcList(this->m_manager.options().nbest.nbest_size, this->m_manager.options().NBestDistinct());
}
}

View File

@ -266,7 +266,7 @@ void HypothesisStackNormal::CleanupArcList()
iterator iter;
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {
Hypothesis *mainHypo = *iter;
mainHypo->CleanupArcList();
mainHypo->CleanupArcList(this->m_manager.options().nbest.nbest_size, this->m_manager.options().NBestDistinct());
}
}

View File

@ -1547,11 +1547,10 @@ void Manager::OutputBest(OutputCollector *collector) const
bestHypo->OutputBestSurface(
out,
staticData.GetOutputFactorOrder(),
options().output.ReportSegmentation,
options().output.ReportAllFactors);
options().output);
if (options().output.PrintAlignmentInfo) {
out << "||| ";
bestHypo->OutputAlignment(out);
bestHypo->OutputAlignment(out, options().output.WA_SortOrder);
}
IFVERBOSE(1) {

View File

@ -5,15 +5,14 @@
namespace Moses {
void
Hypothesis::
OutputLocalWordAlignment(std::vector<xmlrpc_c::value>& dest) const
OutputLocalWordAlignment(std::vector<xmlrpc_c::value>& dest, const ReportingOptions &options) const
{
using namespace std;
Range const& src = this->GetCurrSourceWordsRange();
Range const& trg = this->GetCurrTargetWordsRange();
WordAlignmentSort waso = m_manager.options().output.WA_SortOrder;
vector<pair<size_t,size_t> const* > a
= this->GetCurrTargetPhrase().GetAlignTerm().GetSortedAlignments(waso);
= this->GetCurrTargetPhrase().GetAlignTerm().GetSortedAlignments(options.WA_SortOrder);
typedef pair<size_t,size_t> item;
map<string, xmlrpc_c::value> M;
BOOST_FOREACH(item const* p, a) {
@ -25,13 +24,13 @@ namespace Moses {
void
Hypothesis::
OutputWordAlignment(std::vector<xmlrpc_c::value>& out) const
OutputWordAlignment(std::vector<xmlrpc_c::value>& out, const ReportingOptions &options) const
{
std::vector<Hypothesis const*> tmp;
for (Hypothesis const* h = this; h; h = h->GetPrevHypo())
tmp.push_back(h);
for (size_t i = tmp.size(); i-- > 0;)
tmp[i]->OutputLocalWordAlignment(out);
tmp[i]->OutputLocalWordAlignment(out, options);
}
}

View File

@ -391,7 +391,7 @@ pack_hypothesis(vector<Hypothesis const* > const& edges, string const& key,
// word alignment, if requested
vector<xmlrpc_c::value> w_aln;
BOOST_FOREACH(Hypothesis const* e, edges)
e->OutputLocalWordAlignment(w_aln);
e->OutputLocalWordAlignment(w_aln, m_options.output);
dest["word-align"] = xmlrpc_c::value_array(w_aln);
}
}