source: src/lem_utf8/lemfst.h @ 5f4d9c3

Last change on this file since 5f4d9c3 was 5f4d9c3, checked in by Maciej Prill <mprill@…>, 12 years ago

Rewritten the build system, added lem UTF-8 version.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#ifndef __LemFST
2#define __LemFST
3
4#include <fst/fst.h>
5#include <list>
6#include <wchar.h>
7
8#define fstMAXPATH 100
9using namespace fst;
10class LemFST
11{
12public:
13        LemFST(const char*);
14        ~LemFST(void);
15
16
17//////////////////////////////////////////////////////////////////////////////
18        typedef StdFst::Arc::Label Char; // Pojedynczy znak
19        typedef StdFst::StateId State; // Stan
20       
21        typedef std::list<Char> Word; // Lista znakow.
22        typedef std::list<Char>::iterator WordIt; // Iterator po lisice znakow
23
24
25        typedef ArcIterator<StdFst> ArcsIt; // Iterator po krawedziach
26        typedef struct {
27                ArcsIt* it;             // Krawedzie wychodzace (Iterator)
28                State id;               // Numer stanu
29                State prev;             // Poprzednik stanu
30                Char symbol;    // Symbol po jakim przeszlismy z prev do id
31                bool checked;   // Czy stan byl juz brany pod uwage jako koncowy
32        } StateInfo;
33
34        typedef std::list<StateInfo> Path;      // Sciezka stanow (wlasc. stos)
35        typedef Path::iterator PathIt;          // Iterator po Sciezce
36        typedef Path::reverse_iterator PathRevIt; // Odwrotny iterator po Scieze
37       
38       
39        // Operacje na automacie:
40        StdFst *fst; // Automat LEMa
41        State start();
42        bool accept(State);
43        State next(State, Char); // Go to next state by Char
44        State next(State, Word); // Go to end of the Word
45
46
47
48
49
50        // Przeszukiwanie automatu:
51        Path path;
52    long cont(State, Word*, int); // Return a path from state to finish state;
53
54
55
56        // Pomocnicze:
57        inline const StateInfo getStateInfo(State, State, Char);
58
59
60        static const State noStateId = fst::kNoStateId;
61
62        /** Zwraca ciag wchar_t zbudowany ze slowa w */
63        inline static char* wordToChar(Word* w) {
64                int len = w->size();
65                WordIt it;
66                char* ret = new char[len+1];
67                int i=0;
68                for(it=w->begin(); it!=w->end(); it++) {
69                        ret[i++] = static_cast<char>(*it);
70                }
71                ret[i]='\0';
72                return ret;
73        }
74
75    /** Zwraca ciag wchar_t zbudowany ze slowa w */
76        inline static wchar_t* wordToWChar(Word* w) {
77                int len = w->size();
78                WordIt it;
79                wchar_t* ret = new wchar_t[len+1];
80                int i=0;
81                for(it=w->begin(); it!=w->end(); it++) {
82                        ret[i++] = static_cast<wchar_t>(*it);
83                }
84                ret[i]=L'\0';
85                return ret;
86        }
87
88
89
90        /** Zwraca slowo Word* na podstawie ciagu wchar_t */
91        inline static Word* charToWord(const wchar_t* ch) {
92                int i =0;
93                Word *w = new Word();
94                for(; ch[i]!=L'\0'; i++)  {
95                        w->push_back((int)ch[i]);
96                }
97                return w;
98        }
99   
100    /** Zwraca slowo Word* na podstawie ciagu wchar_t */
101        inline static Word* charToWord(const char* ch) {
102                int i =0;
103                Word *w = new Word();
104                for(; ch[i]!='\0'; i++)  {
105                        w->push_back((int)ch[i]);
106                }
107                return w;
108        }
109
110};
111
112#endif
Note: See TracBrowser for help on using the repository browser.