mosesdecoder/moses2/SCFG/Misc.h

147 lines
2.9 KiB
C
Raw Normal View History

2016-06-02 14:58:29 +03:00
/*
* Misc.h
*
* Created on: 2 Jun 2016
* Author: hieu
*/
#pragma once
#include <vector>
2016-06-02 15:57:29 +03:00
#include <queue>
2016-06-04 01:53:40 +03:00
#include <boost/unordered_set.hpp>
2016-06-28 00:34:01 +03:00
#include "../HypothesisColl.h"
#include "../Vector.h"
#include "Hypothesis.h"
2016-06-02 14:58:29 +03:00
namespace Moses2
{
namespace SCFG
{
class SymbolBind;
2016-06-02 14:58:29 +03:00
class TargetPhrases;
2016-06-02 19:47:04 +03:00
class Queue;
2016-06-02 14:58:29 +03:00
///////////////////////////////////////////
class SeenPosition
{
public:
const SymbolBind &symbolBind;
const SCFG::TargetPhrases &tps;
size_t tpInd;
Vector<size_t> hypoIndColl;
SeenPosition(MemPool &pool,
const SymbolBind &vSymbolBind,
const SCFG::TargetPhrases &vtps,
size_t numNT);
SeenPosition(MemPool &pool,
const SymbolBind &vSymbolBind,
const SCFG::TargetPhrases &vtps,
size_t vtpInd,
const Vector<size_t> &vhypoIndColl);
bool operator==(const SeenPosition &compare) const;
size_t hash() const;
2016-06-20 16:59:31 +03:00
std::string Debug(const System &system) const;
};
///////////////////////////////////////////
class SeenPositions
{
public:
bool Add(const SeenPosition *item);
void clear()
{ m_coll.clear(); }
protected:
typedef boost::unordered_set<const SeenPosition*,
UnorderedComparer<SeenPosition>, UnorderedComparer<SeenPosition> > Coll;
Coll m_coll;
};
2016-06-02 15:57:29 +03:00
///////////////////////////////////////////
2016-06-02 14:58:29 +03:00
class QueueItem
{
public:
2016-06-02 15:57:29 +03:00
SCFG::Hypothesis *hypo;
2016-06-06 01:29:27 +03:00
static QueueItem *Create(MemPool &pool, SCFG::Manager &mgr);
2016-06-03 18:19:22 +03:00
void Init(
2016-06-03 17:53:33 +03:00
MemPool &pool,
const SymbolBind &symbolBind,
2016-08-17 16:10:32 +03:00
const SCFG::TargetPhrases &tps,
const Vector<size_t> &hypoIndColl);
2016-06-03 18:19:22 +03:00
void Init(
2016-06-03 17:53:33 +03:00
MemPool &pool,
const SymbolBind &symbolBind,
const SCFG::TargetPhrases &tps,
2016-08-17 16:10:32 +03:00
size_t vTPInd,
const Vector<size_t> &hypoIndColl);
void AddHypos(const Moses2::Hypotheses &hypos);
2016-06-02 19:47:04 +03:00
void CreateHypo(
MemPool &systemPool,
2016-06-02 19:47:04 +03:00
SCFG::Manager &mgr,
2016-06-02 18:21:15 +03:00
const SCFG::InputPath &path,
const SCFG::SymbolBind &symbolBind);
2016-06-02 19:47:04 +03:00
void CreateNext(
MemPool &systemPool,
MemPool &mgrPool,
2016-06-02 19:47:04 +03:00
SCFG::Manager &mgr,
SCFG::Queue &queue,
2016-06-04 01:53:40 +03:00
SeenPositions &seenPositions,
2016-06-02 19:47:04 +03:00
const SCFG::InputPath &path);
2016-06-03 17:53:33 +03:00
2016-06-20 16:59:31 +03:00
std::string Debug(const System &system) const;
2016-06-15 02:34:30 +03:00
2016-06-03 17:53:33 +03:00
protected:
typedef Vector<const Moses2::Hypotheses *> HyposColl;
HyposColl *m_hyposColl;
2016-06-03 17:53:33 +03:00
const SymbolBind *symbolBind;
const SCFG::TargetPhrases *tps;
size_t tpInd;
const Vector<size_t> *m_hypoIndColl; // pointer to variable in seen position
// hypos and ind to the 1 we're using
2016-06-03 18:19:22 +03:00
QueueItem(MemPool &pool);
2016-06-02 14:58:29 +03:00
};
2016-06-06 01:29:27 +03:00
///////////////////////////////////////////
typedef std::deque<QueueItem*> QueueItemRecycler;
2016-06-02 15:57:29 +03:00
///////////////////////////////////////////
class QueueItemOrderer
2016-06-02 14:58:29 +03:00
{
public:
2016-06-02 15:57:29 +03:00
bool operator()(QueueItem* itemA, QueueItem* itemB) const
{
HypothesisFutureScoreOrderer orderer;
return !orderer(itemA->hypo, itemB->hypo);
}
2016-06-02 14:58:29 +03:00
};
2016-06-02 15:57:29 +03:00
///////////////////////////////////////////
2016-06-02 19:47:04 +03:00
class Queue : public std::priority_queue<QueueItem*,
2016-06-02 15:57:29 +03:00
std::vector<QueueItem*>,
2016-06-02 19:47:04 +03:00
QueueItemOrderer>
{
};
2016-06-02 15:57:29 +03:00
2016-06-04 01:53:40 +03:00
2016-06-02 14:58:29 +03:00
}
}