00001 #pragma once
00002
00003 #include "moses/Syntax/PHyperedge.h"
00004
00005 #include "Forest.h"
00006 #include "HyperTree.h"
00007 #include "RuleMatcher.h"
00008
00009 namespace Moses
00010 {
00011 namespace Syntax
00012 {
00013 namespace F2S
00014 {
00015
00016
00017
00018
00019
00020
00021
00022
00023 template<typename Callback>
00024 class RuleMatcherHyperTree : public RuleMatcher<Callback>
00025 {
00026 public:
00027 RuleMatcherHyperTree(const HyperTree &);
00028
00029 ~RuleMatcherHyperTree() {}
00030
00031 void EnumerateHyperedges(const Forest::Vertex &, Callback &);
00032
00033 private:
00034
00035 typedef std::vector<const Forest::Vertex *> FNS;
00036
00037
00038
00039 struct AnnotatedFNS {
00040 FNS fns;
00041 std::vector<const Forest::Hyperedge *> fragment;
00042 };
00043
00044
00045
00046
00047 struct MatchItem {
00048 AnnotatedFNS annotatedFNS;
00049 const HyperTree::Node *trieNode;
00050 };
00051
00052
00053
00054
00055 void CartesianProduct(const std::vector<AnnotatedFNS> &,
00056 const std::vector<AnnotatedFNS> &,
00057 std::vector<AnnotatedFNS> &);
00058
00059 int CountCommas(const HyperPath::NodeSeq &);
00060
00061 bool MatchChildren(const std::vector<Forest::Vertex *> &,
00062 const HyperPath::NodeSeq &, std::size_t, std::size_t);
00063
00064 void PropagateNextLexel(const MatchItem &);
00065
00066 int SubSeqLength(const HyperPath::NodeSeq &, int);
00067
00068 const HyperTree &m_ruleTrie;
00069 PHyperedge m_hyperedge;
00070 std::queue<MatchItem> m_queue;
00071 };
00072
00073 }
00074 }
00075 }
00076
00077
00078 #include "RuleMatcherHyperTree-inl.h"