mosesdecoder/phrase-extract/score-stsg/LexicalTable.h
Phil Williams 60e56efc6b phrase-extract: add syntax-common sub-library
And remove some (near-)duplicate code from pcfg-common and score-stsg.
2014-12-07 14:27:51 +00:00

47 lines
923 B
C++

#pragma once
#include <istream>
#include <string>
#include <vector>
#include <boost/unordered_map.hpp>
#include "Vocabulary.h"
namespace MosesTraining
{
namespace Syntax
{
namespace ScoreStsg
{
class LexicalTable
{
public:
LexicalTable(Vocabulary &, Vocabulary &);
void Load(std::istream &);
double PermissiveLookup(Vocabulary::IdType s, Vocabulary::IdType t) {
OuterMap::const_iterator p = m_table.find(s);
if (p == m_table.end()) {
return 1.0;
}
const InnerMap &inner = p->second;
InnerMap::const_iterator q = inner.find(t);
return q == inner.end() ? 1.0 : q->second;
}
private:
typedef boost::unordered_map<Vocabulary::IdType, double> InnerMap;
typedef boost::unordered_map<Vocabulary::IdType, InnerMap> OuterMap;
Vocabulary &m_srcVocab;
Vocabulary &m_tgtVocab;
OuterMap m_table;
};
} // namespace ScoreStsg
} // namespace Syntax
} // namespace MosesTraining