|
#pragma once |
|
|
|
#include "moses/Syntax/PHyperedge.h" |
|
|
|
#include "Forest.h" |
|
#include "HyperTree.h" |
|
#include "RuleMatcher.h" |
|
|
|
namespace Moses |
|
{ |
|
namespace Syntax |
|
{ |
|
namespace F2S |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Callback> |
|
class RuleMatcherHyperTree : public RuleMatcher<Callback> |
|
{ |
|
public: |
|
RuleMatcherHyperTree(const HyperTree &); |
|
|
|
~RuleMatcherHyperTree() {} |
|
|
|
void EnumerateHyperedges(const Forest::Vertex &, Callback &); |
|
|
|
private: |
|
|
|
typedef std::vector<const Forest::Vertex *> FNS; |
|
|
|
|
|
|
|
struct AnnotatedFNS { |
|
FNS fns; |
|
std::vector<const Forest::Hyperedge *> fragment; |
|
}; |
|
|
|
|
|
|
|
|
|
struct MatchItem { |
|
AnnotatedFNS annotatedFNS; |
|
const HyperTree::Node *trieNode; |
|
}; |
|
|
|
|
|
|
|
|
|
void CartesianProduct(const std::vector<AnnotatedFNS> &, |
|
const std::vector<AnnotatedFNS> &, |
|
std::vector<AnnotatedFNS> &); |
|
|
|
int CountCommas(const HyperPath::NodeSeq &); |
|
|
|
bool MatchChildren(const std::vector<Forest::Vertex *> &, |
|
const HyperPath::NodeSeq &, std::size_t, std::size_t); |
|
|
|
void PropagateNextLexel(const MatchItem &); |
|
|
|
int SubSeqLength(const HyperPath::NodeSeq &, int); |
|
|
|
const HyperTree &m_ruleTrie; |
|
PHyperedge m_hyperedge; |
|
std::queue<MatchItem> m_queue; |
|
}; |
|
|
|
} |
|
} |
|
} |
|
|
|
|
|
#include "RuleMatcherHyperTree-inl.h" |
|
|