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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// $Id$
#ifndef _DOMAIN_H
#define _DOMAIN_H
#include <iostream>
#include <fstream>
#include <assert.h>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include "ScoreFeature.h"
extern std::vector<std::string> tokenize( const char*);
namespace MosesTraining
{
class Domain
{
public:
std::vector< std::pair< int, std::string > > spec;
std::vector< std::string > list;
std::map< std::string, int > name2id;
void load( const std::string &fileName );
std::string getDomainOfSentence( int sentenceId ) const;
};
class DomainFeature : public ScoreFeature
{
public:
DomainFeature(const std::string& domainFile);
bool equals(const PhraseAlignment& lhs, const PhraseAlignment& rhs) const;
void add(const ScoreFeatureContext& context,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
protected:
/** Overriden in subclass */
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const = 0;
Domain m_domain;
};
class SubsetDomainFeature : public DomainFeature
{
public:
SubsetDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseSubsetDomainFeature : public DomainFeature
{
public:
SparseSubsetDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class IndicatorDomainFeature : public DomainFeature
{
public:
IndicatorDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseIndicatorDomainFeature : public DomainFeature
{
public:
SparseIndicatorDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class RatioDomainFeature : public DomainFeature
{
public:
RatioDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseRatioDomainFeature : public DomainFeature
{
public:
SparseRatioDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
}
#endif
|