mosesdecoder/defer/ExternalFeature.h

101 lines
2.5 KiB
C
Raw Normal View History

2013-09-12 11:48:17 +04:00
#pragma once
#include <string>
2013-09-12 12:17:18 +04:00
#include <cstring>
2013-11-21 23:19:34 +04:00
#include <cstdlib>
2013-09-12 11:48:17 +04:00
#include "StatefulFeatureFunction.h"
#include "FFState.h"
namespace Moses
{
class CdecFF;
class ExternalFeatureState : public FFState
{
protected:
2013-09-27 12:35:24 +04:00
int m_stateSize;
void *m_data;
2013-09-12 11:48:17 +04:00
public:
2013-09-27 12:35:24 +04:00
ExternalFeatureState(int stateSize)
:m_stateSize(stateSize)
2015-01-14 14:07:42 +03:00
,m_data(NULL) {
}
2013-09-27 12:35:24 +04:00
ExternalFeatureState(int stateSize, void *data);
~ExternalFeatureState() {
free(m_data);
}
int Compare(const FFState& other) const {
const ExternalFeatureState &otherFF = static_cast<const ExternalFeatureState&>(other);
int ret = memcmp(m_data, otherFF.m_data, m_stateSize);
return ret;
}
2013-09-12 11:48:17 +04:00
};
// copied from cdec
class ExternalFeature : public StatefulFeatureFunction
{
public:
2013-09-27 12:35:24 +04:00
ExternalFeature(const std::string &line)
:StatefulFeatureFunction(line) {
2013-09-27 12:35:24 +04:00
ReadParameters();
}
~ExternalFeature();
void Load();
bool IsUseable(const FactorMask &mask) const {
return true;
}
void SetParameter(const std::string& key, const std::string& value);
void EvaluateInIsolation(const Phrase &source
2015-01-14 14:07:42 +03:00
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedFutureScore) const {
}
void EvaluateWithSourceContext(const InputType &input
2015-01-14 14:07:42 +03:00
, const InputPath &inputPath
, const TargetPhrase &targetPhrase
, const StackVec *stackVec
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection *estimatedFutureScore = NULL) const {
}
void EvaluateTranslationOptionListWithSourceContext(const InputType &input
2015-01-14 14:07:42 +03:00
, const TranslationOptionList &translationOptionList) const {
}
FFState* EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const;
FFState* EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const ChartHypothesis& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const;
virtual const FFState* EmptyHypothesisState(const InputType &input) const {
return new ExternalFeatureState(m_stateSize);
}
2013-09-12 11:48:17 +04:00
protected:
2013-09-27 12:35:24 +04:00
std::string m_path;
void* lib_handle;
CdecFF *ff_ext;
int m_stateSize;
2013-09-12 11:48:17 +04:00
};
class CdecFF
{
public:
virtual ~CdecFF() {}
2013-09-27 12:35:24 +04:00
virtual int StateSize() const = 0;
2013-09-12 11:48:17 +04:00
};
}