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