comparison dfa.h @ 3:70e2c306231e

- implemented dfa utility functions. - added dfa.c. - rewrote guess functions for ar, gr, hw and tr scripts with dfa utilities. - guess functions for cjk scripts too.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 12 Jun 2008 20:20:43 +0900
parents 754a4550c64e
children
comparison
equal deleted inserted replaced
2:754a4550c64e 3:70e2c306231e
1 #ifndef __DFA_H__ 1 #ifndef __DFA_H__
2 #define __DFA_H__ 2 #define __DFA_H__
3
4 typedef int boolean;
5 #define TRUE 1
6 #define FALSE 0
7
8 /* workaround for that glib's g_convert can't convert
9 properly from UCS-2BE/LE trailing after BOM. */
10 #define WITH_G_CONVERT 1
11 /* #undef WITH_G_CONVERT */
12
13 #ifdef WITH_G_CONVERT
14 #define UCS_2BE "UTF-16"
15 #define UCS_2LE "UTF-16"
16 #else
17 #define UCS_2BE "UCS_2BE"
18 #define UCS_2LE "UCS_2LE"
19 #endif
3 20
4 /* data types */ 21 /* data types */
5 typedef struct guess_arc_rec 22 typedef struct guess_arc_rec
6 { 23 {
7 unsigned int next; /* next state */ 24 unsigned int next; /* next state */
12 { 29 {
13 signed char (*states)[256]; 30 signed char (*states)[256];
14 guess_arc *arcs; 31 guess_arc *arcs;
15 int state; 32 int state;
16 double score; 33 double score;
34 char *name;
17 } guess_dfa; 35 } guess_dfa;
18 36
19 /* macros */ 37 /* macros */
20 #define DFA_INIT(st, ar) \ 38 #define DFA_INIT(st, ar, name) \
21 { st, ar, 0, 1.0 } 39 { st, ar, 0, 1.0 ,name}
22 40
23 #define DFA_NEXT(dfa, ch) \ 41 #define DFA_NEXT(dfa, ch) \
24 do { \ 42 do { \
25 int arc__; \ 43 int arc__; \
26 if (dfa.state >= 0) { \ 44 if (dfa.state >= 0) { \
34 } \ 52 } \
35 } while (0) 53 } while (0)
36 54
37 #define DFA_ALIVE(dfa) (dfa.state >= 0) 55 #define DFA_ALIVE(dfa) (dfa.state >= 0)
38 56
57 #define DFA_NEXT_P(dfa, ch) \
58 do { \
59 int arc__; \
60 if (dfa->state >= 0) { \
61 arc__ = dfa->states[dfa->state][ch]; \
62 if (arc__ < 0) { \
63 dfa->state = -1; \
64 } else { \
65 dfa->state = dfa->arcs[arc__].next; \
66 dfa->score *= dfa->arcs[arc__].score; \
67 } \
68 } \
69 } while (0)
70
71 #define DFA_ALIVE_P(dfa) (dfa->state >= 0)
72
73 /* prototypes */
74 boolean dfa_alone(guess_dfa *dfa, guess_dfa *order[]);
75 boolean dfa_none(guess_dfa *order[]);
76 guess_dfa *dfa_top(guess_dfa *order[]);
77 const char *dfa_process(guess_dfa *order[], int c);
78
39 #endif 79 #endif