00001 #pragma once
00002
00003 #include <vector>
00004 #include <string>
00005 #include <set>
00006 #include "StatefulFeatureFunction.h"
00007 #include "FFState.h"
00008 #include "moses/Phrase.h"
00009 #include "moses/Factor.h"
00010 #include "boost/unordered_map.hpp"
00011
00012 namespace Moses
00013 {
00014
00015
00016
00017 class CoveredReferenceState : public FFState
00018 {
00019 public:
00020 std::multiset<std::string> m_coveredRef;
00021
00022 virtual size_t hash() const;
00023 virtual bool operator==(const FFState& other) const;
00024
00025 };
00026
00027 class CoveredReferenceFeature : public StatefulFeatureFunction
00028 {
00029 static std::multiset<std::string> GetWordsInPhrase(const Phrase &phr) {
00030 std::multiset<std::string> out;
00031 for (size_t i = 0; i < phr.GetSize(); i++) {
00032 out.insert(phr.GetFactor(i, 0)->GetString().as_string());
00033 }
00034 return out;
00035 }
00036
00037 std::string m_path;
00038 boost::unordered_map<long, std::multiset<std::string> > m_refs;
00039
00040 public:
00041 CoveredReferenceFeature(const std::string &line)
00042 :StatefulFeatureFunction(1, line) {
00043 m_tuneable = true;
00044 ReadParameters();
00045 }
00046
00047 void Load(AllOptions::ptr const& opts);
00048
00049 bool IsUseable(const FactorMask &mask) const {
00050 return true;
00051 }
00052 virtual const FFState* EmptyHypothesisState(const InputType &input) const {
00053 return new CoveredReferenceState();
00054 }
00055
00056 void EvaluateWithSourceContext(const InputType &input
00057 , const InputPath &inputPath
00058 , const TargetPhrase &targetPhrase
00059 , const StackVec *stackVec
00060 , ScoreComponentCollection &scoreBreakdown
00061 , ScoreComponentCollection *estimatedScores = NULL) const;
00062
00063 FFState* EvaluateWhenApplied(
00064 const Hypothesis& cur_hypo,
00065 const FFState* prev_state,
00066 ScoreComponentCollection* accumulator) const;
00067 FFState* EvaluateWhenApplied(
00068 const ChartHypothesis& ,
00069 int ,
00070 ScoreComponentCollection* accumulator) const;
00071
00072 void SetParameter(const std::string& key, const std::string& value);
00073 };
00074
00075 }