Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Misc.h « CubePruningBitmapStack « defer « moses2 « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00f3fa86568e75b1d223583c616bd0ee5e40ca47 (plain)
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
/*
 * CubePruning.h
 *
 *  Created on: 27 Nov 2015
 *      Author: hieu
 */
#pragma once
#include <boost/pool/pool_alloc.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <vector>
#include <queue>
#include "../../legacy/Range.h"
#include "../Hypothesis.h"
#include "../../TypeDef.h"
#include "../../Vector.h"
#include "Stack.h"

namespace Moses2
{

class Manager;
class InputPath;
class TargetPhrases;
class Bitmap;

namespace NSCubePruningBitmapStack
{
class CubeEdge;

///////////////////////////////////////////
class QueueItem
{
	~QueueItem(); // NOT IMPLEMENTED. Use MemPool
public:
	static QueueItem *Create(QueueItem *currItem,
			Manager &mgr,
			CubeEdge &edge,
			size_t hypoIndex,
			size_t tpIndex,
			std::deque<QueueItem*> &queueItemRecycler);
	QueueItem(Manager &mgr, CubeEdge &edge, size_t hypoIndex, size_t tpIndex);

	void Init(Manager &mgr, CubeEdge &edge, size_t hypoIndex, size_t tpIndex);

	CubeEdge *edge;
	size_t hypoIndex, tpIndex;
	Hypothesis *hypo;

protected:
	void CreateHypothesis(Manager &mgr);
};

///////////////////////////////////////////
class QueueItemOrderer
{
public:
  bool operator()(QueueItem* itemA, QueueItem* itemB) const {
	  HypothesisFutureScoreOrderer orderer;
	  return !orderer(itemA->hypo, itemB->hypo);
  }
};

///////////////////////////////////////////
class CubeEdge
{
  friend std::ostream& operator<<(std::ostream &, const CubeEdge &);

public:
	typedef std::priority_queue<QueueItem*,
				std::vector<QueueItem*>,
				QueueItemOrderer> Queue;

	typedef std::pair<const CubeEdge*, int> SeenPositionItem;
	typedef boost::unordered_set<SeenPositionItem,
			boost::hash<SeenPositionItem>,
			std::equal_to<SeenPositionItem> > SeenPositions;

	const Hypotheses &hypos;
	const InputPath &path;
	const TargetPhrases &tps;
	const Bitmap &newBitmap;
	SCORE estimatedScore;

	CubeEdge(Manager &mgr,
			const Hypotheses &hypos,
			const InputPath &path,
			const TargetPhrases &tps,
			const Bitmap &newBitmap);

  bool SetSeenPosition(const size_t x, const size_t y, SeenPositions &seenPositions) const;

  void CreateFirst(Manager &mgr,
		  Queue &queue,
		  SeenPositions &seenPositions,
		  std::deque<QueueItem*> &queueItemRecycler);
  void CreateNext(Manager &mgr,
		  QueueItem *item,
		  Queue &queue,
		  SeenPositions &seenPositions,
		  std::deque<QueueItem*> &queueItemRecycler);

protected:

};

}

}