2011-08-13 06:40:54 +04:00
|
|
|
#ifndef moses_WordTranslationFeature_h
|
|
|
|
#define moses_WordTranslationFeature_h
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "FeatureFunction.h"
|
|
|
|
#include "FactorCollection.h"
|
|
|
|
|
2012-02-29 00:22:09 +04:00
|
|
|
#include "Sentence.h"
|
|
|
|
#include "FFState.h"
|
|
|
|
|
|
|
|
#ifdef WITH_THREADS
|
|
|
|
#include <boost/thread/tss.hpp>
|
|
|
|
#endif
|
|
|
|
|
2011-08-13 06:40:54 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Sets the features for word translation
|
|
|
|
*/
|
2012-02-29 00:22:09 +04:00
|
|
|
//class WordTranslationFeature : public StatelessFeatureFunction {
|
|
|
|
class WordTranslationFeature : public StatefulFeatureFunction {
|
|
|
|
|
|
|
|
struct ThreadLocalStorage
|
|
|
|
{
|
|
|
|
const Sentence *input;
|
|
|
|
};
|
|
|
|
|
2011-08-13 06:40:54 +04:00
|
|
|
private:
|
2012-02-29 00:22:09 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
boost::thread_specific_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#else
|
|
|
|
std::auto_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#endif
|
|
|
|
|
2011-08-13 06:40:54 +04:00
|
|
|
std::set<std::string> m_vocabSource;
|
|
|
|
std::set<std::string> m_vocabTarget;
|
|
|
|
FactorType m_factorTypeSource;
|
|
|
|
FactorType m_factorTypeTarget;
|
|
|
|
bool m_unrestricted;
|
2012-03-07 18:04:25 +04:00
|
|
|
bool m_simple;
|
2012-02-27 00:14:49 +04:00
|
|
|
bool m_sourceContext;
|
2012-03-07 18:04:25 +04:00
|
|
|
bool m_targetContext;
|
2012-03-15 04:32:27 +04:00
|
|
|
float m_sparseProducerWeight;
|
|
|
|
|
2011-08-13 06:40:54 +04:00
|
|
|
public:
|
2012-03-07 18:04:25 +04:00
|
|
|
WordTranslationFeature(FactorType factorTypeSource, FactorType factorTypeTarget,
|
|
|
|
bool simple, bool sourceContext, bool targetContext):
|
2012-02-29 00:22:09 +04:00
|
|
|
// StatelessFeatureFunction("wt", ScoreProducer::unlimited),
|
2012-03-19 06:45:59 +04:00
|
|
|
StatefulFeatureFunction("wt", ScoreProducer::unlimited),
|
2011-08-13 06:40:54 +04:00
|
|
|
m_factorTypeSource(factorTypeSource),
|
|
|
|
m_factorTypeTarget(factorTypeTarget),
|
2012-03-19 06:45:59 +04:00
|
|
|
m_unrestricted(true),
|
2012-03-07 18:04:25 +04:00
|
|
|
m_simple(simple),
|
|
|
|
m_sourceContext(sourceContext),
|
|
|
|
m_targetContext(targetContext),
|
2012-03-19 06:45:59 +04:00
|
|
|
m_sparseProducerWeight(1)
|
2012-02-29 00:22:09 +04:00
|
|
|
{
|
2012-03-07 15:48:58 +04:00
|
|
|
std::cerr << "Creating word translation feature.. ";
|
2012-03-07 18:04:25 +04:00
|
|
|
if (m_simple == 1) std::cerr << "using simple word translations.. ";
|
|
|
|
if (m_sourceContext == 1) std::cerr << "using source context.. ";
|
|
|
|
if (m_targetContext == 1) std::cerr << "using target context.. ";
|
2012-03-07 15:48:58 +04:00
|
|
|
std::cerr << "done." << std::endl;
|
2012-02-29 00:22:09 +04:00
|
|
|
}
|
2011-08-13 06:40:54 +04:00
|
|
|
|
|
|
|
bool Load(const std::string &filePathSource, const std::string &filePathTarget);
|
2012-02-29 00:22:09 +04:00
|
|
|
|
|
|
|
void InitializeForInput( Sentence const& in );
|
|
|
|
|
|
|
|
// void Evaluate(const TargetPhrase& cur_phrase, ScoreComponentCollection* accumulator) const;
|
|
|
|
|
|
|
|
const FFState* EmptyHypothesisState(const InputType &) const {
|
|
|
|
return new DummyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
FFState* Evaluate(const Hypothesis& cur_hypo, const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const;
|
|
|
|
|
|
|
|
FFState* EvaluateChart( const ChartHypothesis& /* cur_hypo */, int /* featureID */,
|
|
|
|
ScoreComponentCollection* ) const {
|
|
|
|
/* Not implemented */
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-13 06:40:54 +04:00
|
|
|
|
|
|
|
// basic properties
|
2011-09-20 14:23:38 +04:00
|
|
|
std::string GetScoreProducerWeightShortName(unsigned) const { return "wt"; }
|
2011-08-13 06:40:54 +04:00
|
|
|
size_t GetNumInputScores() const { return 0; }
|
2012-03-15 04:32:27 +04:00
|
|
|
|
|
|
|
void SetSparseProducerWeight(float weight) { m_sparseProducerWeight = weight; }
|
|
|
|
float GetSparseProducerWeight() const { return m_sparseProducerWeight; }
|
2011-08-13 06:40:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // moses_WordTranslationFeature_h
|