FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

Token.h

浏览该文件的文档。
00001 //
00002 // Copyright(C) 2005--2006 Institute of Computing Tech, Chinese Academy of Sciences. 
00003 // All rights reserved.
00004 // This file is part of FirteX (www.firtex.org)
00005 //
00006 // Use of the FirteX is subject to the terms of the software license set forth in 
00007 // the LICENSE file included with this software, and also available at
00008 // http://www.firtex.org/license.html
00009 //
00010 // Author       : 郭瑞杰(GuoRuijie)
00011 // Email        : ruijieguo@software.ict.ac.cn,ruijieguo@gmail.com
00012 // Created      : 2005/11/20
00013 //
00014 #ifndef _TOKEN_H
00015 #define _TOKEN_H
00016 
00017 #if _MSC_VER > 1000
00018 #pragma once
00019 #endif // _MSC_VER > 1000
00020 
00021 #include "../utility/StdHeader.h"
00022 #include "../utility/FXString.h"
00023 #include "../index/Term.h"
00024 using namespace firtex::utility;
00025 
00026 namespace firtex
00027 {
00028         namespace analyzer
00029         {
00030                 enum    TokenType
00031                 {
00032                         TOKEN_NONE              = 0x0,
00033                         TOKEN_WORD              = 0x01, //词
00034                         TOKEN_DATE              = 0x02, //时间日期
00035                         TOKEN_NAME              = 0x04, //人名
00036                         TOKEN_COMPANY   = 0x08, //机构名
00037                         TOKEN_EMAIL             = 0x10, //Email
00038                         TOKEN_NUM               = 0x20, //数字
00039                         TOKEN_ALPHA             = 0x40, //字母
00040                         TOKEN_ALPNUM    = 0x80, //数字字母组合
00041                         TOKEN_URL               = 0x100,//URL
00042                 };
00043 
00044                 class CToken
00045                 {
00046                 public:
00047                         CToken(void) : m_type(TOKEN_NONE),m_strValue(NULL)
00048                         {                               
00049                         }
00050                         CToken(TokenType type):m_type(type),m_strValue(NULL)
00051                         {
00052                         }
00053                         CToken(TokenType type,const tchar* value):m_type(type),m_strValue(new CFXString(value))
00054                         {
00055                         }
00056                         CToken(TokenType type,const tstring& value):m_type(type),m_strValue(new CFXString(value))
00057                         {
00058                         }
00059                         CToken(const CToken& clone)
00060                         {
00061                                 m_type = clone.m_type;
00062                                 if(clone.m_strValue)
00063                                         m_strValue = new CFXString(*(clone.m_strValue));
00064                                 else m_strValue = NULL;
00065                         }
00066                         virtual ~CToken(void)
00067                         {
00068                                 if(m_strValue)
00069                                 {
00070                                         delete m_strValue;
00071                                         m_strValue = NULL;
00072                                 }
00073                         }
00074                 public:
00075                         TokenType               getType(){return m_type;}
00076                         TokenType               setType(TokenType type){m_type = type;}
00077                         const tchar*    stringValue(){return ((m_strValue==NULL)?NULL:m_strValue->c_str());}
00078                         void                    stringValue(const tchar* value)
00079                         {
00080                                 if(m_strValue)
00081                                         *m_strValue = value;
00082                                 else m_strValue = new CFXString(value);
00083                         }
00084                         virtual CToken* asTokenX(){return this;}
00085                         virtual firtex::index::CTerm*   toTerm(const tchar* field){return new firtex::index::CTerm(field);}
00086                 protected:
00087                         TokenType       m_type;
00088                         CFXString*      m_strValue;
00089 
00090                         friend class CTokens;
00091                 };
00092 
00093                 template<typename TokenT>
00094                 class CTokenX : public CToken
00095                 {
00096                 public:
00097                         CTokenX(){}
00098                         CTokenX(TokenType type,TokenT value):CToken(type),m_value(value)
00099                         {
00100                         }
00101                         virtual ~CTokenX(){}
00102                 public:
00103                         TokenT                  getValue()const{return m_value;}
00104                         TokenT                  setValue(const TokenT value){m_value = value;}
00105                         CToken*                 asTokenX(){return this;}                        
00106                         firtex::index::CTerm*                   toTerm(const tchar* field){return new firtex::index::CTermX<TokenT>(field,m_value);}
00107                 private:
00108                         TokenT  m_value;
00109                 };
00110         }
00111 }
00112 
00113 #endif

http://www.firtex.org http://www.sourceforge.net/projects/firtex