Home | History | Annotate | Download | only in slm
      1   0  yongsun /*
      2  82  yongsun  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
      3  82  yongsun  *
      4  82  yongsun  * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
      5  82  yongsun  *
      6  82  yongsun  * The contents of this file are subject to the terms of either the GNU Lesser
      7  82  yongsun  * General Public License Version 2.1 only ("LGPL") or the Common Development and
      8  82  yongsun  * Distribution License ("CDDL")(collectively, the "License"). You may not use this
      9  82  yongsun  * file except in compliance with the License. You can obtain a copy of the CDDL at
     10  82  yongsun  * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
     11  82  yongsun  * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
     12  82  yongsun  * specific language governing permissions and limitations under the License. When
     13  82  yongsun  * distributing the software, include this License Header Notice in each file and
     14  82  yongsun  * include the full text of the License in the License file as well as the
     15  82  yongsun  * following notice:
     16  82  yongsun  *
     17  82  yongsun  * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
     18  82  yongsun  * (CDDL)
     19  82  yongsun  * For Covered Software in this distribution, this License shall be governed by the
     20  82  yongsun  * laws of the State of California (excluding conflict-of-law provisions).
     21  82  yongsun  * Any litigation relating to this License shall be subject to the jurisdiction of
     22  82  yongsun  * the Federal Courts of the Northern District of California and the state courts
     23  82  yongsun  * of the State of California, with venue lying in Santa Clara County, California.
     24  82  yongsun  *
     25  82  yongsun  * Contributor(s):
     26  82  yongsun  *
     27  82  yongsun  * If you wish your version of this file to be governed by only the CDDL or only
     28  82  yongsun  * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
     29  82  yongsun  * include this software in this distribution under the [CDDL or LGPL Version 2.1]
     30  82  yongsun  * license." If you don't indicate a single choice of license, a recipient has the
     31  82  yongsun  * option to distribute your version of this file under either the CDDL or the LGPL
     32  82  yongsun  * Version 2.1, or to extend the choice of license to its licensees as provided
     33  82  yongsun  * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
     34  82  yongsun  * Version 2 license, then the option applies only if the new code is made subject
     35  82  yongsun  * to such option by the copyright holder.
     36   0  yongsun  */
     37  82  yongsun 
     38   0  yongsun #ifndef _SunAGCIM_Dict_H_
     39   0  yongsun #define _SunAGCIM_Dict_H_
     40   0  yongsun 
     41   0  yongsun #include "../portability.h"
     42   0  yongsun 
     43   0  yongsun #include <map>
     44   0  yongsun #include <string>
     45   0  yongsun 
     46   0  yongsun class CSIMDict {
     47   0  yongsun public:
     48   0  yongsun         struct TState;
     49   0  yongsun         typedef const TState * PState;
     50   0  yongsun         struct TState {
     51   0  yongsun                 TSIMWordId word_id;
     52   0  yongsun                 std::map<TSIMChar, TState>* follow;
     53   0  yongsun                 TState(TSIMWordId wid=SIM_ID_NOT_WORD) : word_id(wid), follow(NULL) { }
     54   0  yongsun         };
     55   0  yongsun         typedef std::map<TSIMChar, TState> Map_Type;
     56   0  yongsun 
     57   0  yongsun         CSIMDict() : m_root() {}
     58   0  yongsun         ~CSIMDict() { close(); }
     59   0  yongsun 
     60   0  yongsun         bool parseText(const char* filename);
     61   0  yongsun         void close(){ freeSubTree(m_root); m_root = TState(); }
     62   0  yongsun 
     63   0  yongsun         const TState* getRoot() const { return &m_root; }
     64   0  yongsun         int	matchLongest(const CSIMDict::TState* root, CSIMDict::PState &  result, const TWCHAR* str);
     65   0  yongsun 
     66   0  yongsun         static const TState* step(const CSIMDict::TState* root, TWCHAR wch);
     67   0  yongsun         void PrintOut(FILE* fp) { wstring ws; InnerPrint(fp, ws, getRoot()); }
     68   0  yongsun 
     69   0  yongsun protected:
     70   0  yongsun         TState m_root;
     71   0  yongsun 
     72   0  yongsun protected:
     73   0  yongsun         void freeSubTree(TState& root);
     74   0  yongsun         void insertWord(const TWCHAR* wstr, TSIMWordId id);
     75   0  yongsun         void InnerPrint(FILE* fp, wstring & wstr, const TState* pnode);
     76   0  yongsun };
     77   0  yongsun 
     78   0  yongsun #endif
     79