Natural Language Processing  0.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
token.h
1 #ifndef TOKEN_H
2 #define TOKEN_H
3 
4 #include <string>
5 #include <iostream>
6 #include <iomanip>
7 #include <algorithm>
8 #include <map>
9 
10 void testToken();//NOTE: Because this file has implementation .cpp,
11  // The implementation need to be separated
12 
13 using namespace std;
14 
15 enum TokenType {
16  UNKNOWN = -1,
17  NONE = 0,
18  WHITESPACE = 1,
19  EOL = 2,
20  ALPHA = 3,
21  NUM = 4,
22  OPERATOR = 5,
23  PUNC = 6,
24  MATCHED = 7,
25  QUESTION
26 };
27 //bool operator == (const TokenType& l, const TokenType& r) { return l == r; }
28 
29 static map<TokenType, string> TokenName = {
30  {UNKNOWN, "UNKNOWN"},
31  {NONE, "NONE"},
32  {WHITESPACE, "WHITESPACE"},
33  {EOL, "EOL"},
34  {ALPHA, "ALPHA"},
35  {NUM, "NUM"},
36  {OPERATOR, "OPERATOR"},
37  {PUNC, "PUNC"},
38  {MATCHED, "MATCHED"},
39  {QUESTION, "QUESTION"}
40 };
41 
42 class Token
43 {
44  protected:
45  string mTokenString;
46  TokenType mType;
47 
48  public:
49  Token();
50  Token(const Token& other);
51  Token(string s, TokenType type);
52  Token(char ch, TokenType type);
53  TokenType getType() const;
54  string getTokenString() const;
55 
57  void alltolower();
58 
59  Token& operator = (const Token& newToken);
60  const string& operator * ();
61  friend ostream& operator << (ostream& outs, const Token& t)
62  {
63  outs << left << setw(10) << t.mTokenString << ": " << TokenName[t.mType];
64  return outs;
65  }
66 
67  ~Token();
68 };
69 
70 #endif // TOKEN_H
Definition: token.h:42