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
|
|
|
|
{
|
2016-08-17 15:03:23 +03:00
|
|
|
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
|
|
|
|
2016-06-15 12:49:24 +03:00
|
|
|
///////////////////////////////////////////
|
|
|
|
class SeenPosition
|
|
|
|
{
|
|
|
|
public:
|
2016-08-17 15:03:23 +03:00
|
|
|
const SymbolBind &symbolBind;
|
2016-08-17 15:47:55 +03:00
|
|
|
const SCFG::TargetPhrases &tps;
|
2016-06-15 12:49:24 +03:00
|
|
|
size_t tpInd;
|
|
|
|
Vector<size_t> hypoIndColl;
|
|
|
|
|
2016-08-17 15:34:29 +03:00
|
|
|
SeenPosition(MemPool &pool,
|
|
|
|
const SymbolBind &vSymbolBind,
|
2016-08-17 15:47:55 +03:00
|
|
|
const SCFG::TargetPhrases &vtps,
|
2016-08-17 15:34:29 +03:00
|
|
|
size_t numNT);
|
2016-08-17 15:03:23 +03:00
|
|
|
SeenPosition(MemPool &pool,
|
|
|
|
const SymbolBind &vSymbolBind,
|
2016-08-17 15:47:55 +03:00
|
|
|
const SCFG::TargetPhrases &vtps,
|
2016-08-17 15:03:23 +03:00
|
|
|
size_t vtpInd,
|
|
|
|
const Vector<size_t> &vhypoIndColl);
|
2016-06-15 12:49:24 +03:00
|
|
|
|
|
|
|
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;
|
2016-06-15 12:49:24 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
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:03:41 +03:00
|
|
|
|
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,
|
2016-06-03 16:14:48 +03:00
|
|
|
const SymbolBind &symbolBind,
|
|
|
|
const SCFG::TargetPhrases &tps,
|
2016-08-17 16:10:32 +03:00
|
|
|
size_t vTPInd,
|
|
|
|
const Vector<size_t> &hypoIndColl);
|
2016-06-23 14:54:43 +03:00
|
|
|
void AddHypos(const Moses2::Hypotheses &hypos);
|
2016-06-02 19:47:04 +03:00
|
|
|
void CreateHypo(
|
2016-06-28 17:18:38 +03:00
|
|
|
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(
|
2016-06-28 17:18:38 +03:00
|
|
|
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:
|
2016-06-23 14:54:43 +03:00
|
|
|
typedef Vector<const Moses2::Hypotheses *> HyposColl;
|
2016-06-24 22:13:26 +03:00
|
|
|
HyposColl *m_hyposColl;
|
2016-06-03 17:53:33 +03:00
|
|
|
|
2016-06-03 18:03:41 +03:00
|
|
|
const SymbolBind *symbolBind;
|
|
|
|
const SCFG::TargetPhrases *tps;
|
|
|
|
size_t tpInd;
|
|
|
|
|
2016-08-17 15:43:47 +03:00
|
|
|
const Vector<size_t> *m_hypoIndColl; // pointer to variable in seen position
|
2016-06-03 18:03:41 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|