00001 #include <vector>
00002 #include "DeleteRules.h"
00003 #include "moses/ScoreComponentCollection.h"
00004 #include "moses/TargetPhrase.h"
00005 #include "moses/InputFileStream.h"
00006 #include "util/exception.hh"
00007
00008 using namespace std;
00009
00010 namespace Moses
00011 {
00012 DeleteRules::DeleteRules(const std::string &line)
00013 :StatelessFeatureFunction(1, line)
00014 {
00015 m_tuneable = false;
00016 ReadParameters();
00017 }
00018
00019 void DeleteRules::Load(AllOptions::ptr const& opts)
00020 {
00021 m_options = opts;
00022 std::vector<FactorType> factorOrder;
00023 factorOrder.push_back(0);
00024
00025 InputFileStream strme(m_path);
00026
00027 string line;
00028 while (getline(strme, line)) {
00029 vector<string> toks = TokenizeMultiCharSeparator(line, "|||");
00030 UTIL_THROW_IF2(toks.size() != 2, "Line must be source ||| target");
00031 Phrase source, target;
00032 source.CreateFromString(Input, factorOrder, toks[0], NULL);
00033 target.CreateFromString(Output, factorOrder, toks[1], NULL);
00034
00035 size_t hash = 0;
00036 boost::hash_combine(hash, source);
00037 boost::hash_combine(hash, target);
00038 m_ruleHashes.insert(hash);
00039 }
00040 }
00041
00042 void DeleteRules::EvaluateInIsolation(const Phrase &source
00043 , const TargetPhrase &target
00044 , ScoreComponentCollection &scoreBreakdown
00045 , ScoreComponentCollection &estimatedScores) const
00046 {
00047
00048 size_t hash = 0;
00049 boost::hash_combine(hash, source);
00050 boost::hash_combine(hash, target);
00051
00052 boost::unordered_set<size_t>::const_iterator iter;
00053 iter = m_ruleHashes.find(hash);
00054 if (iter != m_ruleHashes.end()) {
00055 scoreBreakdown.PlusEquals(this, -std::numeric_limits<float>::infinity());
00056 }
00057
00058 }
00059
00060 void DeleteRules::EvaluateWithSourceContext(const InputType &input
00061 , const InputPath &inputPath
00062 , const TargetPhrase &targetPhrase
00063 , const StackVec *stackVec
00064 , ScoreComponentCollection &scoreBreakdown
00065 , ScoreComponentCollection *estimatedScores) const
00066 {}
00067
00068 void DeleteRules::EvaluateTranslationOptionListWithSourceContext(const InputType &input
00069
00070 , const TranslationOptionList &translationOptionList) const
00071 {}
00072
00073 void DeleteRules::EvaluateWhenApplied(const Hypothesis& hypo,
00074 ScoreComponentCollection* accumulator) const
00075 {}
00076
00077 void DeleteRules::EvaluateWhenApplied(const ChartHypothesis &hypo,
00078 ScoreComponentCollection* accumulator) const
00079 {}
00080
00081 void DeleteRules::SetParameter(const std::string& key, const std::string& value)
00082 {
00083 if (key == "path") {
00084 m_path = value;
00085 } else {
00086 StatelessFeatureFunction::SetParameter(key, value);
00087 }
00088 }
00089
00090 }
00091