summaryrefslogtreecommitdiff
path: root/klm/lm/filter/arpa_io.hh
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2013-01-20 12:31:03 +0000
committerKenneth Heafield <github@kheafield.com>2013-01-20 12:31:03 +0000
commitdc16aa2accc7d9033d9c31c7bbc5e581d43a5101 (patch)
tree7ee4b4155447607ad8f0a0e9f8226199403ed77f /klm/lm/filter/arpa_io.hh
parentc18c2497707bed72ace95db459e541261213c7e2 (diff)
Better delimiters, cross-platform fixes
Diffstat (limited to 'klm/lm/filter/arpa_io.hh')
-rw-r--r--klm/lm/filter/arpa_io.hh27
1 files changed, 10 insertions, 17 deletions
diff --git a/klm/lm/filter/arpa_io.hh b/klm/lm/filter/arpa_io.hh
index 90f48447..5b31620b 100644
--- a/klm/lm/filter/arpa_io.hh
+++ b/klm/lm/filter/arpa_io.hh
@@ -16,6 +16,7 @@
#include <err.h>
#include <string.h>
+#include <stdint.h>
namespace util { class FilePiece; }
@@ -25,34 +26,26 @@ class ARPAInputException : public util::Exception {
public:
explicit ARPAInputException(const StringPiece &message) throw();
explicit ARPAInputException(const StringPiece &message, const StringPiece &line) throw();
- virtual ~ARPAInputException() throw() {}
-
- const char *what() const throw() { return what_.c_str(); }
-
- private:
- std::string what_;
+ virtual ~ARPAInputException() throw();
};
-class ARPAOutputException : public std::exception {
+class ARPAOutputException : public util::ErrnoException {
public:
ARPAOutputException(const char *prefix, const std::string &file_name) throw();
- virtual ~ARPAOutputException() throw() {}
-
- const char *what() const throw() { return what_.c_str(); }
+ virtual ~ARPAOutputException() throw();
const std::string &File() const throw() { return file_name_; }
private:
- std::string what_;
const std::string file_name_;
};
// Handling for the counts of n-grams at the beginning of ARPA files.
-size_t SizeNeededForCounts(const std::vector<size_t> &number);
+size_t SizeNeededForCounts(const std::vector<uint64_t> &number);
/* Writes an ARPA file. This has to be seekable so the counts can be written
* at the end. Hence, I just have it own a std::fstream instead of accepting
- * a separately held std::ostream.
+ * a separately held std::ostream. TODO: use the fast one from estimation.
*/
class ARPAOutput : boost::noncopyable {
public:
@@ -88,14 +81,14 @@ class ARPAOutput : boost::noncopyable {
boost::scoped_array<char> buffer_;
std::fstream file_;
size_t fast_counter_;
- std::vector<size_t> counts_;
+ std::vector<uint64_t> counts_;
};
-template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, size_t number, Output &out) {
+template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, uint64_t number, Output &out) {
ReadNGramHeader(in, length);
out.BeginLength(length);
- for (size_t i = 0; i < number; ++i) {
+ for (uint64_t i = 0; i < number; ++i) {
StringPiece line = in.ReadLine();
util::TokenIter<util::SingleCharacter> tabber(line, '\t');
if (!tabber) throw ARPAInputException("blank line", line);
@@ -107,7 +100,7 @@ template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length
}
template <class Output> void ReadARPA(util::FilePiece &in_lm, Output &out) {
- std::vector<size_t> number;
+ std::vector<uint64_t> number;
ReadARPACounts(in_lm, number);
out.ReserveForCounts(SizeNeededForCounts(number));
for (unsigned int i = 0; i < number.size(); ++i) {