diff options
author | Rico Sennrich <rico.sennrich@gmx.ch> | 2014-09-12 21:04:46 +0400 |
---|---|---|
committer | Rico Sennrich <rico.sennrich@gmx.ch> | 2014-09-12 21:17:23 +0400 |
commit | 61c00ed636ea49b7d23239bcaafb1723ae3b0bf9 (patch) | |
tree | b289d3828d61906845bcfb145c65ab441f4a4149 /moses/ChartKBestExtractor.cpp | |
parent | 0a127cb0f1d9655a8ba3637ed2abd2d4e04c1ef1 (diff) |
n-best tree output
Diffstat (limited to 'moses/ChartKBestExtractor.cpp')
-rw-r--r-- | moses/ChartKBestExtractor.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/moses/ChartKBestExtractor.cpp b/moses/ChartKBestExtractor.cpp index 014c8f2b9..e916ba7db 100644 --- a/moses/ChartKBestExtractor.cpp +++ b/moses/ChartKBestExtractor.cpp @@ -124,6 +124,35 @@ Phrase ChartKBestExtractor::GetOutputPhrase(const Derivation &d) return ret; } +// Generate the target tree of the derivation d. +TreePointer ChartKBestExtractor::GetOutputTree(const Derivation &d) +{ + const ChartHypothesis &hypo = d.edge.head->hypothesis; + const TargetPhrase &phrase = hypo.GetCurrTargetPhrase(); + if (const PhraseProperty *property = phrase.GetProperty("Tree")) { + const std::string *tree = property->GetValueString(); + TreePointer mytree (boost::make_shared<InternalTree>(*tree)); + + //get subtrees (in target order) + std::vector<TreePointer> previous_trees; + for (size_t pos = 0; pos < phrase.GetSize(); ++pos) { + const Word &word = phrase.GetWord(pos); + if (word.IsNonTerminal()) { + size_t nonTermInd = phrase.GetAlignNonTerm().GetNonTermIndexMap()[pos]; + const Derivation &subderivation = *d.subderivations[nonTermInd]; + const TreePointer prev_tree = GetOutputTree(subderivation); + previous_trees.push_back(prev_tree); + } + } + + mytree->Combine(previous_trees); + return mytree; + } + else { + UTIL_THROW2("Error: TreeStructureFeature active, but no internal tree structure found"); + } +} + // Create an unweighted hyperarc corresponding to the given ChartHypothesis. ChartKBestExtractor::UnweightedHyperarc ChartKBestExtractor::CreateEdge( const ChartHypothesis &h) |