mosesdecoder/phrase-extract/DomainFeature.h

146 lines
3.8 KiB
C
Raw Normal View History

// $Id$
#ifndef _DOMAIN_H
#define _DOMAIN_H
#include <iostream>
#include <fstream>
#include <assert.h>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include "ScoreFeature.h"
extern std::vector<std::string> tokenize( const char*);
namespace MosesTraining
{
class Domain
{
public:
std::vector< std::pair< int, std::string > > spec;
std::vector< std::string > list;
std::map< std::string, int > name2id;
void load( const std::string &fileName );
std::string getDomainOfSentence( int sentenceId ) const;
};
class DomainFeature : public ScoreFeature
{
2013-05-29 21:16:15 +04:00
public:
DomainFeature(const std::string& domainFile);
2014-05-19 17:35:08 +04:00
void addPropertiesToPhrasePair(ExtractionPhrasePair &phrasePair,
float count,
int sentenceId) const;
2013-05-29 21:16:15 +04:00
void add(const ScoreFeatureContext& context,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
2013-05-29 21:16:15 +04:00
protected:
/** Overridden in subclass */
2013-05-29 21:16:15 +04:00
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const = 0;
2013-05-29 21:16:15 +04:00
Domain m_domain;
const std::string m_propertyKey;
};
class SubsetDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
SubsetDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseSubsetDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
SparseSubsetDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
2013-05-29 21:16:15 +04:00
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class IndicatorDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
IndicatorDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseIndicatorDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
SparseIndicatorDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class RatioDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
RatioDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
class SparseRatioDomainFeature : public DomainFeature
{
2013-05-29 21:16:15 +04:00
public:
SparseRatioDomainFeature(const std::string& domainFile) :
DomainFeature(domainFile) {}
protected:
virtual void add(const std::map<std::string,float>& domainCounts, float count,
const MaybeLog& maybeLog,
std::vector<float>& denseValues,
std::map<std::string,float>& sparseValues) const;
};
}
#endif