00001 #include "ControlRecombination.h"
00002 #include "moses/Hypothesis.h"
00003 #include "moses/Manager.h"
00004 #include "moses/ChartHypothesis.h"
00005 #include "moses/ChartManager.h"
00006 #include "moses/StaticData.h"
00007 #include "moses/InputFileStream.h"
00008 #include "moses/Util.h"
00009 #include "util/exception.hh"
00010
00011 using namespace std;
00012
00013 namespace Moses
00014 {
00015 ControlRecombinationState::ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff)
00016 :m_ff(ff)
00017 {
00018 if (ff.GetType() == SameOutput) {
00019
00020 hypo.GetOutputPhrase(m_outputPhrase);
00021 } else {
00022 m_hypo = &hypo;
00023 }
00024 }
00025
00026 ControlRecombinationState::ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff)
00027 :m_ff(ff)
00028 {
00029 if (ff.GetType() == SameOutput) {
00030 hypo.GetOutputPhrase(m_outputPhrase);
00031 } else {
00032 m_hypo = &hypo;
00033 }
00034 }
00035
00036 size_t ControlRecombinationState::hash() const
00037 {
00038 size_t ret;
00039 if (m_ff.GetType() == SameOutput) {
00040 ret = hash_value(m_outputPhrase);
00041 } else {
00042
00043 ret = (size_t) m_hypo;
00044 }
00045 return ret;
00046 }
00047
00048 bool ControlRecombinationState::operator==(const FFState& other) const
00049 {
00050 const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other);
00051
00052 if (m_ff.GetType() == SameOutput) {
00053 return m_outputPhrase == otherFF.m_outputPhrase;
00054 } else {
00055
00056 if (m_hypo == otherFF.m_hypo)
00057 return true;
00058 return (m_hypo == otherFF.m_hypo);
00059 }
00060 }
00061
00062 std::vector<float> ControlRecombination::DefaultWeights() const
00063 {
00064 UTIL_THROW_IF2(m_numScoreComponents,
00065 "ControlRecombination should not have any scores");
00066 vector<float> ret(0);
00067 return ret;
00068 }
00069
00070 FFState* ControlRecombination::EvaluateWhenApplied(
00071 const Hypothesis& hypo,
00072 const FFState* prev_state,
00073 ScoreComponentCollection* accumulator) const
00074 {
00075 return new ControlRecombinationState(hypo, *this);
00076 }
00077
00078 FFState* ControlRecombination::EvaluateWhenApplied(
00079 const ChartHypothesis &hypo,
00080 int ,
00081 ScoreComponentCollection* accumulator) const
00082 {
00083 return new ControlRecombinationState(hypo, *this);
00084 }
00085
00086 void ControlRecombination::SetParameter(const std::string& key, const std::string& value)
00087 {
00088 if (key == "type") {
00089 m_type = (ControlRecombinationType) Scan<int>(value);
00090 } else {
00091 StatefulFeatureFunction::SetParameter(key, value);
00092 }
00093 }
00094
00095 }
00096