00001 #pragma once 00002 00003 #include <memory> 00004 #include <vector> 00005 00006 #include "moses/Syntax/S2T/Parsers/Parser.h" 00007 #include "moses/Syntax/S2T/RuleTrieScope3.h" 00008 #include "moses/Range.h" 00009 00010 #include "PatternApplicationTrie.h" 00011 #include "SymbolRangeCalculator.h" 00012 #include "TailLattice.h" 00013 #include "TailLatticeBuilder.h" 00014 00015 namespace Moses 00016 { 00017 namespace Syntax 00018 { 00019 namespace S2T 00020 { 00021 00022 // Parser that implements the algorithm described in this paper: 00023 // 00024 // Philip Williams and Philipp Koehn 00025 // "GHKM Rule Extraction and Scope-3 Parsing in Moses" 00026 // In proceedings of WMT 2012 00027 // 00028 template<typename Callback> 00029 class Scope3Parser : public Parser<Callback> 00030 { 00031 public: 00032 typedef Parser<Callback> Base; 00033 typedef RuleTrieScope3 RuleTrie; 00034 00035 // TODO Make this configurable? 00036 static bool RequiresCompressedChart() { 00037 return false; 00038 } 00039 00040 Scope3Parser(PChart &, const RuleTrie &, std::size_t); 00041 00042 ~Scope3Parser(); 00043 00044 void EnumerateHyperedges(const Range &, Callback &); 00045 00046 private: 00047 void Init(); 00048 void InitRuleApplicationVector(); 00049 void FillSentenceMap(SentenceMap &); 00050 void RecordPatternApplicationSpans(const PatternApplicationTrie &); 00051 00052 PatternApplicationTrie *m_patRoot; 00053 std::vector<std::vector<bool> > m_quickCheckTable; 00054 const RuleTrie &m_ruleTable; 00055 const std::size_t m_maxChartSpan; 00056 TailLattice m_lattice; 00057 TailLatticeBuilder m_latticeBuilder; 00058 SymbolRangeCalculator m_symbolRangeCalculator; 00059 std::vector<SymbolRange> m_symbolRanges; 00060 PatternApplicationKey m_patKey; 00061 00062 /* m_patSpans[i][j] records the set of all PAT nodes for span [i,i+j] 00063 i.e. j is the width of the span */ 00064 std::vector<std::vector< 00065 std::vector<const PatternApplicationTrie *> > > m_patSpans; 00066 }; 00067 00068 } // namespace S2T 00069 } // namespace Syntax 00070 } // namespace Moses 00071 00072 // Implementation 00073 #include "Parser-inl.h"