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-02 14:58:29 +03:00
|
|
|
#include "../../HypothesisColl.h"
|
2016-06-03 17:53:33 +03:00
|
|
|
#include "../../Vector.h"
|
2016-06-02 15:57:29 +03:00
|
|
|
#include "../Hypothesis.h"
|
2016-06-02 14:58:29 +03:00
|
|
|
|
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace SCFG
|
|
|
|
{
|
|
|
|
class TargetPhrases;
|
2016-06-02 19:47:04 +03:00
|
|
|
class Queue;
|
2016-06-04 01:53:40 +03:00
|
|
|
class SeenPositions;
|
2016-06-02 14:58:29 +03:00
|
|
|
|
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,
|
|
|
|
const SCFG::TargetPhrases &tps);
|
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-06-03 17:53:33 +03:00
|
|
|
size_t vTPInd);
|
2016-06-02 14:58:29 +03:00
|
|
|
void AddHypos(const Moses2::HypothesisColl &hypos);
|
2016-06-02 19:47:04 +03:00
|
|
|
void CreateHypo(
|
2016-06-04 01:04:02 +03:00
|
|
|
MemPool &pool,
|
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-03 17:53:33 +03:00
|
|
|
MemPool &pool,
|
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-15 02:34:30 +03:00
|
|
|
void Debug(std::ostream &out, const System &system) const;
|
|
|
|
|
2016-06-03 17:53:33 +03:00
|
|
|
protected:
|
|
|
|
typedef Vector<const Moses2::HypothesisColl *> HyposColl;
|
|
|
|
HyposColl *m_hyposColl;
|
|
|
|
|
2016-06-03 18:03:41 +03:00
|
|
|
const SymbolBind *symbolBind;
|
|
|
|
const SCFG::TargetPhrases *tps;
|
|
|
|
size_t tpInd;
|
|
|
|
|
2016-06-03 18:19:22 +03:00
|
|
|
Vector<size_t> hypoIndColl;
|
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 00:25:54 +03:00
|
|
|
///////////////////////////////////////////
|
2016-06-15 03:05:35 +03:00
|
|
|
class SeenPosition
|
2016-06-04 00:25:54 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-06-15 02:47:00 +03:00
|
|
|
const SCFG::TargetPhrases *tps;
|
|
|
|
size_t tpInd;
|
2016-06-15 03:01:29 +03:00
|
|
|
Vector<size_t> hypoIndColl;
|
2016-06-04 00:25:54 +03:00
|
|
|
|
2016-06-15 03:05:35 +03:00
|
|
|
SeenPosition(MemPool &pool, const SCFG::TargetPhrases *vtps, size_t vtpInd, const Vector<size_t> &vhypoIndColl);
|
2016-06-04 01:53:40 +03:00
|
|
|
|
2016-06-15 03:05:35 +03:00
|
|
|
bool operator==(const SeenPosition &compare) const;
|
2016-06-14 23:30:12 +03:00
|
|
|
size_t hash() const;
|
2016-06-04 00:25:54 +03:00
|
|
|
|
2016-06-11 00:03:11 +03:00
|
|
|
void Debug(std::ostream &out, const System &system) const;
|
|
|
|
|
2016-06-04 00:25:54 +03:00
|
|
|
};
|
|
|
|
|
2016-06-04 03:14:46 +03:00
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
class SeenPositions
|
2016-06-04 01:53:40 +03:00
|
|
|
{
|
2016-06-04 03:14:46 +03:00
|
|
|
public:
|
2016-06-15 03:05:35 +03:00
|
|
|
bool Add(const SeenPosition *item);
|
2016-06-04 01:53:40 +03:00
|
|
|
|
2016-06-04 03:14:46 +03:00
|
|
|
void clear()
|
|
|
|
{ m_coll.clear(); }
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2016-06-15 03:05:35 +03:00
|
|
|
typedef boost::unordered_set<const SeenPosition*,
|
|
|
|
UnorderedComparer<SeenPosition>, UnorderedComparer<SeenPosition> > Coll;
|
2016-06-04 03:14:46 +03:00
|
|
|
Coll m_coll;
|
2016-06-04 01:53:40 +03:00
|
|
|
};
|
|
|
|
|
2016-06-02 14:58:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|