00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Tanl_classifier_StreamTokenizer_H
00025 #define Tanl_classifier_StreamTokenizer_H
00026
00027 #include <fstream>
00028 #include <string>
00029 #include <vector>
00030
00031 #include "text/WordIndex.h"
00032
00033 #define MAX_LINE 1024
00034
00035 namespace Tanl {
00036 namespace Classifier {
00037
00041 class StreamTokenizer
00042 {
00043 public:
00044 StreamTokenizer() { }
00045 StreamTokenizer(std::ifstream& stream) :
00046 stream(&stream) { }
00047
00048 std::vector<char*> lineTokens(char const* delim);
00049
00050 protected:
00051 std::ifstream* stream;
00052 char line[MAX_LINE];
00053 };
00054
00058 class FileTokenizer : public StreamTokenizer
00059 {
00060 public:
00061 FileTokenizer(std::string file) :
00062 fname(file.c_str()), ifs(fname)
00063 {
00064 stream = &ifs;
00065 }
00066
00067 FileTokenizer(char const* fname) :
00068 fname(fname), ifs(fname)
00069 {
00070 stream = &ifs;
00071 }
00072
00073
00074 FileTokenizer(char const* fname, std::ifstream& ifs) :
00075 fname(fname)
00076 {
00077 stream = &ifs;
00078 }
00079
00080 int expectInt(char* s);
00081
00082 double expectDouble(char* s);
00083
00084 private:
00085 char const* fname;
00086 std::ifstream ifs;
00087 };
00088
00089 void readItems(char const* fname, Tanl::Text::WordIndex& hashtable);
00090
00091 }
00092 }
00093
00094 #endif // Tanl_classifier_StreamTokenizer_H