|
FreeLing
3.0
|
00001 00002 // 00003 // FreeLing - Open Source Language Analyzers 00004 // 00005 // Copyright (C) 2004 TALP Research Center 00006 // Universitat Politecnica de Catalunya 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 3 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 // 00022 // contact: Lluis Padro (padro@lsi.upc.es) 00023 // TALP Research Center 00024 // despatx C6.212 - Campus Nord UPC 00025 // 08034 Barcelona. SPAIN 00026 // 00028 00030 // 00031 // Author: Stanilovsky Evgeny 00032 // 00034 00035 #ifndef _PREF_TREE_H_ 00036 #define _PREF_TREE_H_ 00037 00038 #include <string> 00039 00041 // Class List is auxiliary to PrefTree 00043 00044 class List { 00045 public: 00046 struct ListRecBase { 00047 ListRecBase(): next(NULL), nextList(NULL) {} 00048 ListRecBase(wchar_t c): symb(c), next(NULL), nextList(NULL) {} 00049 virtual ~ListRecBase() {} 00050 wchar_t symb; 00051 ListRecBase *next; 00052 List *nextList; 00053 }; 00054 00055 struct ListRec: public ListRecBase { 00056 ListRec(): ListRecBase() {} 00057 ListRec(wchar_t c): ListRecBase(c) {} 00058 virtual ~ListRec() {}; 00059 }; 00060 00061 struct ListRecEnd: public ListRecBase { 00062 ListRecEnd(): ListRecBase() {} 00063 ListRecEnd(wchar_t c): ListRecBase(c) {} 00064 }; 00065 00066 struct ListRecData: public ListRecBase { 00067 ListRecData(): ListRecBase() {} 00068 ListRecData(wchar_t c): ListRecBase(c) {} 00069 std::wstring value; 00070 }; 00071 00072 List(): begin(0), end(0) {} 00073 inline ListRecBase *find(const wchar_t c); 00074 List *push(const wchar_t c, bool wordEnd = false, const std::wstring *data = NULL); 00075 virtual ~List(); 00076 00077 private: 00078 ListRecBase *begin, *end; 00079 }; 00080 00082 // Class PrefTree implements a prefix Tree index 00084 00085 class PrefTree { 00086 private: 00087 List *root; 00088 00089 public: 00090 PrefTree() { root = new List(); } 00091 ~PrefTree() { delete root; } 00092 void addWord(const wchar_t *word, const std::wstring &data); 00093 void addWordData(const wchar_t *word, const std::wstring &); 00094 List::ListRecBase *findWord(const wchar_t *) const; 00095 std::wstring *find(const wchar_t *word) const; 00096 bool deleteWord(const wchar_t *); 00097 }; 00098 00099 #endif
1.7.6.1