diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-04 21:35:19 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-04 21:35:19 +0300 |
commit | b23c00989b30a916d3a3fba98bf033dec5081699 (patch) | |
tree | 41cc1ea0903e93d24021ebfe5e2cf72063eaf0e5 | |
parent | 3a2f58eb2c97d03b486508db1438fb8b877f85d7 (diff) |
move OutputDetailedTreeFragmentsTranslationReport() to Manager
-rw-r--r-- | moses/BaseManager.h | 1 | ||||
-rw-r--r-- | moses/ChartManager.cpp | 64 | ||||
-rw-r--r-- | moses/ChartManager.h | 6 | ||||
-rw-r--r-- | moses/IOWrapper.cpp | 104 | ||||
-rw-r--r-- | moses/IOWrapper.h | 22 | ||||
-rw-r--r-- | moses/Incremental.cpp | 50 | ||||
-rw-r--r-- | moses/Incremental.h | 6 | ||||
-rw-r--r-- | moses/Manager.h | 2 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager-inl.h | 7 | ||||
-rw-r--r-- | moses/Syntax/S2T/Manager.h | 8 | ||||
-rw-r--r-- | moses/TranslationTask.cpp | 13 |
11 files changed, 142 insertions, 141 deletions
diff --git a/moses/BaseManager.h b/moses/BaseManager.h index 41bac2b51..49e28b005 100644 --- a/moses/BaseManager.h +++ b/moses/BaseManager.h @@ -51,6 +51,7 @@ public: virtual void OutputLatticeSamples(OutputCollector *collector) const = 0; virtual void OutputAlignment(OutputCollector *collector) const = 0; virtual void OutputDetailedTranslationReport(OutputCollector *collector) const = 0; + virtual void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const = 0; }; diff --git a/moses/ChartManager.cpp b/moses/ChartManager.cpp index a90ea717d..824b440c8 100644 --- a/moses/ChartManager.cpp +++ b/moses/ChartManager.cpp @@ -29,6 +29,7 @@ #include "StaticData.h" #include "DecodeStep.h" #include "TreeInput.h" +#include "moses/FF/StatefulFeatureFunction.h" #include "moses/FF/WordPenaltyProducer.h" #include "moses/OutputCollector.h" #include "moses/ChartKBestExtractor.h" @@ -680,4 +681,67 @@ void ChartManager::OutputUnknowns(OutputCollector *collector) const } +void ChartManager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const +{ + const ChartHypothesis *hypo = GetBestHypothesis(); + if (collector == NULL || hypo == NULL) { + return; + } + + std::ostringstream out; + ApplicationContext applicationContext; + + const Sentence &sentence = dynamic_cast<const Sentence &>(m_source); + const size_t translationId = m_source.GetTranslationId(); + + OutputTreeFragmentsTranslationOptions(out, applicationContext, hypo, sentence, translationId); + + //Tree of full sentence + const StatefulFeatureFunction* treeStructure = StaticData::Instance().GetTreeStructure(); + if (treeStructure != NULL) { + const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions(); + for( size_t i=0; i<sff.size(); i++ ) { + if (sff[i] == treeStructure) { + const TreeState* tree = dynamic_cast<const TreeState*>(hypo->GetFFState(i)); + out << "Full Tree " << translationId << ": " << tree->GetTree()->GetString() << "\n"; + break; + } + } + } + + collector->Write(translationId, out.str()); + +} + +void ChartManager::OutputTreeFragmentsTranslationOptions(std::ostream &out, + ApplicationContext &applicationContext, + const ChartHypothesis *hypo, + const Sentence &sentence, + long translationId) const +{ + + if (hypo != NULL) { + OutputTranslationOption(out, applicationContext, hypo, sentence, translationId); + + const TargetPhrase &currTarPhr = hypo->GetCurrTargetPhrase(); + + out << " ||| "; + if (const PhraseProperty *property = currTarPhr.GetProperty("Tree")) { + out << " " << *property->GetValueString(); + } else { + out << " " << "noTreeInfo"; + } + out << std::endl; + } + + // recursive + const std::vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos(); + std::vector<const ChartHypothesis*>::const_iterator iter; + for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { + const ChartHypothesis *prevHypo = *iter; + OutputTreeFragmentsTranslationOptions(out, applicationContext, prevHypo, sentence, translationId); + } +} + + } // namespace Moses diff --git a/moses/ChartManager.h b/moses/ChartManager.h index 5ff6ab0d5..ba3617123 100644 --- a/moses/ChartManager.h +++ b/moses/ChartManager.h @@ -91,6 +91,11 @@ private: void ReconstructApplicationContext(const ChartHypothesis &hypo, const Sentence &sentence, ApplicationContext &context) const; + void OutputTreeFragmentsTranslationOptions(std::ostream &out, + ApplicationContext &applicationContext, + const ChartHypothesis *hypo, + const Sentence &sentence, + long translationId) const; public: ChartManager(InputType const& source); @@ -147,6 +152,7 @@ public: void OutputAlignment(OutputCollector *collector) const; void OutputDetailedTranslationReport(OutputCollector *collector) const; void OutputUnknowns(OutputCollector *collector) const; + void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const; }; diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index d246195ad..9e3e0f57f 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -502,110 +502,6 @@ void IOWrapper::WriteApplicationContext(std::ostream &out, } } -void IOWrapper::OutputDetailedTreeFragmentsTranslationReport( - const ChartHypothesis *hypo, - const Sentence &sentence, - long translationId) -{ - if (hypo == NULL) { - return; - } - std::ostringstream out; - ApplicationContext applicationContext; - - OutputTreeFragmentsTranslationOptions(out, applicationContext, hypo, sentence, translationId); - UTIL_THROW_IF2(m_detailTreeFragmentsOutputCollector == NULL, - "No output file for tree fragments specified"); - - //Tree of full sentence - const StatefulFeatureFunction* treeStructure = StaticData::Instance().GetTreeStructure(); - if (treeStructure != NULL) { - const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions(); - for( size_t i=0; i<sff.size(); i++ ) { - if (sff[i] == treeStructure) { - const TreeState* tree = dynamic_cast<const TreeState*>(hypo->GetFFState(i)); - out << "Full Tree " << translationId << ": " << tree->GetTree()->GetString() << "\n"; - break; - } - } - } - - m_detailTreeFragmentsOutputCollector->Write(translationId, out.str()); - -} - -void IOWrapper::OutputDetailedTreeFragmentsTranslationReport( - const search::Applied *applied, - const Sentence &sentence, - long translationId) -{ - if (applied == NULL) { - return; - } - std::ostringstream out; - ApplicationContext applicationContext; - - OutputTreeFragmentsTranslationOptions(out, applicationContext, applied, sentence, translationId); - UTIL_THROW_IF2(m_detailTreeFragmentsOutputCollector == NULL, - "No output file for tree fragments specified"); - - //Tree of full sentence - //TODO: incremental search doesn't support stateful features - - m_detailTreeFragmentsOutputCollector->Write(translationId, out.str()); - -} - -void IOWrapper::OutputTreeFragmentsTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) -{ - - if (hypo != NULL) { - OutputTranslationOption(out, applicationContext, hypo, sentence, translationId); - - const TargetPhrase &currTarPhr = hypo->GetCurrTargetPhrase(); - - out << " ||| "; - if (const PhraseProperty *property = currTarPhr.GetProperty("Tree")) { - out << " " << *property->GetValueString(); - } else { - out << " " << "noTreeInfo"; - } - out << std::endl; - } - - // recursive - const std::vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos(); - std::vector<const ChartHypothesis*>::const_iterator iter; - for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const ChartHypothesis *prevHypo = *iter; - OutputTreeFragmentsTranslationOptions(out, applicationContext, prevHypo, sentence, translationId); - } -} - -void IOWrapper::OutputTreeFragmentsTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const search::Applied *applied, const Sentence &sentence, long translationId) -{ - - if (applied != NULL) { - OutputTranslationOption(out, applicationContext, applied, sentence, translationId); - - const TargetPhrase &currTarPhr = *static_cast<const TargetPhrase*>(applied->GetNote().vp); - - out << " ||| "; - if (const PhraseProperty *property = currTarPhr.GetProperty("Tree")) { - out << " " << *property->GetValueString(); - } else { - out << " " << "noTreeInfo"; - } - out << std::endl; - } - - // recursive - const search::Applied *child = applied->Children(); - for (size_t i = 0; i < applied->GetArity(); i++) { - OutputTreeFragmentsTranslationOptions(out, applicationContext, child++, sentence, translationId); - } -} - /*** * print surface factor only for the given phrase */ diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index f55c73ff7..3244be44c 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -117,16 +117,6 @@ protected: ApplicationContext &context); void WriteApplicationContext(std::ostream &out, const ApplicationContext &context); - void OutputTreeFragmentsTranslationOptions(std::ostream &out, - ApplicationContext &applicationContext, - const Moses::ChartHypothesis *hypo, - const Moses::Sentence &sentence, - long translationId); - void OutputTreeFragmentsTranslationOptions(std::ostream &out, - ApplicationContext &applicationContext, - const search::Applied *applied, - const Moses::Sentence &sentence, - long translationId); void OutputSurface(std::ostream &out, const Phrase &phrase, const std::vector<FactorType> &outputFactorOrder, bool reportAllFactors); void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<FactorType> &outputFactorOrder, @@ -175,6 +165,11 @@ public: return m_latticeSamplesCollector; } + Moses::OutputCollector *GetDetailTreeFragmentsOutputCollector() { + return m_detailTreeFragmentsOutputCollector; + } + + // CHART void OutputBestHypo(const Moses::ChartHypothesis *hypo, long translationId); void OutputBestHypo(search::Applied applied, long translationId); @@ -184,13 +179,6 @@ public: void OutputDetailedAllTranslationReport(const std::vector<boost::shared_ptr<Moses::ChartKBestExtractor::Derivation> > &nBestList, const Moses::ChartManager &manager, const Moses::Sentence &sentence, long translationId); - void OutputDetailedTreeFragmentsTranslationReport(const Moses::ChartHypothesis *hypo, - const Moses::Sentence &sentence, - long translationId); - void OutputDetailedTreeFragmentsTranslationReport(const search::Applied *applied, - const Moses::Sentence &sentence, - long translationId); - // phrase-based void OutputBestSurface(std::ostream &out, const Moses::Hypothesis *hypo, const std::vector<Moses::FactorType> &outputFactorOrder, char reportSegmentation, bool reportAllFactors); void OutputLatticeMBRNBest(std::ostream& out, const std::vector<LatticeMBRSolution>& solutions,long translationId); diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp index e05697cc8..bb20d0640 100644 --- a/moses/Incremental.cpp +++ b/moses/Incremental.cpp @@ -411,6 +411,56 @@ void Manager::ReconstructApplicationContext(const search::Applied *applied, } } +void Manager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const +{ + if (collector == NULL || Completed().empty()) { + return; + } + + const search::Applied *applied = &Completed()[0]; + const Sentence &sentence = dynamic_cast<const Sentence &>(source_); + const size_t translationId = source_.GetTranslationId(); + + std::ostringstream out; + ApplicationContext applicationContext; + + OutputTreeFragmentsTranslationOptions(out, applicationContext, applied, sentence, translationId); + + //Tree of full sentence + //TODO: incremental search doesn't support stateful features + + collector->Write(translationId, out.str()); + +} + +void Manager::OutputTreeFragmentsTranslationOptions(std::ostream &out, + ApplicationContext &applicationContext, + const search::Applied *applied, + const Sentence &sentence, + long translationId) const +{ + + if (applied != NULL) { + OutputTranslationOption(out, applicationContext, applied, sentence, translationId); + + const TargetPhrase &currTarPhr = *static_cast<const TargetPhrase*>(applied->GetNote().vp); + + out << " ||| "; + if (const PhraseProperty *property = currTarPhr.GetProperty("Tree")) { + out << " " << *property->GetValueString(); + } else { + out << " " << "noTreeInfo"; + } + out << std::endl; + } + + // recursive + const search::Applied *child = applied->Children(); + for (size_t i = 0; i < applied->GetArity(); i++) { + OutputTreeFragmentsTranslationOptions(out, applicationContext, child++, sentence, translationId); + } +} + namespace { diff --git a/moses/Incremental.h b/moses/Incremental.h index ea416eb7b..fb304075b 100644 --- a/moses/Incremental.h +++ b/moses/Incremental.h @@ -45,6 +45,7 @@ public: {} void OutputAlignment(OutputCollector *collector) const {} + void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const; @@ -84,6 +85,11 @@ private: void ReconstructApplicationContext(const search::Applied *applied, const Sentence &sentence, ApplicationContext &context) const; + void OutputTreeFragmentsTranslationOptions(std::ostream &out, + ApplicationContext &applicationContext, + const search::Applied *applied, + const Sentence &sentence, + long translationId) const; }; diff --git a/moses/Manager.h b/moses/Manager.h index 71dd69930..3b09b6f0d 100644 --- a/moses/Manager.h +++ b/moses/Manager.h @@ -192,6 +192,8 @@ public: void OutputLatticeSamples(OutputCollector *collector) const; void OutputDetailedTranslationReport(OutputCollector *collector) const; void OutputUnknowns(OutputCollector *collector) const; + void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const + {} }; diff --git a/moses/Syntax/S2T/Manager-inl.h b/moses/Syntax/S2T/Manager-inl.h index 344705c6e..9df717edc 100644 --- a/moses/Syntax/S2T/Manager-inl.h +++ b/moses/Syntax/S2T/Manager-inl.h @@ -400,13 +400,6 @@ void Manager<Parser>::OutputNBest(OutputCollector *collector) const } -template<typename Parser> -void Manager<Parser>::OutputLatticeSamples(OutputCollector *collector) const -{} - -template<typename Parser> -void Manager<Parser>::OutputAlignment(OutputCollector *collector) const -{} template<typename Parser> void Manager<Parser>::OutputDetailedTranslationReport(OutputCollector *collector) const diff --git a/moses/Syntax/S2T/Manager.h b/moses/Syntax/S2T/Manager.h index 801da80f5..72e5f1aee 100644 --- a/moses/Syntax/S2T/Manager.h +++ b/moses/Syntax/S2T/Manager.h @@ -44,10 +44,14 @@ class Manager : public BaseManager const std::set<Word> &GetUnknownWords() const { return m_oovs; } void OutputNBest(OutputCollector *collector) const; - void OutputLatticeSamples(OutputCollector *collector) const; - void OutputAlignment(OutputCollector *collector) const; + void OutputLatticeSamples(OutputCollector *collector) const + {} + void OutputAlignment(OutputCollector *collector) const + {} void OutputDetailedTranslationReport(OutputCollector *collector) const; void OutputUnknowns(OutputCollector *collector) const; + void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const + {} private: void FindOovs(const PChart &, std::set<Word> &, std::size_t); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index c08aab706..26aded951 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -327,11 +327,8 @@ void TranslationTask::RunChart() m_ioWrapper.OutputBestHypo(nbest[0], translationId); manager.OutputDetailedTranslationReport(m_ioWrapper.GetDetailedTranslationCollector()); + manager.OutputDetailedTreeFragmentsTranslationReport(m_ioWrapper.GetDetailTreeFragmentsOutputCollector()); - if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) { - const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source); - m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(&nbest[0], sentence, translationId); - } } else { m_ioWrapper.OutputBestNone(translationId); } @@ -361,13 +358,7 @@ void TranslationTask::RunChart() manager.OutputAlignment(m_ioWrapper.GetAlignmentInfoCollector()); manager.OutputDetailedTranslationReport(m_ioWrapper.GetDetailedTranslationCollector()); - - - if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) { - const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source); - m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(bestHypo, sentence, translationId); - } - + manager.OutputDetailedTreeFragmentsTranslationReport(m_ioWrapper.GetDetailTreeFragmentsOutputCollector()); manager.OutputUnknowns(m_ioWrapper.GetUnknownsCollector()); //DIMw |