Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/moses2/FF/FeatureRegistry.cpp')
-rw-r--r--contrib/moses2/FF/FeatureRegistry.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/contrib/moses2/FF/FeatureRegistry.cpp b/contrib/moses2/FF/FeatureRegistry.cpp
new file mode 100644
index 000000000..af0af9d0f
--- /dev/null
+++ b/contrib/moses2/FF/FeatureRegistry.cpp
@@ -0,0 +1,127 @@
+#include "FeatureRegistry.h"
+
+#include "../TranslationModel/Memory/PhraseTableMemory.h"
+#include "../TranslationModel/CompactPT/PhraseTableCompact.h"
+#include "../TranslationModel/ProbingPT/ProbingPT.h"
+#include "../TranslationModel/UnknownWordPenalty.h"
+#include "../TranslationModel/Transliteration.h"
+
+#include "../LM/KENLM.h"
+#include "../LM/KENLMBatch.h"
+#include "../LM/LanguageModel.h"
+#include "../LM/GPULM.h"
+
+#include "Distortion.h"
+#include "LexicalReordering/LexicalReordering.h"
+#include "PhrasePenalty.h"
+#include "WordPenalty.h"
+#include "OSM/OpSequenceModel.h"
+
+#include "SkeletonStatefulFF.h"
+#include "SkeletonStatelessFF.h"
+
+using namespace std;
+
+namespace Moses2
+{
+template<class F>
+class DefaultFeatureFactory: public FeatureFactory
+{
+public:
+ FeatureFunction *Create(size_t startInd, const std::string &line)
+ {
+ return new F(startInd, line);
+ }
+};
+
+////////////////////////////////////////////////////////////////////
+class KenFactory: public FeatureFactory
+{
+public:
+ FeatureFunction *Create(size_t startInd, const std::string &line)
+ {
+ ConstructKenLM(startInd, line);
+ }
+};
+
+////////////////////////////////////////////////////////////////////
+FeatureRegistry::FeatureRegistry()
+{
+ // Feature with same name as class
+#define MOSES_FNAME(name) Add(#name, new DefaultFeatureFactory< name >());
+ // Feature with different name than class.
+#define MOSES_FNAME2(name, type) Add(name, new DefaultFeatureFactory< type >());
+
+ MOSES_FNAME2("PhraseDictionaryCompact", PhraseTableCompact);
+ MOSES_FNAME2("PhraseDictionaryMemory", PhraseTableMemory);
+ MOSES_FNAME(ProbingPT);
+ MOSES_FNAME2("PhraseDictionaryTransliteration", Transliteration);
+ MOSES_FNAME(UnknownWordPenalty);
+
+ Add("KENLM", new KenFactory());
+
+ MOSES_FNAME(KENLMBatch);
+ MOSES_FNAME(GPULM);
+
+ MOSES_FNAME(LanguageModel);
+
+ MOSES_FNAME(Distortion);
+ MOSES_FNAME(LexicalReordering);
+ MOSES_FNAME(PhrasePenalty);
+ MOSES_FNAME(WordPenalty);
+ MOSES_FNAME(OpSequenceModel);
+
+ MOSES_FNAME(SkeletonStatefulFF);
+ MOSES_FNAME(SkeletonStatelessFF);
+}
+
+FeatureRegistry::~FeatureRegistry()
+{
+
+}
+
+void FeatureRegistry::Add(const std::string &name, FeatureFactory *factory)
+{
+ std::pair<std::string, boost::shared_ptr<FeatureFactory> > to_ins(name,
+ boost::shared_ptr<FeatureFactory>(factory));
+ if (!registry_.insert(to_ins).second) {
+ cerr << "Duplicate feature name " << name << endl;
+ abort();
+ }
+}
+
+FeatureFunction *FeatureRegistry::Construct(size_t startInd,
+ const std::string &name, const std::string &line)
+{
+ Map::iterator i = registry_.find(name);
+ if (i == registry_.end()) {
+ cerr << "Feature name " << name << " is not registered.";
+ abort();
+ }
+ FeatureFactory *fact = i->second.get();
+ FeatureFunction *ff = fact->Create(startInd, line);
+ return ff;
+}
+
+void FeatureRegistry::PrintFF() const
+{
+ std::vector<std::string> ffs;
+ std::cerr << "Available feature functions:" << std::endl;
+ Map::const_iterator iter;
+ for (iter = registry_.begin(); iter != registry_.end(); ++iter) {
+ const std::string &ffName = iter->first;
+ ffs.push_back(ffName);
+ }
+
+ std::vector<std::string>::const_iterator iterVec;
+ std::sort(ffs.begin(), ffs.end());
+ for (iterVec = ffs.begin(); iterVec != ffs.end(); ++iterVec) {
+ const std::string &ffName = *iterVec;
+ std::cerr << ffName << " ";
+ }
+
+ std::cerr << std::endl;
+}
+
+}
+