mosesdecoder/contrib/moses2/SCFG/ActiveChart.cpp

110 lines
2.1 KiB
C++
Raw Normal View History

2016-04-20 22:22:57 +03:00
#include <boost/foreach.hpp>
2016-05-01 11:32:49 +03:00
#include <boost/functional/hash_fwd.hpp>
#include "ActiveChart.h"
2016-04-20 18:54:08 +03:00
#include "InputPath.h"
2016-05-01 12:52:36 +03:00
#include "Word.h"
#include "Hypothesis.h"
2016-05-25 23:02:34 +03:00
#include "../Vector.h"
2016-04-20 18:54:08 +03:00
2016-05-06 13:09:52 +03:00
using namespace std;
2016-04-20 18:54:08 +03:00
namespace Moses2
{
namespace SCFG
{
2016-06-24 21:15:47 +03:00
SymbolBindElement::SymbolBindElement()
{
}
2016-05-01 12:52:36 +03:00
SymbolBindElement::SymbolBindElement(
const Moses2::Range &range,
const SCFG::Word &word,
const Moses2::Hypotheses *hypos)
:m_range(&range)
,word(&word)
2016-05-01 12:52:36 +03:00
,hypos(hypos)
{
assert( (word.isNonTerminal && hypos) || (!word.isNonTerminal && hypos == NULL));
2016-05-01 12:52:36 +03:00
}
2016-04-20 18:54:08 +03:00
2016-05-01 11:32:49 +03:00
size_t hash_value(const SymbolBindElement &obj)
{
size_t ret = (size_t) obj.hypos;
2016-05-01 11:32:49 +03:00
boost::hash_combine(ret, obj.word);
return ret;
}
std::string SymbolBindElement::Debug(const System &system) const
{
stringstream out;
out << "(";
out << *m_range;
out << word->Debug(system);
out << ")";
return out.str();
}
2016-05-01 11:32:49 +03:00
////////////////////////////////////////////////////////////////////////////
2016-06-24 21:15:47 +03:00
SymbolBind::SymbolBind(MemPool &pool)
:coll(pool)
,numNT(0)
{
}
void SymbolBind::Add(const Range &range, const SCFG::Word &word, const Moses2::Hypotheses *hypos)
2016-05-05 19:41:50 +03:00
{
SymbolBindElement ele(range, word, hypos);
2016-05-05 19:41:50 +03:00
coll.push_back(ele);
if (word.isNonTerminal) {
++numNT;
}
}
2016-05-06 13:09:52 +03:00
std::vector<const SymbolBindElement*> SymbolBind::GetNTElements() const
{
std::vector<const SymbolBindElement*> ret;
for (size_t i = 0; i < coll.size(); ++i) {
const SymbolBindElement &ele = coll[i];
//cerr << "ele=" << ele.word->isNonTerminal << " " << ele.hypos << endl;
if (ele.word->isNonTerminal) {
ret.push_back(&ele);
}
}
return ret;
}
2016-06-20 16:59:31 +03:00
std::string SymbolBind::Debug(const System &system) const
2016-04-20 22:22:57 +03:00
{
2016-06-20 16:59:31 +03:00
stringstream out;
2016-06-11 00:03:11 +03:00
BOOST_FOREACH(const SymbolBindElement &ele, coll) {
out << ele.Debug(system) << " ";
2016-04-20 22:22:57 +03:00
}
2016-06-20 16:59:31 +03:00
return out.str();
2016-04-20 22:22:57 +03:00
}
2016-06-24 21:15:47 +03:00
////////////////////////////////////////////////////////////////////////////
ActiveChartEntry::ActiveChartEntry(MemPool &pool)
:m_symbolBind(pool)
{
}
2016-04-20 18:54:08 +03:00
2016-05-25 23:02:34 +03:00
////////////////////////////////////////////////////////////////////////////
ActiveChart::ActiveChart(MemPool &pool)
2016-06-24 21:15:47 +03:00
:entries(pool)
2016-05-25 23:02:34 +03:00
{
}
ActiveChart::~ActiveChart()
{
}
2016-04-20 18:54:08 +03:00
}
}