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

PhraseDictionaryTreeAdaptor.cpp « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ef98d6ad4e62dfcb941703f5441ad2872b1b171 (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
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
// $Id$

#include "PhraseDictionaryTreeAdaptor.h"
#include <sys/stat.h>
#include <algorithm>
#include "PhraseDictionaryTree.h"
#include "Phrase.h"
#include "FactorCollection.h"
#include "InputFileStream.h"
#include "InputType.h"
#include "ConfusionNet.h"
#include "Sentence.h"
#include "StaticData.h"
#include "UniqueObject.h"
#include "PDTAimp.h"
#include "UserMessage.h"

/*************************************************************
	function definitions of the interface class
	virtually everything is forwarded to the implementation class
*************************************************************/

PhraseDictionaryTreeAdaptor::
PhraseDictionaryTreeAdaptor(size_t numScoreComponent,unsigned numInputScores)
	: MyBase(numScoreComponent),imp(new PDTAimp(this,numInputScores)) {}

PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor() 
{
	imp->CleanUp();
	delete imp;
}

void PhraseDictionaryTreeAdaptor::CleanUp() 
{
	imp->CleanUp();
	MyBase::CleanUp();
}

void PhraseDictionaryTreeAdaptor::InitializeForInput(InputType const& source)
{
	// caching only required for confusion net
	if(ConfusionNet const* cn=dynamic_cast<ConfusionNet const*>(&source))
		imp->CacheSource(*cn);
	//else if(Sentence const* s=dynamic_cast<Sentence const*>(&source))
	// following removed by phi, not helpful
	//	imp->CacheSource(ConfusionNet(*s));
}

bool PhraseDictionaryTreeAdaptor::Load(const std::vector<FactorType> &input
																				 , const std::vector<FactorType> &output
																				 , const std::string &filePath
																				 , const std::vector<float> &weight
																				 , size_t tableLimit
																				 , const LMList &languageModels
																				 , float weightWP
																				 )
{
	FactorCollection &factorCollection = FactorCollection::Instance();

	if(m_numScoreComponent!=weight.size()) {
		stringstream strme;
		strme << "ERROR: mismatch of number of scaling factors: "<<weight.size()
						 <<" "<<m_numScoreComponent<<"\n";
		UserMessage::Add(strme.str());
		return false;
	}
	m_filePath = filePath;

	// set Dictionary members
	m_inputFactors = FactorMask(input);
	m_outputFactors = FactorMask(output);
	VERBOSE(2,"PhraseDictionaryTreeAdaptor: input=" << m_inputFactors << "  output=" << m_outputFactors << std::endl);

	// set PhraseDictionary members
	m_tableLimit=tableLimit;

	imp->Create(input,output,filePath,
							weight,languageModels,weightWP);
	return true;
}

TargetPhraseCollection const* 
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(Phrase const &src) const
{
	return imp->GetTargetPhraseCollection(src);
}
TargetPhraseCollection const* 
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(InputType const& src,WordsRange const &range) const
{
	if(imp->m_rangeCache.empty())
	{
		return imp->GetTargetPhraseCollection(src.GetSubString(range));
	}
	else
	{
		return imp->m_rangeCache[range.GetStartPos()][range.GetEndPos()];
	}
}

void PhraseDictionaryTreeAdaptor::
SetWeightTransModel(const std::vector<float> &weightT)
{
	CleanUp();
	imp->m_weights=weightT;
}

void PhraseDictionaryTreeAdaptor::
AddEquivPhrase(const Phrase &source, const TargetPhrase &targetPhrase) 
{
	imp->AddEquivPhrase(source,targetPhrase);
}
void PhraseDictionaryTreeAdaptor::EnableCache()
{
	imp->useCache=1;
}
void PhraseDictionaryTreeAdaptor::DisableCache()
{
	imp->useCache=0;
}



size_t PhraseDictionaryTreeAdaptor::GetNumInputScores() const {
	return imp->GetNumInputScores();
}

std::string PhraseDictionaryTreeAdaptor::GetScoreProducerDescription() const
{
	return "Translation score, file=" + m_filePath;
}