diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 22:09:10 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-12-02 22:09:10 +0300 |
commit | 3da84150959de4dc99edf3ee35665e81a23aae26 (patch) | |
tree | ee7c487a26f2d56f56763dd5fe8885f6d6130465 /moses/BaseManager.cpp | |
parent | ba7afba9f6f325441387557ab8af487d5901f023 (diff) |
add OutputNBest() as abstract method to BaseManager. Tighten up framework
Diffstat (limited to 'moses/BaseManager.cpp')
-rw-r--r-- | moses/BaseManager.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp index 17bcf9627..485cdd182 100644 --- a/moses/BaseManager.cpp +++ b/moses/BaseManager.cpp @@ -9,8 +9,8 @@ using namespace std; namespace Moses { -void BaseManager::OutputAllFeatureScores(const Moses::ScoreComponentCollection &features - , std::ostream &out) +void BaseManager::OutputAllFeatureScores(const Moses::ScoreComponentCollection &features, + std::ostream &out) const { std::string lastName = ""; const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions(); @@ -30,10 +30,10 @@ void BaseManager::OutputAllFeatureScores(const Moses::ScoreComponentCollection & } } -void BaseManager::OutputFeatureScores( std::ostream& out - , const ScoreComponentCollection &features - , const FeatureFunction *ff - , std::string &lastName ) +void BaseManager::OutputFeatureScores( std::ostream& out, + const ScoreComponentCollection &features, + const FeatureFunction *ff, + std::string &lastName ) const { const StaticData &staticData = StaticData::Instance(); bool labeledOutput = staticData.IsLabeledNBestList(); @@ -57,6 +57,37 @@ void BaseManager::OutputFeatureScores( std::ostream& out } } +/*** + * print surface factor only for the given phrase + */ +void BaseManager::OutputSurface(std::ostream &out, const Phrase &phrase, + const std::vector<FactorType> &outputFactorOrder, + bool reportAllFactors) const +{ + UTIL_THROW_IF2(outputFactorOrder.size() == 0, + "Cannot be empty phrase"); + if (reportAllFactors == true) { + out << phrase; + } else { + size_t size = phrase.GetSize(); + for (size_t pos = 0 ; pos < size ; pos++) { + const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]); + out << *factor; + UTIL_THROW_IF2(factor == NULL, + "Empty factor 0 at position " << pos); + + for (size_t i = 1 ; i < outputFactorOrder.size() ; i++) { + const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[i]); + UTIL_THROW_IF2(factor == NULL, + "Empty factor " << i << " at position " << pos); + + out << "|" << *factor; + } + out << " "; + } + } } +} // namespace + |