Remove Owner class

This commit is contained in:
Kenneth Heafield 2012-10-15 06:43:43 -04:00
parent 0265725c03
commit ed00315c8c
5 changed files with 12 additions and 33 deletions

View File

@ -1,6 +1,5 @@
#include "Incremental/Fill.h"
#include "Incremental/Owner.h"
#include "ChartCellLabel.h"
#include "ChartCellLabelSet.h"
#include "TargetPhraseCollection.h"
@ -18,8 +17,8 @@
namespace Moses {
namespace Incremental {
template <class Model> Fill<Model>::Fill(search::Context<Model> &context, const std::vector<lm::WordIndex> &vocab_mapping, Owner &owner)
: context_(context), vocab_mapping_(vocab_mapping), owner_(owner), edges_(context.PopLimit()) {}
template <class Model> Fill<Model>::Fill(search::Context<Model> &context, const std::vector<lm::WordIndex> &vocab_mapping)
: context_(context), vocab_mapping_(vocab_mapping), edges_(context.PopLimit()) {}
template <class Model> void Fill<Model>::Add(const TargetPhraseCollection &targets, const StackVec &nts, const WordsRange &) {
const unsigned char arity = nts.size();
@ -124,8 +123,8 @@ class HypothesisCallback {
};
} // namespace
template <class Model> void Fill<Model>::Search(ChartCellLabelSet &out) {
HypothesisCallback callback(context_, out, owner_.VertexPool());
template <class Model> void Fill<Model>::Search(ChartCellLabelSet &out, boost::object_pool<search::Vertex> &vertex_pool) {
HypothesisCallback callback(context_, out, vertex_pool);
edges_.Search(context_, callback);
}

View File

@ -13,6 +13,7 @@
namespace search {
template <class Model> class Context;
class Vertex;
} // namespace search
namespace Moses {
@ -24,13 +25,12 @@ class ChartCellLabelSet;
class TargetPhrase;
namespace Incremental {
class Owner;
// Replacement for ChartTranslationOptionList
// TODO: implement count and score thresholding.
template <class Model> class Fill : public ChartParserCallback {
public:
Fill(search::Context<Model> &context, const std::vector<lm::WordIndex> &vocab_mapping, Owner &owner);
Fill(search::Context<Model> &context, const std::vector<lm::WordIndex> &vocab_mapping);
void Add(const TargetPhraseCollection &targets, const StackVec &nts, const WordsRange &ignored);
@ -38,7 +38,7 @@ template <class Model> class Fill : public ChartParserCallback {
bool Empty() const { return edges_.Empty(); }
void Search(ChartCellLabelSet &out);
void Search(ChartCellLabelSet &out, boost::object_pool<search::Vertex> &vertex_pool);
private:
lm::WordIndex Convert(const Word &word) const ;
@ -47,8 +47,6 @@ template <class Model> class Fill : public ChartParserCallback {
const std::vector<lm::WordIndex> &vocab_mapping_;
Owner &owner_;
search::EdgeQueue edges_;
};

View File

@ -89,13 +89,16 @@ template <class Model> void Manager::LMCallback(const Model &model, const std::v
search::Context<Model> context(config, model);
size_t size = source_.GetSize();
boost::object_pool<search::Vertex> vertex_pool(std::max<size_t>(size * size / 2, 32));
for (size_t width = 1; width <= size; ++width) {
for (size_t startPos = 0; startPos <= size-width; ++startPos) {
size_t endPos = startPos + width - 1;
WordsRange range(startPos, endPos);
Fill<Model> filler(context, words, owner_);
Fill<Model> filler(context, words);
parser_.Create(range, filler);
filler.Search(cells_.MutableBase(range).MutableTargetLabelSet());
filler.Search(cells_.MutableBase(range).MutableTargetLabelSet(), vertex_pool);
}
}
BestString(cells_.GetBase(WordsRange(0, source_.GetSize() - 1)).GetTargetLabelSet(), output_);

View File

@ -4,7 +4,6 @@
#include "ChartCellCollection.h"
#include "ChartParser.h"
#include "Incremental/Owner.h"
namespace Moses {
class InputType;
@ -28,7 +27,6 @@ class Manager {
const TranslationSystem &system_;
ChartCellCollectionBase cells_;
ChartParser parser_;
Owner owner_;
std::string output_;
};

View File

@ -1,19 +0,0 @@
#pragma once
#include "search/vertex.hh"
#include <boost/pool/object_pool.hpp>
namespace Moses {
namespace Incremental {
class Owner {
public:
boost::object_pool<search::Vertex> &VertexPool() { return vertices_; }
private:
boost::object_pool<search::Vertex> vertices_;
};
} // namespace Incremental
} // namespace Moses