mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +03:00
d317fdc373
This mirrors the change made for the chart decoder in commit 465b4756...
63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <queue>
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
#include "SHyperedge.h"
|
|
#include "SHyperedgeBundle.h"
|
|
|
|
namespace Moses
|
|
{
|
|
namespace Syntax
|
|
{
|
|
|
|
// A cube -- in the cube pruning sense (see Chiang (2007)) -- that lazily
|
|
// produces SHyperedge objects from a SHyperedgeBundle in approximately
|
|
// best-first order.
|
|
class Cube
|
|
{
|
|
public:
|
|
Cube(const SHyperedgeBundle &);
|
|
~Cube();
|
|
|
|
SHyperedge *Pop();
|
|
|
|
SHyperedge *Top() const {
|
|
return m_queue.top().first;
|
|
}
|
|
|
|
bool IsEmpty() const {
|
|
return m_queue.empty();
|
|
}
|
|
|
|
private:
|
|
typedef boost::unordered_set<std::vector<int> > CoordinateSet;
|
|
|
|
typedef std::pair<SHyperedge *, const std::vector<int> *> QueueItem;
|
|
|
|
class QueueItemOrderer
|
|
{
|
|
public:
|
|
bool operator()(const QueueItem &p, const QueueItem &q) const {
|
|
return p.first->label.futureScore < q.first->label.futureScore;
|
|
}
|
|
};
|
|
|
|
typedef std::priority_queue<QueueItem, std::vector<QueueItem>,
|
|
QueueItemOrderer> Queue;
|
|
|
|
SHyperedge *CreateHyperedge(const std::vector<int> &);
|
|
void CreateNeighbour(const std::vector<int> &);
|
|
void CreateNeighbours(const std::vector<int> &);
|
|
|
|
const SHyperedgeBundle &m_bundle;
|
|
CoordinateSet m_visited;
|
|
Queue m_queue;
|
|
};
|
|
|
|
} // Syntax
|
|
} // Moses
|