diff options
author | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-13 14:52:47 +0300 |
---|---|---|
committer | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-13 14:52:47 +0300 |
commit | e4eb201c52be74fee74399a6f35fcbe8eb85d834 (patch) | |
tree | 7792ef96d63262f6e28f1857741e1162c7dccbc4 /moses/ChartKBestExtractor.cpp | |
parent | cea2d9d8bb34a81660974cae20d66aefec4e0468 (diff) | |
parent | a0b6b6a341e74b47bbef4652ad7fd928cf91e17c (diff) |
merged master into dynamic-models and solved conflicts
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 8de77f139..cb1097c8a 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) |