static void set_string(struct condition *cond, struct res_db *db, struct input *in, anthy_context_t ac) { struct conv_res *cr1, *cr2; int pr; anthy_set_string(ac, in->str); /* result */ cr1 = find_conv_res(db, ac, in->str, 1); sum_up(db, cr1); /* split */ cr2 = find_conv_res(db, ac, in->str, 0); sum_up(db, cr2); /**/ pr = 0; if (cond->miss_only) { if (cr1->check == CHK_MISS || cr2->check == CHK_MISS) { pr = 1; } } else if (!cond->quiet) { pr = 1; } if (pr) { printf("%d:(%s)\n", in->serial, in->str); anthy_print_context(ac); } anthy_reset_context(ac); }
int main(int argc,char **argv){ if(anthy_init()) { printf("anthy_init() is failed.\n"); return 1; } anthy_set_personality(""); ac = anthy_create_context(); if(!ac) { printf("anthy_create_context() is failed.\n"); return 1; } //準備完了! for(k=0; k<1000; k++){ anthy_set_string(ac, "わたしのなまえはおくのです。"); //anthy_commit_segment(ac); anthy_get_stat(ac, &cs); //printf("segment:%d\n",cs.nr_segment); for(i=0; i<cs.nr_segment; i++){ struct anthy_segment_stat ss; anthy_get_segment_stat(ac,i,&ss); //printf("can:%d,len:%d |", ss.nr_candidate, ss.seg_len); for(j=0; j<ss.nr_candidate; j++){ char buffer[256]; anthy_get_segment(ac,i,j,buffer,256); //printf(" %s ", buffer); } //printf("\n"); } //printf("\n"); //anthy_print_context(ac); } anthy_release_context(ac); anthy_quit(); return 0; }
void toHira(char* str) { int len, cur, isquestion; char buf[BUFSIZE]; struct anthy_conv_stat cs; replaceSign(str); replaceGrass(str); printf("rgr_str:%s\n", str); if (anthy_init()) { fprintf(stderr, "anthy init error\n"); abort(); } anthy_context_t ctx = anthy_create_context(); if (!ctx) { fprintf(stderr, "can not create context\n"); abort(); } anthy_context_set_encoding(ctx, ANTHY_UTF8_ENCODING); if (anthy_set_string(ctx, str)) { fprintf(stderr, "can not set string\n"); abort(); } if (anthy_get_stat(ctx, &cs)) { fprintf(stderr, "can not get stat\n"); abort(); } cur = 0; for (int i = 0; i < cs.nr_segment; i++) { if ((len = anthy_get_segment(ctx, i, NTH_UNCONVERTED_CANDIDATE, buf, BUFSIZE)) == -1) { fprintf(stderr, "can not get segment %d\n", i); abort(); } if (istalk(buf)) { memcpy(str + cur, buf, len); cur += len; } if (i < cs.nr_segment - 1) if (i == cs.nr_segment - 3 && isquestion) continue; else if (i == cs.nr_segment - 2) continue; else str[cur] = '/'; else str[cur] = '\0'; cur++; } anthy_release_context(ctx); }
static uim_lisp set_string(uim_lisp ac_, uim_lisp str_) { anthy_context_t ac; const char *str; ac = get_anthy_context(ac_); str = REFER_C_STR(str_); anthy_set_string(ac, str); return uim_scm_f(); }
// // starting and finishing // void Conversion::convert (std::string source, CandidateType ctype, bool single_segment) { if (is_converting ()) return; clear (); std::string dest; // convert struct anthy_conv_stat conv_stat; anthy_get_stat (m_anthy_context, &conv_stat); if (conv_stat.nr_segment <= 0) { dest = source; anthy_set_string (m_anthy_context, dest.c_str ()); } if (single_segment) join_all_segments (); // get information about conversion string anthy_get_stat (m_anthy_context, &conv_stat); if (conv_stat.nr_segment <= 0) return; // select first segment m_cur_segment = 0; // create segments m_segments.clear(); for (int i = m_start_id; i < conv_stat.nr_segment; i++) { struct anthy_segment_stat seg_stat; anthy_get_segment_stat (m_anthy_context, i, &seg_stat); m_segments.push_back ( ConversionSegment (get_segment_string (i, ctype), ctype, seg_stat.seg_len)); } }
gboolean module_feedkey(int kv, int kvstate) { int lkv = tolower(kv); int shift_m=(kvstate&ShiftMask) > 0; // printf("%x %c %d\n", kv, kv, shift_m); if (kvstate & ControlMask) return FALSE; if (kvstate & (Mod1Mask|Mod4Mask|Mod5Mask)) return FALSE; if (kv==XK_Shift_L||kv==XK_Shift_R) { key_press_time = gmf.mf_current_time(); } if (!gmf.mf_tsin_pho_mode()) return 0; gboolean b_is_empty = is_empty(); switch (kv) { case XK_F7: if (is_empty()) return FALSE; state = STATE_ROMANJI; if (state_hira_kata != STATE_kata) state_hira_kata = STATE_kata; else state_hira_kata = STATE_hira; disp_input(); return TRUE; case XK_F8: if (is_empty()) return FALSE; state = STATE_ROMANJI; if (state_hira_kata != STATE_half_kata) state_hira_kata = STATE_half_kata; else state_hira_kata = STATE_hira; disp_input(); return TRUE; case XK_F11: system("kasumi &"); return TRUE; case XK_F12: system("kasumi -a &"); return TRUE; case XK_Up: if (b_is_empty) return FALSE; if (state==STATE_SELECT) { int N = page_N(); gmf.mf_tss->pho_menu_idx--; if (gmf.mf_tss->pho_menu_idx < 0) gmf.mf_tss->pho_menu_idx = N - 1; disp_select(); } return TRUE; case XK_Down: if (b_is_empty) return FALSE; if (state==STATE_CONVERT) { state = STATE_SELECT; gmf.mf_tss->sel_pho = TRUE; // puts("STATE_SELECT"); disp_select(); } else if (state==STATE_SELECT) { int N = page_N(); gmf.mf_tss->pho_menu_idx=(gmf.mf_tss->pho_menu_idx+1)% N; disp_select(); } return TRUE; case XK_Return: if (b_is_empty) return FALSE; if (state==STATE_SELECT) { if (select_idx(gmf.mf_tss->pho_menu_idx)) goto send; return TRUE; } send: return module_flush_input(); case XK_Escape: if (state==STATE_SELECT) { state = STATE_CONVERT; gmf.mf_tss->sel_pho = FALSE; gmf.mf_clear_sele(); } else if (state==STATE_CONVERT) goto rom; return FALSE; case XK_BackSpace: if (b_is_empty) { state_hira_kata = STATE_hira; return FALSE; } gmf.mf_hide_selections_win(); if (state&(STATE_CONVERT|STATE_SELECT)) { rom: // puts("romanji"); state = STATE_ROMANJI; cursor = jpN; segN = 0; disp_input(); return TRUE; } // puts("back"); if (keysN) { keysN--; keys[keysN]=0; } else if (jpN && cursor) { delete_jpstr(cursor-1); cursor--; } else return FALSE; disp_input(); auto_hide(); return TRUE; case XK_Delete: if (b_is_empty) return FALSE; if (state&STATE_ROMANJI) { if (keysN) return TRUE; delete_jpstr(cursor); disp_input(); } auto_hide(); return TRUE; case XK_Left: if (b_is_empty) return FALSE; if (state&STATE_ROMANJI) { if (keysN) keysN = 0; else { if (cursor) cursor--; } disp_input(); } else if (state&STATE_CONVERT) { if (shift_m) { anthy_resize_segment(ac, cursor, -1); load_seg(); } else { if (cursor) cursor--; } disp_convert(); } return TRUE; case XK_Right: if (b_is_empty) return FALSE; if (state&STATE_ROMANJI) { if (cursor < jpN) cursor++; disp_input(); } else if (state&STATE_CONVERT) { if (shift_m) { anthy_resize_segment(ac, cursor, 1); load_seg(); } else { if (cursor < segN-1) cursor++; } disp_convert(); } return TRUE; case XK_Home: if (b_is_empty) return FALSE; cursor = 0; if (state&STATE_ROMANJI) { disp_input(); } else if (state&STATE_CONVERT) { disp_convert(); } return TRUE; case XK_End: if (b_is_empty) return FALSE; if (state&STATE_ROMANJI) { cursor = jpN; disp_input(); } else if (state&STATE_CONVERT) { cursor = segN-1; disp_convert(); } return TRUE; case XK_Prior: if (state!=STATE_SELECT) return FALSE; prev_page(); return TRUE; case XK_Next: if (state!=STATE_SELECT) return FALSE; next_page(); return TRUE; case ' ': if (b_is_empty) return FALSE; goto lab1; default: if (state==STATE_SELECT) { char *pp; if ((pp=strchr(*gmf.mf_pho_selkey, lkv))) { int c=pp-*gmf.mf_pho_selkey; if (select_idx(c)) goto send; } return TRUE; } } // printf("kv %d\n", kv); if (!is_legal_char(kv)) return FALSE; kv = lkv; if (state==STATE_CONVERT && kv!=' ') { send_seg(); state = STATE_ROMANJI; } lab1: if (state==STATE_ROMANJI) { if (keysN < MAX_KEYS) keys[keysN++]=kv; keys[keysN]=0; parse_key(); disp_input(); } module_show_win(); if (kv==' ') { if (state==STATE_ROMANJI) { char tt[512]; clear_seg_label(); merge_jp(tt, TRUE); // dbg("tt %s %d\n", tt, strlen(tt)); anthy_set_string(ac, tt); load_seg(); } else if (state==STATE_CONVERT) { state = STATE_SELECT; gmf.mf_tss->sel_pho = TRUE; // puts("STATE_SELECT"); disp_select(); } else if (state==STATE_SELECT) { next_page(); } } return TRUE; }