blob: 62163144feff1c46e32686bc0228c08b5169e6bc (
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
|
#ifndef SEARCH_CONTEXT__
#define SEARCH_CONTEXT__
#include "lm/model.hh"
#include "search/config.hh"
#include "search/final.hh"
#include "search/types.hh"
#include "search/vertex.hh"
#include "util/exception.hh"
#include "util/pool.hh"
#include <boost/pool/object_pool.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <vector>
namespace search {
class Weights;
class ContextBase {
public:
explicit ContextBase(const Config &config) : pop_limit_(config.PopLimit()), weights_(config.GetWeights()) {}
util::Pool &FinalPool() {
return final_pool_;
}
VertexNode *NewVertexNode() {
VertexNode *ret = vertex_node_pool_.construct();
assert(ret);
return ret;
}
void DeleteVertexNode(VertexNode *node) {
vertex_node_pool_.destroy(node);
}
unsigned int PopLimit() const { return pop_limit_; }
const Weights &GetWeights() const { return weights_; }
private:
util::Pool final_pool_;
boost::object_pool<VertexNode> vertex_node_pool_;
unsigned int pop_limit_;
const Weights &weights_;
};
template <class Model> class Context : public ContextBase {
public:
Context(const Config &config, const Model &model) : ContextBase(config), model_(model) {}
const Model &LanguageModel() const { return model_; }
private:
const Model &model_;
};
} // namespace search
#endif // SEARCH_CONTEXT__
|