00001 #include "SHyperedge.h" 00002 00003 #include "moses/StaticData.h" 00004 00005 #include "SVertex.h" 00006 00007 namespace Moses 00008 { 00009 namespace Syntax 00010 { 00011 00012 Phrase GetOneBestTargetYield(const SHyperedge &h) 00013 { 00014 FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor; 00015 00016 Phrase ret(ARRAY_SIZE_INCR); 00017 00018 const AlignmentInfo::NonTermIndexMap &targetToSourceMap = 00019 h.label.translation->GetAlignNonTerm().GetNonTermIndexMap2(); 00020 00021 for (std::size_t pos = 0; pos < h.label.translation->GetSize(); ++pos) { 00022 const Word &word = h.label.translation->GetWord(pos); 00023 if (word.IsNonTerminal()) { 00024 std::size_t sourceIndex = targetToSourceMap[pos]; 00025 const SHyperedge &incoming = *h.tail[sourceIndex]->best; 00026 Phrase subPhrase = GetOneBestTargetYield(incoming); 00027 ret.Append(subPhrase); 00028 } else { 00029 ret.AddWord(word); 00030 if (placeholderFactor == NOT_FOUND) { 00031 continue; 00032 } 00033 assert(false); 00034 // FIXME Modify this chunk of code to work for SHyperedge. 00035 /* 00036 std::set<std::size_t> sourcePosSet = 00037 h.translation->GetAlignTerm().GetAlignmentsForTarget(pos); 00038 if (sourcePosSet.size() == 1) { 00039 const std::vector<const Word*> *ruleSourceFromInputPath = 00040 hypo.GetTranslationOption().GetSourceRuleFromInputPath(); 00041 UTIL_THROW_IF2(ruleSourceFromInputPath == NULL, 00042 "Source Words in of the rules hasn't been filled out"); 00043 std::size_t sourcePos = *sourcePosSet.begin(); 00044 const Word *sourceWord = ruleSourceFromInputPath->at(sourcePos); 00045 UTIL_THROW_IF2(sourceWord == NULL, 00046 "Null source word at position " << sourcePos); 00047 const Factor *factor = sourceWord->GetFactor(placeholderFactor); 00048 if (factor) { 00049 ret.Back()[0] = factor; 00050 } 00051 } 00052 */ 00053 } 00054 } 00055 return ret; 00056 } 00057 00058 } // Syntax 00059 } // Moses