2010-09-14 19:00:22 +04:00
|
|
|
#ifndef BLUESCOREFEATURE_H
|
|
|
|
#define BLUESCOREFEATURE_H
|
|
|
|
|
2010-09-15 20:51:21 +04:00
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2010-09-14 19:00:22 +04:00
|
|
|
#include "FeatureFunction.h"
|
|
|
|
|
|
|
|
#include "FFState.h"
|
|
|
|
#include "Phrase.h"
|
|
|
|
|
|
|
|
namespace Moses {
|
|
|
|
|
|
|
|
class BleuScoreFeature;
|
|
|
|
|
|
|
|
class BleuScoreState : public FFState {
|
|
|
|
public:
|
|
|
|
friend class BleuScoreFeature;
|
|
|
|
static size_t bleu_order;
|
|
|
|
|
|
|
|
BleuScoreState();
|
|
|
|
virtual int Compare(const FFState& other) const;
|
2010-09-16 16:49:57 +04:00
|
|
|
void print(std::ostream& out) const;
|
2010-09-14 19:00:22 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Phrase m_words;
|
|
|
|
|
2010-09-16 16:38:00 +04:00
|
|
|
size_t m_source_length;
|
|
|
|
float m_scaled_ref_length;
|
|
|
|
|
2010-09-14 19:00:22 +04:00
|
|
|
std::vector< size_t > m_ngram_counts;
|
|
|
|
std::vector< size_t > m_ngram_matches;
|
|
|
|
};
|
|
|
|
|
2010-09-16 16:49:57 +04:00
|
|
|
std::ostream& operator<<(std::ostream& out, const BleuScoreState& state);
|
|
|
|
|
2010-09-16 19:40:13 +04:00
|
|
|
typedef std::map< Phrase, size_t > NGrams;
|
|
|
|
|
2010-09-14 19:00:22 +04:00
|
|
|
class BleuScoreFeature : public StatefulFeatureFunction {
|
|
|
|
public:
|
|
|
|
BleuScoreFeature();
|
|
|
|
|
|
|
|
std::string GetScoreProducerWeightShortName() const
|
|
|
|
{
|
|
|
|
return "bl";
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetNumScoreComponents() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-16 13:54:13 +04:00
|
|
|
void LoadReferences(const std::vector< std::vector< std::string > > &);
|
2010-09-15 20:51:21 +04:00
|
|
|
void SetCurrentReference(size_t);
|
2010-09-16 20:44:11 +04:00
|
|
|
void UpdateHistory(const std::vector< const Word* >&);
|
2010-09-16 19:40:13 +04:00
|
|
|
void GetNgramMatchCounts(Phrase&,
|
|
|
|
const NGrams&,
|
|
|
|
std::vector< size_t >&,
|
|
|
|
std::vector< size_t >&,
|
2010-09-16 20:44:11 +04:00
|
|
|
size_t skip = 0) const;
|
2010-09-14 19:00:22 +04:00
|
|
|
|
|
|
|
FFState* Evaluate( const Hypothesis& cur_hypo,
|
|
|
|
const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const;
|
2010-09-15 20:51:21 +04:00
|
|
|
float CalculateBleu(BleuScoreState*) const;
|
2010-09-14 20:44:31 +04:00
|
|
|
const FFState* EmptyHypothesisState(const InputType&) const;
|
|
|
|
|
2010-09-15 20:51:21 +04:00
|
|
|
private:
|
2010-09-16 13:54:13 +04:00
|
|
|
std::map< size_t, std::pair< size_t, NGrams > > m_refs;
|
|
|
|
NGrams m_cur_ref_ngrams;
|
2010-09-15 20:51:21 +04:00
|
|
|
size_t m_cur_ref_length;
|
2010-09-16 19:40:13 +04:00
|
|
|
std::vector< float > m_count_history;
|
2010-09-16 20:44:11 +04:00
|
|
|
std::vector< float > m_match_history;
|
|
|
|
float m_target_length_history;
|
|
|
|
float m_ref_length_history;
|
2010-09-14 19:00:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace.
|
|
|
|
|
|
|
|
#endif //BLUESCOREFEATURE_H
|
2010-09-15 20:51:21 +04:00
|
|
|
|