|
#ifndef LM_COMMON_MODEL_BUFFER_H |
|
#define LM_COMMON_MODEL_BUFFER_H |
|
|
|
|
|
|
|
|
|
#include "../word_index.hh" |
|
#include "../../util/file.hh" |
|
#include "../../util/fixed_array.hh" |
|
#include "../../util/string_piece.hh" |
|
|
|
#include <string> |
|
#include <vector> |
|
|
|
namespace util { namespace stream { |
|
class Chains; |
|
class Chain; |
|
}} |
|
|
|
namespace lm { |
|
|
|
namespace ngram { class State; } |
|
|
|
class ModelBuffer { |
|
public: |
|
|
|
ModelBuffer(StringPiece file_base, bool keep_buffer, bool output_q); |
|
|
|
|
|
explicit ModelBuffer(StringPiece file_base); |
|
|
|
|
|
void Sink(util::stream::Chains &chains, const std::vector<uint64_t> &counts); |
|
|
|
|
|
|
|
void Source(util::stream::Chains &chains); |
|
|
|
void Source(std::size_t order_minus_1, util::stream::Chain &chain); |
|
|
|
|
|
std::size_t Order() const { return counts_.size(); } |
|
|
|
const std::vector<uint64_t> &Counts() const { |
|
assert(!counts_.empty()); |
|
return counts_; |
|
} |
|
|
|
int VocabFile() const { return vocab_file_.get(); } |
|
|
|
int RawFile(std::size_t order_minus_1) const { |
|
return files_[order_minus_1].get(); |
|
} |
|
|
|
bool Keep() const { return keep_buffer_; } |
|
|
|
|
|
|
|
|
|
float SlowQuery(const ngram::State &context, WordIndex word, ngram::State &out) const; |
|
|
|
private: |
|
const std::string file_base_; |
|
const bool keep_buffer_; |
|
bool output_q_; |
|
std::vector<uint64_t> counts_; |
|
|
|
util::scoped_fd vocab_file_; |
|
util::FixedArray<util::scoped_fd> files_; |
|
}; |
|
|
|
} |
|
|
|
#endif |
|
|