00001
00002
00003 #ifndef _DOMAIN_H
00004 #define _DOMAIN_H
00005
00006 #include <iostream>
00007 #include <fstream>
00008 #include <cassert>
00009 #include <cstdlib>
00010 #include <string>
00011 #include <queue>
00012 #include <map>
00013 #include <cmath>
00014
00015 #include "ScoreFeature.h"
00016
00017 namespace MosesTraining
00018 {
00019
00020 class Domain
00021 {
00022 public:
00023 std::vector< std::pair< int, std::string > > spec;
00024 std::vector< std::string > list;
00025 std::map< std::string, int > name2id;
00026 void load( const std::string &fileName );
00027 std::string getDomainOfSentence( int sentenceId ) const;
00028 };
00029
00030 class DomainFeature : public ScoreFeature
00031 {
00032 public:
00033
00034 DomainFeature(const std::string& domainFile);
00035
00036 void addPropertiesToPhrasePair(ExtractionPhrasePair &phrasePair,
00037 float count,
00038 int sentenceId) const;
00039
00040 void add(const ScoreFeatureContext& context,
00041 std::vector<float>& denseValues,
00042 std::map<std::string,float>& sparseValues) const;
00043
00044 protected:
00046 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00047 const MaybeLog& maybeLog,
00048 std::vector<float>& denseValues,
00049 std::map<std::string,float>& sparseValues) const = 0;
00050
00051
00052 Domain m_domain;
00053
00054 const std::string m_propertyKey;
00055
00056 };
00057
00058 class SubsetDomainFeature : public DomainFeature
00059 {
00060 public:
00061 SubsetDomainFeature(const std::string& domainFile) :
00062 DomainFeature(domainFile) {}
00063
00064 protected:
00065 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00066 const MaybeLog& maybeLog,
00067 std::vector<float>& denseValues,
00068 std::map<std::string,float>& sparseValues) const;
00069 };
00070
00071 class SparseSubsetDomainFeature : public DomainFeature
00072 {
00073 public:
00074 SparseSubsetDomainFeature(const std::string& domainFile) :
00075 DomainFeature(domainFile) {}
00076
00077 protected:
00078 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00079 const MaybeLog& maybeLog,
00080 std::vector<float>& denseValues,
00081 std::map<std::string,float>& sparseValues) const;
00082
00083 };
00084
00085 class IndicatorDomainFeature : public DomainFeature
00086 {
00087 public:
00088 IndicatorDomainFeature(const std::string& domainFile) :
00089 DomainFeature(domainFile) {}
00090
00091 protected:
00092 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00093 const MaybeLog& maybeLog,
00094 std::vector<float>& denseValues,
00095 std::map<std::string,float>& sparseValues) const;
00096 };
00097
00098
00099 class SparseIndicatorDomainFeature : public DomainFeature
00100 {
00101 public:
00102 SparseIndicatorDomainFeature(const std::string& domainFile) :
00103 DomainFeature(domainFile) {}
00104
00105 protected:
00106 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00107 const MaybeLog& maybeLog,
00108 std::vector<float>& denseValues,
00109 std::map<std::string,float>& sparseValues) const;
00110 };
00111
00112
00113 class RatioDomainFeature : public DomainFeature
00114 {
00115 public:
00116 RatioDomainFeature(const std::string& domainFile) :
00117 DomainFeature(domainFile) {}
00118
00119 protected:
00120 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00121 const MaybeLog& maybeLog,
00122 std::vector<float>& denseValues,
00123 std::map<std::string,float>& sparseValues) const;
00124 };
00125
00126
00127 class SparseRatioDomainFeature : public DomainFeature
00128 {
00129 public:
00130 SparseRatioDomainFeature(const std::string& domainFile) :
00131 DomainFeature(domainFile) {}
00132
00133 protected:
00134 virtual void add(const std::map<std::string,float>& domainCounts, float count,
00135 const MaybeLog& maybeLog,
00136 std::vector<float>& denseValues,
00137 std::map<std::string,float>& sparseValues) const;
00138 };
00139
00140
00141 }
00142
00143 #endif