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

71 lines
1.4 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-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-04-20 22:22:57 +03:00
std::ostream& operator<<(std::ostream &out, const SymbolBind &obj)
{
2016-05-01 11:32:49 +03:00
BOOST_FOREACH(const SymbolBindElement &ele, obj.coll) {
out << "("<< *ele.range << *ele.word << ") ";
2016-04-20 22:22:57 +03:00
}
return out;
}
2016-04-20 18:54:08 +03:00
}
}