00001 #pragma once 00002 00003 #include "moses/Syntax/BoundedPriorityContainer.h" 00004 #include "moses/Syntax/PHyperedge.h" 00005 #include "moses/Syntax/PVertex.h" 00006 #include "moses/Syntax/SHyperedgeBundle.h" 00007 #include "moses/Syntax/SHyperedgeBundleScorer.h" 00008 00009 #include "PHyperedgeToSHyperedgeBundle.h" 00010 #include "PVertexToStackMap.h" 00011 00012 namespace Moses 00013 { 00014 namespace Syntax 00015 { 00016 namespace F2S 00017 { 00018 00019 class RuleMatcherCallback 00020 { 00021 private: 00022 typedef BoundedPriorityContainer<SHyperedgeBundle> Container; 00023 00024 public: 00025 RuleMatcherCallback(const PVertexToStackMap &stackMap, std::size_t ruleLimit) 00026 : m_stackMap(stackMap) 00027 , m_container(ruleLimit) {} 00028 00029 void operator()(const PHyperedge &hyperedge) { 00030 PHyperedgeToSHyperedgeBundle(hyperedge, m_stackMap, m_tmpBundle); 00031 float score = SHyperedgeBundleScorer::Score(m_tmpBundle); 00032 m_container.SwapIn(m_tmpBundle, score); 00033 } 00034 00035 void ClearContainer() { 00036 m_container.LazyClear(); 00037 } 00038 00039 const Container &GetContainer() { 00040 return m_container; 00041 } 00042 00043 private: 00044 const PVertexToStackMap &m_stackMap; 00045 SHyperedgeBundle m_tmpBundle; 00046 BoundedPriorityContainer<SHyperedgeBundle> m_container; 00047 }; 00048 00049 } // F2S 00050 } // Syntax 00051 } // Moses