File size: 3,026 Bytes
158b61b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
/*
* Misc.h
*
* Created on: 2 Jun 2016
* Author: hieu
*/
#pragma once
#include <vector>
#include <queue>
#include <boost/unordered_set.hpp>
#include "../HypothesisColl.h"
#include "../Vector.h"
#include "Hypothesis.h"
namespace Moses2
{
namespace SCFG
{
class SymbolBind;
class TargetPhrases;
class Queue;
///////////////////////////////////////////
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;
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;
};
///////////////////////////////////////////
class QueueItem
{
public:
SCFG::Hypothesis *hypo;
static QueueItem *Create(MemPool &pool, SCFG::Manager &mgr);
void Init(
MemPool &pool,
const SymbolBind &symbolBind,
const SCFG::TargetPhrases &tps,
const Vector<size_t> &hypoIndColl);
void Init(
MemPool &pool,
const SymbolBind &symbolBind,
const SCFG::TargetPhrases &tps,
size_t vTPInd,
const Vector<size_t> &hypoIndColl);
void AddHypos(const Moses2::Hypotheses &hypos);
void CreateHypo(
MemPool &systemPool,
SCFG::Manager &mgr,
const SCFG::InputPath &path,
const SCFG::SymbolBind &symbolBind);
void CreateNext(
MemPool &systemPool,
MemPool &mgrPool,
SCFG::Manager &mgr,
SCFG::Queue &queue,
SeenPositions &seenPositions,
const SCFG::InputPath &path);
std::string Debug(const System &system) const;
protected:
typedef Vector<const Moses2::Hypotheses *> HyposColl;
HyposColl *m_hyposColl;
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
QueueItem(MemPool &pool);
};
///////////////////////////////////////////
typedef std::deque<QueueItem*> QueueItemRecycler;
///////////////////////////////////////////
class QueueItemOrderer
{
public:
bool operator()(QueueItem* itemA, QueueItem* itemB) const {
HypothesisFutureScoreOrderer orderer;
return !orderer(itemA->hypo, itemB->hypo);
}
};
///////////////////////////////////////////
class Queue : public std::priority_queue<QueueItem*,
std::vector<QueueItem*>,
QueueItemOrderer>
{
};
}
}
|