mosesdecoder/contrib/other-builds/moses2/SCFG/ActiveChart.cpp

85 lines
1.8 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"
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-05-01 12:52:36 +03:00
SymbolBindElement::SymbolBindElement(
const Range *range,
const SCFG::Word *word,
const Moses2::HypothesisColl *hypos)
:range(range)
,word(word)
,hypos(hypos)
{
assert( (word->isNonTerminal && hypos) || (!word->isNonTerminal && hypos == NULL));
}
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.range;
boost::hash_combine(ret, obj.word);
return ret;
}
////////////////////////////////////////////////////////////////////////////
2016-05-05 19:41:50 +03:00
void SymbolBind::Add(const Range &range, const SCFG::Word &word, const Moses2::HypothesisColl *hypos)
{
SymbolBindElement ele(&range, &word, hypos);
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.range;
2016-06-20 16:59:31 +03:00
out << ele.word->Debug(system);
2016-06-11 00:03:11 +03:00
out << ") ";
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-04-20 18:54:08 +03:00
2016-05-25 23:02:34 +03:00
////////////////////////////////////////////////////////////////////////////
ActiveChart::ActiveChart(MemPool &pool)
{
entries = new (pool.Allocate< Vector<ActiveChartEntry*> >()) Vector<ActiveChartEntry*>(pool);
}
ActiveChart::~ActiveChart()
{
}
2016-04-20 18:54:08 +03:00
}
}