00001 #pragma once 00002 00003 #include "moses/Syntax/PHyperedge.h" 00004 #include "moses/Syntax/PVertex.h" 00005 #include "moses/Syntax/SHyperedgeBundle.h" 00006 00007 #include "SChart.h" 00008 00009 namespace Moses 00010 { 00011 namespace Syntax 00012 { 00013 namespace S2T 00014 { 00015 00016 // Given a PHyperedge object and SChart produces a SHyperedgeBundle object. 00017 inline void PHyperedgeToSHyperedgeBundle(const PHyperedge &hyperedge, 00018 const SChart &schart, 00019 SHyperedgeBundle &bundle) 00020 { 00021 bundle.translations = hyperedge.label.translations; 00022 bundle.stacks.clear(); 00023 for (std::vector<PVertex*>::const_iterator p = hyperedge.tail.begin(); 00024 p != hyperedge.tail.end(); ++p) { 00025 const PVertex *v = *p; 00026 std::size_t spanStart = v->span.GetStartPos(); 00027 std::size_t spanEnd = v->span.GetEndPos(); 00028 const Word &symbol = v->symbol; 00029 const SChart::Cell &cell = schart.GetCell(spanStart, spanEnd); 00030 const SVertexStack *stack = 0; 00031 if (symbol.IsNonTerminal()) { 00032 stack = cell.nonTerminalStacks.Find(symbol); 00033 } else { 00034 const SChart::Cell::TMap::const_iterator q = 00035 cell.terminalStacks.find(symbol); 00036 assert(q != cell.terminalStacks.end()); 00037 stack = &(q->second); 00038 } 00039 bundle.stacks.push_back(stack); 00040 } 00041 } 00042 00043 } // S2T 00044 } // Syntax 00045 } // Moses