00001 #pragma once 00002 00003 #include <string> 00004 #include <algorithm> 00005 #include "VWFeatureSource.h" 00006 #include "moses/Util.h" 00007 00008 namespace Moses 00009 { 00010 00011 class VWFeatureSourceIndicator : public VWFeatureSource 00012 { 00013 public: 00014 VWFeatureSourceIndicator(const std::string &line) 00015 : VWFeatureSource(line) { 00016 ReadParameters(); 00017 00018 // Call this last 00019 VWFeatureBase::UpdateRegister(); 00020 } 00021 00022 void operator()(const InputType &input 00023 , const Range &sourceRange 00024 , Discriminative::Classifier &classifier 00025 , Discriminative::FeatureVector &outFeatures) const { 00026 size_t begin = sourceRange.GetStartPos(); 00027 size_t end = sourceRange.GetEndPos() + 1; 00028 00029 std::vector<std::string> words(end - begin); 00030 00031 for (size_t i = 0; i < end - begin; i++) 00032 words[i] = GetWord(input, begin + i); 00033 00034 outFeatures.push_back(classifier.AddLabelIndependentFeature("sind^" + Join(" ", words))); 00035 } 00036 00037 virtual void SetParameter(const std::string& key, const std::string& value) { 00038 VWFeatureSource::SetParameter(key, value); 00039 } 00040 }; 00041 00042 }