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
|
#include "InputPath.h"
#include "ScoreComponentCollection.h"
#include "TargetPhraseCollection.h"
#include "StaticData.h"
#include "TypeDef.h"
#include "AlignmentInfo.h"
#include "util/exception.hh"
#include "TranslationModel/PhraseDictionary.h"
using namespace std;
namespace Moses
{
InputPath::
InputPath(ttaskwptr const theTask,
Phrase const& phrase,
NonTerminalSet const& sourceNonTerms,
WordsRange const& range, InputPath const *prevNode,
const ScorePair *inputScore)
: ttask(theTask)
, m_prevPath(prevNode)
, m_phrase(phrase)
, m_range(range)
, m_inputScore(inputScore)
, m_nextNode(1)
, m_sourceNonTerms(sourceNonTerms)
, m_sourceNonTermArray(FactorCollection::Instance().GetNumNonTerminals(), false)
{
for (NonTerminalSet::const_iterator iter = sourceNonTerms.begin(); iter != sourceNonTerms.end(); ++iter) {
size_t idx = (*iter)[0]->GetId();
m_sourceNonTermArray[idx] = true;
}
//cerr << "phrase=" << phrase << " m_inputScore=" << *m_inputScore << endl;
}
InputPath::~InputPath()
{
// std::cerr << "Deconstructing InputPath" << std::endl;
// // NOT NEEDED ANY MORE SINCE THE SWITCH TO SHARED POINTERS
// // Since there is no way for the Phrase Dictionaries to tell in
// // which (sentence) context phrases were looked up, we tell them
// // now that the phrase isn't needed any more by this inputPath
// typedef std::pair<boost::shared_ptr<TargetPhraseCollection>, const void* > entry;
// std::map<const PhraseDictionary*, entry>::iterator iter;
// ttasksptr theTask = this->ttask.lock();
// for (iter = m_targetPhrases.begin(); iter != m_targetPhrases.end(); ++iter)
// {
// // std::cerr << iter->second.first << " decommissioned." << std::endl;
// iter->first->Release(theTask, iter->second.first);
// }
delete m_inputScore;
}
TargetPhraseCollection::shared_ptr
InputPath::
GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
{
TargetPhrases::const_iterator iter;
iter = m_targetPhrases.find(&phraseDictionary);
if (iter == m_targetPhrases.end()) {
return TargetPhraseCollection::shared_ptr();
}
return iter->second.first;
}
const void*
InputPath::
GetPtNode(const PhraseDictionary &phraseDictionary) const
{
TargetPhrases::const_iterator iter;
iter = m_targetPhrases.find(&phraseDictionary);
if (iter == m_targetPhrases.end()) {
return NULL;
}
return iter->second.second;
}
void
InputPath::
SetTargetPhrases(const PhraseDictionary &phraseDictionary,
TargetPhraseCollection::shared_ptr const& targetPhrases,
const void *ptNode)
{
std::pair<TargetPhraseCollection::shared_ptr, const void*>
value(targetPhrases, ptNode);
m_targetPhrases[&phraseDictionary] = value;
}
const Word &InputPath::GetLastWord() const
{
size_t len = m_phrase.GetSize();
UTIL_THROW_IF2(len == 0, "Input path phrase cannot be empty");
const Word &ret = m_phrase.GetWord(len - 1);
return ret;
}
size_t InputPath::GetTotalRuleSize() const
{
size_t ret = 0;
TargetPhrases::const_iterator iter;
for (iter = m_targetPhrases.begin(); iter != m_targetPhrases.end(); ++iter) {
// const PhraseDictionary *pt = iter->first;
TargetPhraseCollection::shared_ptr tpColl = iter->second.first;
if (tpColl) {
ret += tpColl->GetSize();
}
}
return ret;
}
std::ostream& operator<<(std::ostream& out, const InputPath& obj)
{
out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevPath() << " " << obj.GetPhrase();
InputPath::TargetPhrases::const_iterator iter;
for (iter = obj.m_targetPhrases.begin(); iter != obj.m_targetPhrases.end(); ++iter) {
const PhraseDictionary *pt = iter->first;
boost::shared_ptr<TargetPhraseCollection const> tpColl = iter->second.first;
out << pt << "=";
if (tpColl) {
cerr << tpColl->GetSize() << " ";
} else {
cerr << "NULL ";
}
}
return out;
}
}
|