|
|
#pragma once |
|
|
|
|
|
#include <string> |
|
|
#include <algorithm> |
|
|
#include "VWFeatureSource.h" |
|
|
#include "moses/Util.h" |
|
|
|
|
|
namespace Moses |
|
|
{ |
|
|
|
|
|
class VWFeatureSourceIndicator : public VWFeatureSource |
|
|
{ |
|
|
public: |
|
|
VWFeatureSourceIndicator(const std::string &line) |
|
|
: VWFeatureSource(line) { |
|
|
ReadParameters(); |
|
|
|
|
|
|
|
|
VWFeatureBase::UpdateRegister(); |
|
|
} |
|
|
|
|
|
void operator()(const InputType &input |
|
|
, const Range &sourceRange |
|
|
, Discriminative::Classifier &classifier |
|
|
, Discriminative::FeatureVector &outFeatures) const { |
|
|
size_t begin = sourceRange.GetStartPos(); |
|
|
size_t end = sourceRange.GetEndPos() + 1; |
|
|
|
|
|
std::vector<std::string> words(end - begin); |
|
|
|
|
|
for (size_t i = 0; i < end - begin; i++) |
|
|
words[i] = GetWord(input, begin + i); |
|
|
|
|
|
outFeatures.push_back(classifier.AddLabelIndependentFeature("sind^" + Join(" ", words))); |
|
|
} |
|
|
|
|
|
virtual void SetParameter(const std::string& key, const std::string& value) { |
|
|
VWFeatureSource::SetParameter(key, value); |
|
|
} |
|
|
}; |
|
|
|
|
|
} |
|
|
|