diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 20:40:53 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 20:40:53 +0300 |
commit | ba7afba9f6f325441387557ab8af487d5901f023 (patch) | |
tree | 42a4372ff8cc6fe6a4136051609aac95e76b7f48 /moses/BaseManager.cpp | |
parent | 08c57bce870da0e74ab0cf1aff4816539dfad3c8 (diff) |
move n-best code for phrase-based from IOWrapper to ChartManager
Diffstat (limited to 'moses/BaseManager.cpp')
-rw-r--r-- | moses/BaseManager.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp index f4d8123a0..17bcf9627 100644 --- a/moses/BaseManager.cpp +++ b/moses/BaseManager.cpp @@ -1,7 +1,61 @@ +#include <vector> + +#include "StaticData.h" #include "BaseManager.h" +#include "moses/FF/StatelessFeatureFunction.h" +#include "moses/FF/StatefulFeatureFunction.h" + +using namespace std; namespace Moses { +void BaseManager::OutputAllFeatureScores(const Moses::ScoreComponentCollection &features + , std::ostream &out) +{ + std::string lastName = ""; + const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions(); + for( size_t i=0; i<sff.size(); i++ ) { + const StatefulFeatureFunction *ff = sff[i]; + if (ff->GetScoreProducerDescription() != "BleuScoreFeature" + && ff->IsTuneable()) { + OutputFeatureScores( out, features, ff, lastName ); + } + } + const vector<const StatelessFeatureFunction*>& slf = StatelessFeatureFunction::GetStatelessFeatureFunctions(); + for( size_t i=0; i<slf.size(); i++ ) { + const StatelessFeatureFunction *ff = slf[i]; + if (ff->IsTuneable()) { + OutputFeatureScores( out, features, ff, lastName ); + } + } +} + +void BaseManager::OutputFeatureScores( std::ostream& out + , const ScoreComponentCollection &features + , const FeatureFunction *ff + , std::string &lastName ) +{ + const StaticData &staticData = StaticData::Instance(); + bool labeledOutput = staticData.IsLabeledNBestList(); + + // regular features (not sparse) + if (ff->GetNumScoreComponents() != 0) { + if( labeledOutput && lastName != ff->GetScoreProducerDescription() ) { + lastName = ff->GetScoreProducerDescription(); + out << " " << lastName << "="; + } + vector<float> scores = features.GetScoresForProducer( ff ); + for (size_t j = 0; j<scores.size(); ++j) { + out << " " << scores[j]; + } + } + + // sparse features + const FVector scores = features.GetVectorForProducer( ff ); + for(FVector::FNVmap::const_iterator i = scores.cbegin(); i != scores.cend(); i++) { + out << " " << i->first << "= " << i->second; + } +} } |