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)
|
2013-10-29 22:59:53 +04:00
|
|
|
: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);
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
void EvaluateInIsolation(const Phrase &source
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const {
|
|
|
|
}
|
2014-07-10 02:06:54 +04:00
|
|
|
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 {
|
|
|
|
}
|
|
|
|
|
2015-01-06 15:56:13 +03:00
|
|
|
void EvaluateTranslationOptionListWithSourceContext(const InputType &input
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TranslationOptionList &translationOptionList) const {
|
|
|
|
}
|
|
|
|
|
2014-07-10 02:41:08 +04:00
|
|
|
FFState* EvaluateWhenApplied(
|
2013-09-27 12:35:24 +04:00
|
|
|
const Hypothesis& cur_hypo,
|
|
|
|
const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const;
|
|
|
|
|
2014-07-10 02:54:16 +04:00
|
|
|
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:
|
2014-10-10 18:47:53 +04:00
|
|
|
virtual ~CdecFF() {}
|
2013-09-27 12:35:24 +04:00
|
|
|
virtual int StateSize() const = 0;
|
2013-09-12 11:48:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|