2012-03-23 20:52:24 +04:00
|
|
|
#ifndef MERT_SEMPOSOVERLAPPING_H_
|
|
|
|
#define MERT_SEMPOSOVERLAPPING_H_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-09-16 19:36:45 +04:00
|
|
|
#include "Types.h"
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
namespace MosesTuning
|
|
|
|
{
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
|
2012-03-24 19:07:47 +04:00
|
|
|
class SemposScorer;
|
|
|
|
|
2012-03-23 23:12:33 +04:00
|
|
|
// TODO: need comments about this number.
|
2012-03-24 02:42:00 +04:00
|
|
|
const int kMaxNOC = 50;
|
2012-03-23 20:52:24 +04:00
|
|
|
|
|
|
|
typedef std::pair<std::string, std::string> str_item_t;
|
|
|
|
typedef std::vector<str_item_t> str_sentence_t;
|
|
|
|
typedef str_sentence_t::const_iterator str_sentence_it;
|
|
|
|
|
|
|
|
typedef std::pair<int,int> item_t;
|
|
|
|
typedef std::multiset<item_t> sentence_t;
|
|
|
|
typedef sentence_t::const_iterator sentence_it;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An interface for classes representing overlapping formulas
|
|
|
|
*/
|
|
|
|
class SemposOverlapping
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SemposOverlapping() {}
|
2014-09-16 19:36:45 +04:00
|
|
|
virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref) = 0;
|
|
|
|
virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const = 0;
|
2012-03-23 20:52:24 +04:00
|
|
|
virtual std::size_t NumberOfScores() const = 0;
|
|
|
|
};
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
class SemposOverlappingFactory
|
|
|
|
{
|
|
|
|
public:
|
2012-03-24 19:07:47 +04:00
|
|
|
static SemposOverlapping* GetOverlapping(const std::string& str, const SemposScorer* sempos);
|
2012-03-23 20:52:24 +04:00
|
|
|
|
|
|
|
// dependency injection for unit testing.
|
|
|
|
static void SetOverlapping(SemposOverlapping* ovr);
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
private:
|
2012-03-23 20:52:24 +04:00
|
|
|
SemposOverlappingFactory() {}
|
|
|
|
~SemposOverlappingFactory() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overlapping proposed by (Bojar and Machacek, WMT 2011)
|
|
|
|
*
|
|
|
|
* Please refer to the paper for details:
|
|
|
|
* http://aclweb.org/anthology-new/W/W11/W11-2108.pdf
|
|
|
|
*/
|
|
|
|
class CapMicroOverlapping : public SemposOverlapping
|
|
|
|
{
|
|
|
|
public:
|
2012-03-24 19:07:47 +04:00
|
|
|
CapMicroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {}
|
2012-03-23 20:52:24 +04:00
|
|
|
~CapMicroOverlapping() {}
|
|
|
|
|
2014-09-16 19:36:45 +04:00
|
|
|
virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref);
|
|
|
|
virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const;
|
2013-05-29 21:16:15 +04:00
|
|
|
virtual std::size_t NumberOfScores() const {
|
|
|
|
return 2;
|
|
|
|
}
|
2012-03-23 20:52:24 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
private:
|
2012-03-23 20:52:24 +04:00
|
|
|
// no copying allowed.
|
|
|
|
CapMicroOverlapping(const CapMicroOverlapping&);
|
|
|
|
CapMicroOverlapping& operator=(const CapMicroOverlapping&);
|
2012-03-24 19:07:47 +04:00
|
|
|
const SemposScorer* semposScorer;
|
2012-03-23 20:52:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overlapping proposed by (Kos and Bojar, 2009)
|
|
|
|
*/
|
|
|
|
class CapMacroOverlapping : public SemposOverlapping
|
|
|
|
{
|
|
|
|
public:
|
2012-03-24 19:07:47 +04:00
|
|
|
CapMacroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {}
|
2012-03-23 20:52:24 +04:00
|
|
|
~CapMacroOverlapping() {}
|
|
|
|
|
2014-09-16 19:36:45 +04:00
|
|
|
virtual std::vector<ScoreStatsType> prepareStats(const sentence_t& cand, const sentence_t& ref);
|
|
|
|
virtual float calculateScore(const std::vector<ScoreStatsType>& stats) const;
|
2013-05-29 21:16:15 +04:00
|
|
|
virtual std::size_t NumberOfScores() const {
|
|
|
|
return kMaxNOC * 2;
|
|
|
|
}
|
2012-03-23 20:52:24 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
private:
|
2012-03-23 20:52:24 +04:00
|
|
|
// no copying allowed.
|
|
|
|
CapMacroOverlapping(const CapMacroOverlapping&);
|
|
|
|
CapMacroOverlapping& operator=(const CapMacroOverlapping&);
|
2012-03-24 19:07:47 +04:00
|
|
|
const SemposScorer* semposScorer;
|
2012-03-23 20:52:24 +04:00
|
|
|
};
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-23 20:52:24 +04:00
|
|
|
#endif // MERT_SEMPOSOVERLAPPING_H_
|