File size: 2,484 Bytes
158b61b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
/*
* Rule.h
*
* Created on: 20 Feb 2014
* Author: hieu
*/
#pragma once
#include <vector>
#include "Phrase.h"
#include "RulePhrase.h"
#include "Property.h"
#include "moses/TypeDef.h"
class ConsistentPhrase;
class AlignedSentence;
class NonTerm;
class Parameter;
class Rule
{
public:
typedef std::set<std::pair<int,int> > Alignments;
typedef std::vector<Property> Properties;
Rule(const Rule ©); // do not implement
// original rule with no non-term
Rule(const NonTerm &lhsNonTerm, const AlignedSentence &alignedSentence);
// extend a rule, adding 1 new non-term
Rule(const Rule ©, const NonTerm &nonTerm);
virtual ~Rule();
bool IsValid() const {
return m_isValid;
}
bool CanRecurse() const {
return m_canRecurse;
}
const NonTerm &GetLHS() const {
return m_lhs;
}
const ConsistentPhrase &GetConsistentPhrase() const;
int GetNextSourcePosForNonTerm() const;
void SetCount(float count) {
m_count = count;
}
float GetCount() const {
return m_count;
}
const Alignments &GetAlignments() const {
return m_alignments;
}
const Properties &GetProperties() const {
return m_properties;
}
std::string Debug() const;
void Output(std::ostream &out, bool forward) const;
void Prevalidate(const Parameter ¶ms);
void CreateTarget(const Parameter ¶ms);
void CreateProperties(const Parameter ¶ms);
const RulePhrase &GetPhrase(Moses::FactorDirection direction) const {
return (direction == Moses::Input) ? m_source : m_target;
}
protected:
const NonTerm &m_lhs;
const AlignedSentence &m_alignedSentence;
RulePhrase m_source, m_target;
float m_count;
Alignments m_alignments;
// in source order
std::vector<const NonTerm*> m_nonterms;
bool m_isValid, m_canRecurse;
// should be in consistent order, for comparisons
Properties m_properties;
void CreateSource();
void CreateAlignments();
void CreateAlignments(int sourcePos, const std::set<const Word *> &targetWords);
void CreateAlignments(int sourcePos, const RuleSymbol *targetSought);
bool ContainTerm(const ConsistentPhrase &cp, const std::set<const Word*> &terms) const;
int GetScope(const Parameter ¶ms) const;
void NonTermContext(int sourceTarget, int factors, size_t ntInd, const ConsistentPhrase &cp, std::ostream &out) const;
// sourceTarget: 1 = source, 2 = target
void NonTermContextFactor(int factor, const Word &word, std::ostream &out) const;
};
|