/* * Rules.h * * Created on: 20 Feb 2014 * Author: hieu */ #pragma once #include #include #include "ConsistentPhrases.h" #include "Rule.h" extern bool g_debug; class AlignedSentence; class Parameter; struct CompareRules { bool operator()(const Rule *a, const Rule *b) { int compare; compare = a->GetPhrase(Moses::Input).Compare(b->GetPhrase(Moses::Input)); if (compare) return compare < 0; compare = a->GetPhrase(Moses::Output).Compare(b->GetPhrase(Moses::Output)); if (compare) return compare < 0; if (a->GetAlignments() != b->GetAlignments()) { return a->GetAlignments() < b->GetAlignments(); } if (a->GetLHS().GetString() != b->GetLHS().GetString()) { return a->GetLHS().GetString() < b->GetLHS().GetString(); } if (a->GetProperties() != b->GetProperties()) { return a->GetProperties() < b->GetProperties(); } return false; } }; class Rules { public: Rules(const AlignedSentence &alignedSentence); virtual ~Rules(); void Extend(const Parameter ¶ms); void Consolidate(const Parameter ¶ms); std::string Debug() const; void Output(std::ostream &out, bool forward, const Parameter ¶ms) const; protected: const AlignedSentence &m_alignedSentence; std::set m_keepRules; std::set m_mergeRules; void Extend(const Rule &rule, const Parameter ¶ms); void Extend(const Rule &rule, const ConsistentPhrases::Coll &cps, const Parameter ¶ms); void Extend(const Rule &rule, const ConsistentPhrase &cp, const Parameter ¶ms); // create original rules void CreateRules(const ConsistentPhrase &cp, const Parameter ¶ms); void CreateRule(const NonTerm &nonTerm, const Parameter ¶ms); void MergeRules(const Parameter ¶ms); void CalcFractionalCount(); };