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
|
#include "InternalStructFeature.h"
using namespace std;
namespace MosesTraining
{
InternalStructFeature::InternalStructFeature()
:m_type(0){
//cout<<"InternalStructFeature: Construct "<<m_type<<"\n";
}
bool InternalStructFeature::equals(const PhraseAlignment& lhs, const PhraseAlignment& rhs) const{
//cout<<"InternalStructFeature: Equals\n";
//don't know what it's used for and what we should compare
//-> if the dense score is the same
//-> if the sparse feature is set
// compare phrases? with the internalStrucutre string?
/** Return true if the two phrase pairs are equal from the point of this feature. Assume
that they already compare true according to PhraseAlignment.equals()
**/
/* if(lhs.ghkmParse==rhs.ghkmParse)
return true;
else
return false;
*/
//return true;
}
void InternalStructFeature::add(const ScoreFeatureContext& context,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const{
for(size_t i=0; i<context.phrasePair.size(); i++) {
add(&context.phrasePair[i]->ghkmParse, denseValues, sparseValues);
}
}
void InternalStructFeatureDense::add(std::string *internalStruct,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const{
//cout<<"Dense: "<<*internalStruct<<endl;
size_t start=0;
int countNP=0;
while((start = internalStruct->find("NP", start)) != string::npos) {
countNP++;
start+=2; //length of "NP"
}
//should add e^countNP so in the decoder I get log(e^countNP)=countNP -> but is log or ln?
//should use this but don't know what it does? -> maybeLog( (bitmap == i) ? 2.718 : 1 )
denseValues.push_back(exp(countNP));
}
void InternalStructFeatureSparse::add(std::string *internalStruct,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const{
//cout<<"Sparse: "<<*internalStruct<<endl;
if(internalStruct->find("VBZ")!=std::string::npos)
sparseValues["NTVBZ"] = 1;
if(internalStruct->find("VBD")!=std::string::npos)
sparseValues["NTVBD"] = 1;
if(internalStruct->find("VBP")!=std::string::npos)
sparseValues["NTVBP"] = 1;
if(internalStruct->find("PP")!=std::string::npos)
sparseValues["NTPP"] = 1;
if(internalStruct->find("SBAR")!=std::string::npos)
sparseValues["NTSBAR"] = 1;
}
}
|