Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Rule.h « phrase-extract.5 « training « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5c66ee67277d663bddb9deae73b383df7b1e73c (plain)
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
#pragma once
/*
 *  Rule.h
 *  extract
 *
 *  Created by Hieu Hoang on 19/07/2010.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */
#include <vector>
#include <iostream>
#include "LatticeNode.h"
#include "SymbolSequence.h"
#include "Global.h"

class Lattice;
class SentenceAlignment;
class Global;
class RuleCollection;
class SyntaxNode;
class TunnelCollection;

class RuleElement
{
protected:
	const LatticeNode *m_latticeNode;
public:
	size_t symbolPos[2];
	
	RuleElement(const RuleElement &copy);
	RuleElement(const LatticeNode &latticeNode, size_t sourcePos);

	const LatticeNode &GetLatticeNode() const
	{ return *m_latticeNode; }

};

class Rule
{
	friend std::ostream& operator<<(std::ostream &out, const Rule &obj);

protected:
	typedef std::vector<RuleElement> CollType;
	CollType m_coll;

	typedef std::vector<RuleElement*> CollTypeTarget;
	CollTypeTarget m_targetSorted;

	const SyntaxNode *m_lhsS, *m_lhsT;
	SymbolSequence m_source, m_target;
	
	void SortTargetLHS();
	bool IsHole(const TunnelCollection &holeColl) const;

	const LatticeNode &GetLatticeNode(size_t ind) const;
	void CreateSymbolsInterna();

public:
	// init
	Rule(const LatticeNode *latticeNode);

	// create new rule by appending node to prev rule
	Rule(const Rule &prevRule, const LatticeNode *latticeNode);

	// create copy with lhs
	Rule(const Rule &copy, const SyntaxNode *lhsS, const SyntaxNode *lhsT);

	// can continue to add to this rule
	bool CanRecurse(const Global &global, const TunnelCollection &holeColl) const;

	virtual ~Rule();

	// can add this to the set of rules
	bool IsValid(const Global &global, const TunnelCollection &holeColl) const;

	size_t GetNumSymbols() const;
	bool AdjacentDefaultNonTerms() const;
	bool MaxNonTerm(const Global &global) const;

	void CreateRules(RuleCollection &rules
									 , const Lattice &lattice
									 , const SentenceAlignment &sentence
									 , const Global &global);

	std::pair<size_t, size_t> GetSpan(size_t direction) const;
	
	int Compare(const Rule &compare) const;
	bool operator<(const Rule &compare) const;
	
	std::string ToString() const;
	
	void CreateSymbols();
	
	DEBUG_OUTPUT();
};