Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/moses
diff options
context:
space:
mode:
Diffstat (limited to 'moses')
-rwxr-xr-xmoses/src/Hypothesis.h2
-rwxr-xr-xmoses/src/Manager.cpp53
-rwxr-xr-xmoses/src/Manager.h2
-rwxr-xr-xmoses/src/Parameter.cpp1
-rwxr-xr-xmoses/src/StaticData.cpp6
-rwxr-xr-xmoses/src/StaticData.h5
6 files changed, 69 insertions, 0 deletions
diff --git a/moses/src/Hypothesis.h b/moses/src/Hypothesis.h
index cbf2cedd4..ff738b345 100755
--- a/moses/src/Hypothesis.h
+++ b/moses/src/Hypothesis.h
@@ -256,6 +256,8 @@ public:
const ScoreComponentCollection &GetCachedReorderingScore() const;
+ const TranslationOption &GetTranslationOption() const
+ { return *m_transOpt; }
};
std::ostream& operator<<(std::ostream& out, const Hypothesis& hypothesis);
diff --git a/moses/src/Manager.cpp b/moses/src/Manager.cpp
index acf5bbe20..692b6ba3f 100755
--- a/moses/src/Manager.cpp
+++ b/moses/src/Manager.cpp
@@ -479,3 +479,56 @@ void Manager::CalcDecoderStatistics() const
}
}
}
+
+void Manager::GetWordGraph() const
+{
+ const StaticData &staticData = StaticData::Instance();
+ string fileName = staticData.GetParam("output-word-graph")[0];
+ bool outputNBest = Scan<bool>(staticData.GetParam("output-word-graph")[1]);
+
+ std::ofstream wordGraphFile;
+ wordGraphFile.open(fileName.c_str());
+
+ size_t stackNo = 1;
+ std::vector < HypothesisStack >::const_iterator iterStack;
+ for (iterStack = ++m_hypoStackColl.begin() ; iterStack != m_hypoStackColl.end() ; ++iterStack)
+ {
+ cerr << endl << stackNo++ << endl;
+ const HypothesisStack &stack = *iterStack;
+ HypothesisStack::const_iterator iterHypo;
+ for (iterHypo = stack.begin() ; iterHypo != stack.end() ; ++iterHypo)
+ {
+ const Hypothesis *hypo = *iterHypo;
+ const Hypothesis *prevHypo = hypo->GetPrevHypo();
+ const Phrase *sourcePhrase = hypo->GetSourcePhrase();
+ const Phrase &targetPhrase = hypo->GetCurrTargetPhrase();
+
+
+ wordGraphFile << prevHypo->GetId() << " -> " << hypo->GetId() << ": "
+ << *sourcePhrase << " "
+ << targetPhrase << " "
+ << hypo->GetTranslationOption().GetScoreBreakdown() << endl;
+
+ if (outputNBest)
+ {
+ const ArcList *arcList = hypo->GetArcList();
+ if (arcList != NULL)
+ {
+ ArcList::const_iterator iterArcList;
+ for (iterArcList = arcList->begin() ; iterArcList != arcList->end() ; ++iterArcList)
+ {
+ const Hypothesis *loserHypo = *iterArcList;
+ const Hypothesis *prevHypo = loserHypo->GetPrevHypo();
+
+ wordGraphFile << prevHypo->GetId() << " -> " << loserHypo->GetId() << ": "
+ << *sourcePhrase << " "
+ << targetPhrase << " "
+ << loserHypo->GetTranslationOption().GetScoreBreakdown() << endl;
+ }
+ }
+ } //if (outputNBest)
+ } //for (iterHypo
+ } // for (iterStack
+
+ wordGraphFile.close();
+} \ No newline at end of file
diff --git a/moses/src/Manager.h b/moses/src/Manager.h
index 6c1383e0d..7ae9d9b74 100755
--- a/moses/src/Manager.h
+++ b/moses/src/Manager.h
@@ -97,6 +97,8 @@ public:
const Hypothesis *GetBestHypothesis() const;
void CalcNBest(size_t count, TrellisPathList &ret,bool onlyDistinct=0) const;
+ void GetWordGraph() const;
+
/***
* to be called after processing a sentence (which may consist of more than just calling ProcessSentence() )
*/
diff --git a/moses/src/Parameter.cpp b/moses/src/Parameter.cpp
index 02f00d68d..0c4225fb0 100755
--- a/moses/src/Parameter.cpp
+++ b/moses/src/Parameter.cpp
@@ -80,6 +80,7 @@ Parameter::Parameter()
AddParam("mbr-scale", "scaling factor to convert log linear score probability in MBR decoding (default 1.0)");
AddParam("use-persistent-cache", "cache translation options across sentences (default true)");
AddParam("recover-input-path", "r", "(conf net/word lattice only) - recover input path corresponding to the best translation");
+ AddParam("output-word-graph", "owg", "Output stack info as word graph. Takes filename, 0=only hypos in stack, 1=stack + nbest hypos");
}
Parameter::~Parameter()
diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp
index d3aaf7e44..a4cf7099a 100755
--- a/moses/src/StaticData.cpp
+++ b/moses/src/StaticData.cpp
@@ -138,6 +138,12 @@ bool StaticData::LoadData(Parameter *parameter)
m_nBestFactor = 20;
}
+ // word graph
+ if (m_parameter->GetParam("output-word-graph").size() == 2)
+ m_outputWordGraph = true;
+ else
+ m_outputWordGraph = false;
+
// include feature names in the n-best list
SetBooleanParameter( &m_labeledNBestList, "labeled-n-best-list", true );
diff --git a/moses/src/StaticData.h b/moses/src/StaticData.h
index 600030b0b..8cb1dc5e7 100755
--- a/moses/src/StaticData.h
+++ b/moses/src/StaticData.h
@@ -123,6 +123,9 @@ protected:
mutable const InputType* m_input; //! holds reference to current sentence
bool m_isAlwaysCreateDirectTranslationOption;
//! constructor. only the 1 static variable can be created
+
+ bool m_outputWordGraph; //! whether to output word graph
+
StaticData();
//! helper fn to set bool param from ini file/command line
@@ -332,6 +335,8 @@ public:
{
return m_nBestFactor;
}
+ bool GetOutputWordGraph() const
+ { return m_outputWordGraph; }
//! Sets the global score vector weights for a given ScoreProducer.
void SetWeightsForScoreProducer(const ScoreProducer* sp, const std::vector<float>& weights);