00001
00044
00045
00046
00047
00048
00049
00050
00051 #include <sent/stddefs.h>
00052 #include <sent/dfa.h>
00053
00060 boolean
00061 extract_cpair(DFA_INFO *dinfo)
00062 {
00063 int i;
00064 DFA_ARC *arc_l, *arc_r, *arc_r2;
00065 int left, right;
00066 int size;
00067
00068
00069
00070 size = dinfo->arc_num / dinfo->state_num;
00071 if (size < DFA_CP_MINSTEP) size = DFA_CP_MINSTEP;
00072 malloc_dfa_cp(dinfo, dinfo->term_num, size);
00073
00074
00075 for (i=0;i<dinfo->state_num;i++) {
00076 if ((dinfo->st[i].status & INITIAL_S) != 0) {
00077 for (arc_r = dinfo->st[i].arc; arc_r; arc_r = arc_r->next) {
00078 if (dinfo->is_sp[arc_r->label]) {
00079 jlog("Error: mkcpair: skippable sp should not appear at end of sentence\n");
00080 return FALSE;
00081 }
00082 set_dfa_cp_end(dinfo, arc_r->label, TRUE);
00083 }
00084 }
00085 for(arc_l = dinfo->st[i].arc; arc_l; arc_l = arc_l->next) {
00086 left = arc_l->label;
00087 if ((dinfo->st[arc_l->to_state].status & ACCEPT_S) != 0) {
00088 if (dinfo->is_sp[left]) {
00089 jlog("Error: mkcpair: skippable sp should not appear at beginning of sentence\n");
00090 return FALSE;
00091 }
00092 set_dfa_cp_begin(dinfo, left, TRUE);
00093 }
00094
00095 for (arc_r = dinfo->st[arc_l->to_state].arc; arc_r; arc_r = arc_r->next) {
00096 right = arc_r->label;
00097 set_dfa_cp(dinfo, right, left, TRUE);
00098 if (dinfo->is_sp[right]) {
00099 for (arc_r2 = dinfo->st[arc_r->to_state].arc; arc_r2; arc_r2 = arc_r2->next) {
00100 if (dinfo->is_sp[arc_r2->label]) {
00101 jlog("Error: mkcpair: skippable sp should not repeat\n");
00102 return FALSE;
00103 }
00104 set_dfa_cp(dinfo, arc_r2->label, left, TRUE);
00105 }
00106 }
00107 }
00108
00109 }
00110 }
00111
00112 return TRUE;
00113 }
00114
00122 boolean
00123 cpair_append(DFA_INFO *dst, DFA_INFO *src, int coffset)
00124 {
00125
00126
00127 if (dst->term_num - coffset != src->term_num) {
00128 jlog("Error: mkcpair: append term num not match!: %d, %d, %d\n",
00129 dst->term_num, src->term_num, coffset);
00130 return FALSE;
00131 }
00132
00133
00134 if (dfa_cp_append(dst, src, coffset) == FALSE) return FALSE;
00135
00136 return TRUE;
00137 }