#pragma once #include #include #include #include "util/string_piece.hh" namespace Moses { namespace ScoreStsg { // A group of rules that share the same source-side. Rules are added through // calls to SetNewSource() and AddRule(). They can then be accessed via the // iterators. // // It is assumed that rules with the same (target, ntAlign, alignment) value // will be added consecutively, and so will rules with the same // (target, ntAlign) value. In other words, it is assumed that rules will be // added in the order they occur in a correctly-sorted extract file. class RuleGroup { public: // Stores the target-side and NT-alignment of a distinct rule. Also records // the rule's count and the observed symbol alignments (plus their // frequencies). struct DistinctRule { std::string target; std::string ntAlign; std::vector > alignments; int count; }; typedef std::vector::const_iterator ConstIterator; // Begin and End iterators for iterating over the group's distinct rules. ConstIterator Begin() const { return m_distinctRules.begin(); } ConstIterator End() const { return m_distinctRules.end(); } // Get the current source-side value. const std::string &GetSource() const { return m_source; } // Get the number of distinct rules. int GetSize() const { return m_distinctRules.size(); } // Get the total count. int GetTotalCount() const { return m_totalCount; } // Clear the rule group and set a new source-side value. This must be // done once for every new source-side value, prior to the first call to // AddRule(). void SetNewSource(const StringPiece &source); // Add a rule. To determine rule distinctness, the target and ntAlign // values will be checked against those of the previous rule only (in other // words, the input is assumed to be ordered). void AddRule(const StringPiece &target, const StringPiece &ntAlign, const StringPiece &fullAlign, int count); private: std::string m_source; std::vector m_distinctRules; int m_totalCount; }; } // namespace ScoreStsg } // namespace Moses