mosesdecoder/moses/GlobalLexicalModelUnlimited.h

106 lines
2.6 KiB
C
Raw Normal View History

#ifndef GLOBALLEXICALMODELUNLIMITED_H_
#define GLOBALLEXICALMODELUNLIMITED_H_
#include <string>
#include <vector>
#include "Factor.h"
#include "Phrase.h"
#include "TypeDef.h"
#include "Util.h"
#include "WordsRange.h"
#include "FeatureFunction.h"
#include "FactorTypeSet.h"
#include "Sentence.h"
#include "FFState.h"
#ifdef WITH_THREADS
#include <boost/thread/tss.hpp>
#endif
namespace Moses
{
class Factor;
class Phrase;
class Hypothesis;
class InputType;
/** Discriminatively trained global lexicon model
* This is a implementation of Mauser et al., 2009's model that predicts
* each output word from _all_ the input words. The intuition behind this
* feature is that it uses context words for disambiguation
*/
class GlobalLexicalModelUnlimited : public StatelessFeatureFunction
{
2012-02-15 15:27:00 +04:00
typedef std::map< char, short > CharHash;
2012-02-03 19:35:26 +04:00
typedef std::map< std::string, short > StringHash;
struct ThreadLocalStorage
{
const Sentence *input;
};
private:
#ifdef WITH_THREADS
boost::thread_specific_ptr<ThreadLocalStorage> m_local;
#else
std::auto_ptr<ThreadLocalStorage> m_local;
#endif
2012-02-15 15:27:00 +04:00
CharHash m_punctuationHash;
std::vector< FactorType > m_inputFactors;
std::vector< FactorType > m_outputFactors;
2012-02-26 21:46:04 +04:00
bool m_unrestricted;
bool m_sourceContext;
bool m_biphrase;
bool m_bitrigger;
bool m_biasFeature;
bool m_ignorePunctuation;
std::set<std::string> m_vocabSource;
std::set<std::string> m_vocabTarget;
public:
GlobalLexicalModelUnlimited(const std::string &line);
bool Load(const std::string &filePathSource, const std::string &filePathTarget);
void InitializeForInput( Sentence const& in );
const FFState* EmptyHypothesisState(const InputType &) const {
return new DummyState();
}
2012-09-07 19:57:53 +04:00
//TODO: This implements the old interface, but cannot be updated because
//it appears to be stateful
void Evaluate(const Hypothesis& cur_hypo,
ScoreComponentCollection* accumulator) const;
void EvaluateChart(const ChartHypothesis& /* cur_hypo */,
int /* featureID */,
ScoreComponentCollection* ) const {
/* Not implemented */
assert(0);
}
virtual void Evaluate(const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedFutureScore) const;
void AddFeature(ScoreComponentCollection* accumulator,
StringPiece sourceTrigger, StringPiece sourceWord, StringPiece targetTrigger,
StringPiece targetWord) const;
2013-04-30 22:27:49 +04:00
virtual StatelessFeatureType GetStatelessFeatureType() const
{ return RequiresSource; }
2013-04-30 22:27:49 +04:00
};
}
#endif /* GLOBALLEXICALMODELUNLIMITED_H_ */