00001 #ifndef MERT_SEMPOSOVERLAPPING_H_ 00002 #define MERT_SEMPOSOVERLAPPING_H_ 00003 00004 #include <map> 00005 #include <set> 00006 #include <string> 00007 #include <utility> 00008 #include <vector> 00009 00010 #include "Types.h" 00011 00012 namespace MosesTuning 00013 { 00014 00015 00016 class SemposScorer; 00017 00018 // TODO: need comments about this number. 00019 const int kMaxNOC = 50; 00020 00021 typedef std::pair<std::string, std::string> str_item_t; 00022 typedef std::vector<str_item_t> str_sentence_t; 00023 typedef str_sentence_t::const_iterator str_sentence_it; 00024 00025 typedef std::pair<int,int> item_t; 00026 typedef std::multiset<item_t> sentence_t; 00027 typedef sentence_t::const_iterator sentence_it; 00028 00032 class SemposOverlapping 00033 { 00034 public: 00035 virtual ~SemposOverlapping() {} 00036 virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref) = 0; 00037 virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const = 0; 00038 virtual std::size_t NumberOfScores() const = 0; 00039 }; 00040 00041 class SemposOverlappingFactory 00042 { 00043 public: 00044 static SemposOverlapping* GetOverlapping(const std::string& str, const SemposScorer* sempos); 00045 00046 // dependency injection for unit testing. 00047 static void SetOverlapping(SemposOverlapping* ovr); 00048 00049 private: 00050 SemposOverlappingFactory() {} 00051 ~SemposOverlappingFactory() {} 00052 }; 00053 00060 class CapMicroOverlapping : public SemposOverlapping 00061 { 00062 public: 00063 CapMicroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {} 00064 ~CapMicroOverlapping() {} 00065 00066 virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref); 00067 virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const; 00068 virtual std::size_t NumberOfScores() const { 00069 return 2; 00070 } 00071 00072 private: 00073 // no copying allowed. 00074 CapMicroOverlapping(const CapMicroOverlapping&); 00075 CapMicroOverlapping& operator=(const CapMicroOverlapping&); 00076 const SemposScorer* semposScorer; 00077 }; 00078 00082 class CapMacroOverlapping : public SemposOverlapping 00083 { 00084 public: 00085 CapMacroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {} 00086 ~CapMacroOverlapping() {} 00087 00088 virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref); 00089 virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const; 00090 virtual std::size_t NumberOfScores() const { 00091 return kMaxNOC * 2; 00092 } 00093 00094 private: 00095 // no copying allowed. 00096 CapMacroOverlapping(const CapMacroOverlapping&); 00097 CapMacroOverlapping& operator=(const CapMacroOverlapping&); 00098 const SemposScorer* semposScorer; 00099 }; 00100 00101 } 00102 00103 #endif // MERT_SEMPOSOVERLAPPING_H_