comparison dfa.c @ 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
children
comparison
equal deleted inserted replaced
2:754a4550c64e 3:70e2c306231e
1 #include "libguess.h"
2 #include "dfa.h"
3
4 boolean
5 dfa_alone(guess_dfa *dfa, guess_dfa *order[])
6 {
7 int i;
8
9 if (dfa->state < 0)
10 return FALSE;
11
12 for (i = 0; order[i] != NULL; i++) {
13 if (order[i] != dfa && order[i]->state >= 0) { //DFA_ALIVE()
14 return FALSE;
15 }
16 }
17
18 return TRUE;
19 }
20
21 boolean
22 dfa_none(guess_dfa *order[])
23 {
24 int i;
25
26 for (i = 0; order[i] != NULL; i++) {
27 if (order[i]->state >= 0) { //DFA_ALIVE()
28 return FALSE;
29 }
30 }
31
32 return TRUE;
33 }
34
35 guess_dfa *
36 dfa_top(guess_dfa *order[])
37 {
38 int i;
39 guess_dfa *top = NULL;
40 for (i = 0; order[i] != NULL; i++) {
41 if (order[i]->state >= 0) { //DFA_ALIVE()
42 if (top == NULL || order[i]->score > top->score)
43 top = order[i];
44 }
45 }
46 return top;
47 }
48
49 const char *
50 dfa_process(guess_dfa *order[], int c)
51 {
52 int i;
53 for (i = 0; order[i] != NULL; i++) {
54 if (DFA_ALIVE_P(order[i])) {
55 if (dfa_alone(order[i], order))
56 return order[i]->name;
57 DFA_NEXT_P(order[i], c);
58 }
59
60 }
61 }