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
00011 namespace Moses
00012 {
00013 namespace Syntax
00014 {
00015 namespace S2T
00016 {
00017
00018 class StandardParserCallback
00019 {
00020 private:
00021 typedef BoundedPriorityContainer<SHyperedgeBundle> Container;
00022
00023 public:
00024 StandardParserCallback(const SChart &schart, std::size_t ruleLimit)
00025 : m_schart(schart)
00026 , m_container(ruleLimit) {}
00027
00028 void operator()(const PHyperedge &hyperedge) {
00029 PHyperedgeToSHyperedgeBundle(hyperedge, m_schart, m_tmpBundle);
00030 float score = SHyperedgeBundleScorer::Score(m_tmpBundle);
00031 m_container.SwapIn(m_tmpBundle, score);
00032 }
00033
00034 void InitForRange(const Range &range) {
00035 m_container.LazyClear();
00036 }
00037
00038 const Container &GetContainer() {
00039 return m_container;
00040 }
00041
00042 private:
00043 const SChart &m_schart;
00044 SHyperedgeBundle m_tmpBundle;
00045 BoundedPriorityContainer<SHyperedgeBundle> m_container;
00046 };
00047
00048 class EagerParserCallback
00049 {
00050 private:
00051 typedef BoundedPriorityContainer<SHyperedgeBundle> Container;
00052
00053 public:
00054 EagerParserCallback(const SChart &schart, std::size_t ruleLimit)
00055 : m_schart(schart)
00056 , m_containers(schart.GetWidth(), Container(ruleLimit))
00057 , m_prevStart(std::numeric_limits<std::size_t>::max()) {}
00058
00059 void operator()(const PHyperedge &hyperedge, std::size_t end) {
00060 PHyperedgeToSHyperedgeBundle(hyperedge, m_schart, m_tmpBundle);
00061 float score = SHyperedgeBundleScorer::Score(m_tmpBundle);
00062 m_containers[end].SwapIn(m_tmpBundle, score);
00063 }
00064
00065 void InitForRange(const Range &range) {
00066 const std::size_t start = range.GetStartPos();
00067 m_end = range.GetEndPos();
00068 if (start != m_prevStart) {
00069 for (std::vector<Container>::iterator p = m_containers.begin();
00070 p != m_containers.end(); ++p) {
00071 p->LazyClear();
00072 }
00073 m_prevStart = start;
00074 }
00075 }
00076
00077 const Container &GetContainer() {
00078 return m_containers[m_end];
00079 }
00080
00081 private:
00082 const SChart &m_schart;
00083 SHyperedgeBundle m_tmpBundle;
00084 std::vector<Container> m_containers;
00085 std::size_t m_end;
00086 std::size_t m_prevStart;
00087 };
00088
00089 }
00090 }
00091 }