blob: fa2747c82c7900ed5b71b7b9bc51890fd6aab4c5 (
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
96
97
98
99
100
101
102
103
104
105
106
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
#pragma once
#include <string>
#include <vector>
#include <boost/scoped_ptr.hpp>
#include "moses/Factor.h"
#include "moses/Phrase.h"
#include "moses/TypeDef.h"
#include "moses/Util.h"
#include "moses/Range.h"
#include "moses/TranslationOption.h"
#include "moses/FF/StatefulFeatureFunction.h"
#include "util/exception.hh"
#include "LexicalReorderingState.h"
#include "LexicalReorderingTable.h"
#include "SparseReordering.h"
namespace Moses
{
class Factor;
class Phrase;
class Hypothesis;
class InputType;
// implementation of lexical reordering (Tilman ...) for phrase-based
// decoding
class LexicalReordering : public StatefulFeatureFunction
{
public:
LexicalReordering(const std::string &line);
virtual ~LexicalReordering();
void Load();
virtual
bool
IsUseable(const FactorMask &mask) const;
virtual
FFState const*
EmptyHypothesisState(const InputType &input) const;
void
InitializeForInput(ttasksptr const& ttask) {
if (m_table) m_table->InitializeForInput(ttask);
}
Scores
GetProb(const Phrase& f, const Phrase& e) const;
virtual
FFState*
EvaluateWhenApplied(const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const;
virtual
FFState*
EvaluateWhenApplied(const ChartHypothesis&, int featureID,
ScoreComponentCollection*) const {
UTIL_THROW2("LexicalReordering is not valid for chart decoder");
}
bool
GetHaveDefaultScores() {
return m_haveDefaultScores;
}
float
GetDefaultScore( size_t i ) {
return m_defaultScores[i];
}
virtual
void
SetCache(TranslationOption& to) const;
virtual
void
SetCache(TranslationOptionList& tol) const;
private:
bool DecodeCondition(std::string s);
bool DecodeDirection(std::string s);
bool DecodeNumFeatureFunctions(std::string s);
boost::scoped_ptr<LRModel> m_configuration;
std::string m_modelTypeString;
std::vector<std::string> m_modelType;
boost::scoped_ptr<LexicalReorderingTable> m_table;
std::vector<LRModel::Condition> m_condition;
std::vector<FactorType> m_factorsE, m_factorsF;
std::string m_filePath;
bool m_haveDefaultScores;
Scores m_defaultScores;
public:
LRModel const& GetModel() const;
};
}
|