mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-19 23:27:46 +03:00
ThreadLocalFeatureStorage
This commit is contained in:
parent
5b71b2c3a9
commit
c898f8e63f
9
moses/FF/VW/ThreadLocalFeatureStorage.cpp
Normal file
9
moses/FF/VW/ThreadLocalFeatureStorage.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#include "ThreadLocalFeatureStorage.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
TSNameFeatureMap ThreadLocalFeatureStorage::m_nameMap;
|
||||
}
|
||||
|
||||
|
51
moses/FF/VW/ThreadLocalFeatureStorage.h
Normal file
51
moses/FF/VW/ThreadLocalFeatureStorage.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/thread/tss.hpp>
|
||||
|
||||
#include "moses/FF/FeatureFunction.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
typedef std::vector<std::string> Features;
|
||||
typedef std::map<std::string, Features> NameFeatureMap;
|
||||
typedef boost::thread_specific_ptr<NameFeatureMap> TSNameFeatureMap;
|
||||
|
||||
class ThreadLocalFeatureStorage
|
||||
{
|
||||
public:
|
||||
|
||||
ThreadLocalFeatureStorage(FeatureFunction* ff) : m_ff(ff) {}
|
||||
|
||||
virtual Features& GetStoredFeatures() {
|
||||
return (*m_nameMap)[m_ff->GetScoreProducerDescription()];
|
||||
}
|
||||
|
||||
virtual const Features& GetStoredFeatures() const {
|
||||
NameFeatureMap::const_iterator it
|
||||
= m_nameMap->find(m_ff->GetScoreProducerDescription());
|
||||
|
||||
UTIL_THROW_IF2(it == m_nameMap->end(),
|
||||
"No features stored for: " << m_ff->GetScoreProducerDescription());
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
virtual void InitializeForInput(InputType const& source) {
|
||||
if(!m_nameMap.get())
|
||||
m_nameMap.reset(new NameFeatureMap());
|
||||
|
||||
(*m_nameMap)[m_ff->GetScoreProducerDescription()].clear();
|
||||
}
|
||||
|
||||
private:
|
||||
FeatureFunction* m_ff;
|
||||
static TSNameFeatureMap m_nameMap;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user