00001 #pragma once
00002
00003 #include <string>
00004 #include <map>
00005 #include <iostream>
00006 #include <boost/unordered_map.hpp>
00007 #include "StatefulFeatureFunction.h"
00008 #include "FFState.h"
00009 #include "util/exception.hh"
00010 #include <stdint.h>
00011
00012 namespace Moses
00013 {
00014
00015 class TargetPreferencesFeatureState : public FFState
00016 {
00017
00018 public:
00019
00020 TargetPreferencesFeatureState(bool distinguishStates)
00021 : m_distinguishStates(distinguishStates)
00022 {}
00023
00024 void AddProbabilityForLHSLabel(size_t label, double cost);
00025
00026 void NormalizeProbabilitiesForLHSLabels(double denominator);
00027
00028 const std::map<size_t,double> &GetProbabilitiesForLHSLabels() const {
00029 return m_probabilitiesForLHSLabels;
00030 }
00031
00032 double GetProbabilityForLHSLabel(size_t label, bool &isMatch) const;
00033
00034 size_t hash() const;
00035
00036 virtual bool operator==(const FFState& other) const;
00037
00038
00039 private:
00040
00041 const bool m_distinguishStates;
00042 std::map<size_t,double> m_probabilitiesForLHSLabels;
00043
00044 };
00045
00046
00047 class TargetPreferencesFeature : public StatefulFeatureFunction
00048 {
00049
00050 public:
00051
00052 TargetPreferencesFeature(const std::string &line);
00053
00054 ~TargetPreferencesFeature();
00055
00056 bool IsUseable(const FactorMask &mask) const {
00057 return true;
00058 }
00059
00060 virtual const FFState* EmptyHypothesisState(const InputType &input) const {
00061 return new TargetPreferencesFeatureState(m_distinguishStates);
00062 }
00063
00064 void SetParameter(const std::string& key, const std::string& value);
00065
00066 void Load(AllOptions::ptr const& opts);
00067
00068 void EvaluateInIsolation(const Phrase &source
00069 , const TargetPhrase &targetPhrase
00070 , ScoreComponentCollection &scoreBreakdown
00071 , ScoreComponentCollection &estimatedFutureScore) const
00072 {};
00073
00074 void EvaluateWithSourceContext(const InputType &input
00075 , const InputPath &inputPath
00076 , const TargetPhrase &targetPhrase
00077 , const StackVec *stackVec
00078 , ScoreComponentCollection &scoreBreakdown
00079 , ScoreComponentCollection *estimatedFutureScore = NULL) const
00080 {};
00081
00082 void EvaluateTranslationOptionListWithSourceContext(const InputType &input
00083 , const TranslationOptionList &translationOptionList) const
00084 {}
00085
00086 FFState* EvaluateWhenApplied(
00087 const Hypothesis& cur_hypo,
00088 const FFState* prev_state,
00089 ScoreComponentCollection* accumulator) const {
00090 UTIL_THROW2(GetScoreProducerDescription() << ": feature currently not implemented for phrase-based decoding.");
00091 return new TargetPreferencesFeatureState(m_distinguishStates);
00092 };
00093
00094 FFState* EvaluateWhenApplied(
00095 const ChartHypothesis& cur_hypo,
00096 int featureID,
00097 ScoreComponentCollection* accumulator) const;
00098
00099
00100 private:
00101
00102 std::string m_labelSetFile;
00103 std::string m_unknownLeftHandSideFile;
00104 size_t m_featureVariant;
00105 bool m_distinguishStates;
00106 bool m_noMismatches;
00107
00108 mutable boost::unordered_map<std::string,size_t> m_labels;
00109 mutable std::vector<std::string> m_labelsByIndex;
00110 mutable size_t m_XRHSLabel;
00111 mutable size_t m_XLHSLabel;
00112 mutable size_t m_GlueTopLabel;
00113 std::map<size_t,double> m_unknownLHSProbabilities;
00114
00115 void LoadLabelSet();
00116 void LoadUnknownLeftHandSideFile();
00117
00118 };
00119
00120 }
00121