2013-09-12 20:46:40 +04:00
|
|
|
#include "InternalStructFeature.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace MosesTraining
|
|
|
|
{
|
|
|
|
|
|
|
|
InternalStructFeature::InternalStructFeature()
|
|
|
|
:m_type(0){
|
2013-09-13 14:45:46 +04:00
|
|
|
//cout<<"InternalStructFeature: Construct "<<m_type<<"\n";
|
2013-09-12 20:46:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
**/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalStructFeature::add(const ScoreFeatureContext& context,
|
|
|
|
std::vector<float>& denseValues,
|
|
|
|
std::map<std::string,float>& sparseValues) const{
|
2013-09-13 14:45:46 +04:00
|
|
|
for(size_t i=0; i<context.phrasePair.size(); i++) {
|
|
|
|
add(&context.phrasePair[i]->ghkmParse, denseValues, sparseValues);
|
|
|
|
}
|
|
|
|
|
2013-09-12 20:46:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InternalStructFeatureDense::add(std::string *internalStruct,
|
|
|
|
std::vector<float>& denseValues,
|
|
|
|
std::map<std::string,float>& sparseValues) const{
|
2013-09-13 14:45:46 +04:00
|
|
|
//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));
|
2013-09-12 20:46:40 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalStructFeatureSparse::add(std::string *internalStruct,
|
|
|
|
std::vector<float>& denseValues,
|
|
|
|
std::map<std::string,float>& sparseValues) const{
|
2013-09-13 14:45:46 +04:00
|
|
|
//cout<<"Sparse: "<<*internalStruct<<endl;
|
|
|
|
if(internalStruct->find("VBZ")!=std::string::npos)
|
|
|
|
sparseValues["NT_VBZ"] = 1;
|
|
|
|
if(internalStruct->find("VBD")!=std::string::npos)
|
|
|
|
sparseValues["NT_VBD"] = 1;
|
|
|
|
|
2013-09-12 20:46:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|