diff options
author | Barry Haddow <barry.haddow@gmail.com> | 2011-11-15 17:12:14 +0400 |
---|---|---|
committer | Barry Haddow <barry.haddow@gmail.com> | 2011-11-15 17:12:14 +0400 |
commit | 0a2e0f44a6d5fa2755b6f3894a55aa608272987d (patch) | |
tree | 2408a5149de4070a9ea57a1696630cca50ab34c5 /mert/FeatureDataIterator.h | |
parent | 3a6c0e0680e656a9a05da24c1b54e54caf651f48 (diff) |
Finish and test feature and score data iterators.
Diffstat (limited to 'mert/FeatureDataIterator.h')
-rw-r--r-- | mert/FeatureDataIterator.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/mert/FeatureDataIterator.h b/mert/FeatureDataIterator.h index 49d77f77f..6df249822 100644 --- a/mert/FeatureDataIterator.h +++ b/mert/FeatureDataIterator.h @@ -1,6 +1,3 @@ -// $Id$ -// vim:tabstop=2 - /*********************************************************************** Moses - factored phrase-based language decoder Copyright (C) 2011- University of Edinburgh @@ -29,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <fstream> #include <map> -#include <memory> #include <stdexcept> #include <vector> @@ -37,23 +33,34 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <boost/shared_ptr.hpp> #include "util/file_piece.hh" +#include "util/string_piece.hh" #include "FeatureStats.h" -class FeatureDataItem { - public: - std::vector<float> dense; - SparseVector sparse; -}; - -class FileFormatException : public util::Exception { +class FileFormatException : public util::Exception +{ public: explicit FileFormatException(const std::string filename, const std::string& line) { *this << "Error in line \"" << line << "\" of " << filename; } }; + +/** Assumes a delimiter, so only apply to tokens */ +int ParseInt(const StringPiece& str ); + +/** Assumes a delimiter, so only apply to tokens */ +float ParseFloat(const StringPiece& str); + + +class FeatureDataItem +{ + public: + std::vector<float> dense; + SparseVector sparse; +}; + class FeatureDataIterator : public boost::iterator_facade<FeatureDataIterator, const std::vector<FeatureDataItem>, @@ -61,7 +68,7 @@ class FeatureDataIterator : { public: FeatureDataIterator(); - FeatureDataIterator(const std::string filename); + FeatureDataIterator(const std::string& filename); static FeatureDataIterator end() { return FeatureDataIterator(); |