00001 #include <map>
00002 #include <vector>
00003 #include <cassert>
00004 #include "SourceGHKMTreeInputMatchFeature.h"
00005 #include "moses/StaticData.h"
00006 #include "moses/InputFileStream.h"
00007 #include "moses/ScoreComponentCollection.h"
00008 #include "moses/Hypothesis.h"
00009 #include "moses/ChartHypothesis.h"
00010 #include "moses/Factor.h"
00011 #include "moses/FactorCollection.h"
00012 #include "moses/InputPath.h"
00013 #include "moses/TreeInput.h"
00014
00015
00016 using namespace std;
00017
00018 namespace Moses
00019 {
00020
00021 SourceGHKMTreeInputMatchFeature::SourceGHKMTreeInputMatchFeature(const std::string &line)
00022 : StatelessFeatureFunction(2, line)
00023 {
00024 std::cerr << GetScoreProducerDescription() << "Initializing feature...";
00025 ReadParameters();
00026 std::cerr << " Done." << std::endl;
00027 }
00028
00029 void SourceGHKMTreeInputMatchFeature::SetParameter(const std::string& key, const std::string& value)
00030 {
00031 UTIL_THROW(util::Exception, GetScoreProducerDescription() << ": Unknown parameter " << key << "=" << value);
00032 }
00033
00034
00035 void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType &input
00036 , const InputPath &inputPath
00037 , const TargetPhrase &targetPhrase
00038 , const StackVec *stackVec
00039 , ScoreComponentCollection &scoreBreakdown
00040 , ScoreComponentCollection *estimatedScores) const
00041 {
00042 const Range& range = inputPath.GetWordsRange();
00043 size_t startPos = range.GetStartPos();
00044 size_t endPos = range.GetEndPos();
00045 const TreeInput& treeInput = static_cast<const TreeInput&>(input);
00046 const NonTerminalSet& treeInputLabels = treeInput.GetLabelSet(startPos,endPos);
00047 const Word& lhsLabel = targetPhrase.GetTargetLHS();
00048
00049 const StaticData& staticData = StaticData::Instance();
00050
00051 std::vector<float> newScores(m_numScoreComponents,0.0);
00052
00053
00054 if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end())
00055 && (lhsLabel != m_options->syntax.output_default_non_terminal) ) {
00056
00057 newScores[0] = 1.0;
00058 } else {
00059
00060 newScores[1] = 1.0;
00061 }
00062
00063 scoreBreakdown.PlusEquals(this, newScores);
00064 }
00065
00066 void
00067 SourceGHKMTreeInputMatchFeature::
00068 Load(AllOptions::ptr const& opts)
00069 {
00070 m_options = opts;
00071
00072 }
00073
00074 }
00075