/********************************************************************** * tess_adaptable_word * * Return true if the word is regarded as "good enough". **********************************************************************/ BOOL8 Tesseract::tess_adaptable_word( // test adaptability WERD *word, // word to test WERD_CHOICE *best_choice, // after context WERD_CHOICE *raw_choice // before context ) { TWERD *tessword = make_tess_word(word, NULL); int result = (tessword && best_choice && raw_choice && AdaptableWord(tessword, *best_choice, *raw_choice)); delete_word(tessword); return result != 0; }
BOOL8 tess_adaptable_word( //test adaptability WERD *word, //word to test WERD_CHOICE *word_choice, //after context WERD_CHOICE *raw_choice //before context ) { TWERD *tessword; //converted word INT32 result; //answer tessword = make_tess_word (word, NULL); result = AdaptableWord (tessword, word_choice->string ().string (), raw_choice->string ().string ()); delete_word(tessword); return result != 0; }
void tess_adapter( //adapt to word WERD *word, //bln word DENORM *denorm, //de-normalise const char *string, //string for word const char *raw_string, //before context const char *rejmap //reject map ) { TWERD *tessword; //converted word static TEXTROW tessrow; //dummy row //make dummy row make_tess_row(denorm, &tessrow); //make a word tessword = make_tess_word (word, &tessrow); AdaptToWord(tessword, &tessrow, string, raw_string, rejmap); //adapt to it delete_word(tessword); //free it }
int TWubiIM::processinput(TIMC * std_imc, XKeyEvent * e) { TWubiIMC * imc = (TWubiIMC *) std_imc; static int do_switch_enable = 0; if (iskey(e, &Switch_Enable_Key)){ if (e->type == KeyPress){ do_switch_enable = 1; return FORWARD_KEY; }else if (do_switch_enable){ do_switch_enable = 0; imc->switch_stat(IMC_STAT_DISABLE); return STAT_KEY; } }else do_switch_enable = 0; if (e->type == KeyRelease) return IGNORE_KEY; if (!imc->enabled()) return FORWARD_KEY; if (iskey(e, &Switch_BQ_Key)){ switchBQmode(imc); return STAT_KEY; } if (imc->is_preedit()){ if (iskey(e, &Listforward_Key)) return LISTFORWARD_KEY; if (iskey(e, &Listbackward_Key)) return LISTBACKWARD_KEY; int i; if ((i = iskey(e, Word_Delete_Keys, 9)) > 0){ if (i > imc->display_count()) return IGNORE_KEY; List_Item * li = imc->display_list_item(i-1); //is it a word? if (li->wr.w[1] != 0){ delete_word(li); imc->set_update_stamp(time(NULL)); imc->clear(); return HIDE_KEY; } return IGNORE_KEY; } } if (iskey(e, &New_Word_Key)){ imc->start_new_word(); return NORMAL_KEY; } if (e->state & (ControlMask | Mod1Mask)) // the key with shift only is needed return FORWARD_KEY; if (imc->is_mb_input()) if (convertB2Q(e, cb2q)) return COMMIT_KEY; else return FORWARD_KEY; return processnormal((TWubiIMC *)imc, e); }
int main( int argc, char *argv[] ) { /* (x,y) position of edit window. x column, y line -> (0,0) at upper left on screen */ unsigned int xCursorPos = 0; unsigned int yCursorPos = 0; unsigned int curmenu = 0x1100; int i; cwsetup( argc, argv ); writestatus( 0 ); writetab( ); splashscreen( ); /* Main program loop */ do { dispstrhgc( " ", wind.col, 2, NORMALATTR ); i = pulled_down_menu( &curmenu, &xCursorPos, &yCursorPos ); if ( filename[0] != '\0' ) { switch ( i ) { case RETKEY: keymain = menu_to_key( curmenu ); break; case ESCKEY: waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); /* Show blinking cursor */ keymain = readkbd( ); /* If keypressed Get it */ break; default: keymain = i; break; } while ( keymain != ESCKEY ) { if ( ( keymain & 0xff ) >= 32 ) { keymain = changekey( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } else { /* Function Key */ switch ( keymain ) { case PGUPKEY: case CNTRL_R: page_up( ); break; case PGDNKEY: case CNTRL_C: page_down( ); break; case UPKEY: case CNTRL_E: cursor_up( ); break; case DNKEY: case CNTRL_X: cursor_down( yCursorPos ); break; case LEKEY: case CNTRL_S: cursor_left( &xCursorPos ); break; case 0x2301: gobeginblk( &xCursorPos ); break; case 0x2401: goendblk( &xCursorPos ); break; case RIKEY: case CNTRL_D: cursor_right( &xCursorPos, yCursorPos ); break; case CNTRL_W: scroll_up( ); break; case CNTRL_Z: scroll_down( ); break; case CHOMEKEY: top_of_page( ); break; case CPGUPKEY: topfile( &xCursorPos ); break; case CENDKEY: bottom_of_page( ); break; case CPGDNKEY: endfile( &xCursorPos ); break; case DELKEY: case CNTRL_G: delete_char( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_T: delete_word( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_Y: delete_line( ); changeflag = YES; break; case CNTRL_M: case RETKEY: if ( insertmode == NO ) { returnkey( &xCursorPos, yCursorPos ); } else { ret_with_ins( &xCursorPos, yCursorPos ); changeflag = YES; } break; case BSKEY: case CNTRL_H: backspace( &xCursorPos ); yCursorPos = findrow( ); refreshline( 0, yCursorPos ); changeflag = YES; break; case INSKEY: case CNTRL_V: insertmode = !insertmode; writeinsmode( ); break; case CNTRL_N: insert_ret( &xCursorPos ); break; case F10KEY: thaimode = !thaimode; writelanguage( ); break; case F1KEY: fontused = 0x00; writeattr( ); break; case F2KEY: fontused = fontused | ITALICATTR; writeattr( ); break; case F3KEY: fontused = fontused | ONELINEATTR; fontused = fontused & 0x7f; writeattr( ); break; case F4KEY: fontused = fontused | TWOLINEATTR; fontused = fontused & 0xfe; writeattr( ); break; case F5KEY: fontused = fontused | BOLDATTR; writeattr( ); break; case F6KEY: fontused = fontused | ENLARGEATTR; writeattr( ); break; case F7KEY: fontused = fontused | SUPERATTR; if ( ( fontused & SUBATTR ) == SUBATTR ) { fontused = fontused ^ SUBATTR; } writeattr( ); break; case F8KEY: fontused = fontused | SUBATTR; if ( ( fontused & SUPERATTR ) == SUPERATTR ) { fontused = fontused ^ SUPERATTR; } writeattr( ); break; case F9KEY: manualwrap( &xCursorPos, &yCursorPos ); break; case ALTM: editmacro( ); break; case TABKEY: case CNTRL_I: movetotab( &xCursorPos, yCursorPos ); break; case CNTRL_K: blockcommand( &xCursorPos ); break; case 0x1401: blkcmd( 'p', &xCursorPos ); break; case 0x6101: blkcmd( 'b', &xCursorPos ); break; case 0x6201: blkcmd( 'k', &xCursorPos ); break; case 0x6301: blkcmd( 'c', &xCursorPos ); break; case 0x6401: blkcmd( 'y', &xCursorPos ); break; case 0x6501: blkcmd( 'v', &xCursorPos ); break; case 0x6601: blkcmd( 'r', &xCursorPos ); break; case 0x6701: blkcmd( 'w', &xCursorPos ); break; case 0x6801: blkcmd( 'h', &xCursorPos ); break; case CNTRL_O: onscreen( xCursorPos, yCursorPos ); break; case 0x7101: doonscrn( 'l', xCursorPos, yCursorPos ); break; case 0x7201: doonscrn( 'r', xCursorPos, yCursorPos ); break; case 0x7301: doonscrn( 'i', xCursorPos, yCursorPos ); break; case 0x7401: doonscrn( 'n', xCursorPos, yCursorPos ); break; case 0x7501: doonscrn( 'c', xCursorPos, yCursorPos ); break; case 0x7601: doonscrn( 'p', xCursorPos, yCursorPos ); break; case 0x7701: doonscrn( 'x', xCursorPos, yCursorPos ); break; case CNTRL_Q: quick( &xCursorPos, &yCursorPos ); break; case 0x3501: deltoendline( xCursorPos, yCursorPos ); break; case 0x8111: inscntrl( CNTRL_W, xCursorPos, yCursorPos ); break; case 0x8211: inscntrl( CNTRL_S, xCursorPos, yCursorPos ); break; case 0x8311: inscntrl( CNTRL_R, xCursorPos, yCursorPos ); break; case 0x8411: inscntrl( CNTRL_B, xCursorPos, yCursorPos ); break; case 0x8511: inscntrl( CNTRL_E, xCursorPos, yCursorPos ); break; case 0x8611: inscntrl( CNTRL_T, xCursorPos, yCursorPos ); break; case 0x8711: inscntrl( CNTRL_V, xCursorPos, yCursorPos ); break; case CNTRL_P: printcntrl( xCursorPos, yCursorPos ); break; case HOMEKEY: home( &xCursorPos ); break; case ENDKEY: endline( &xCursorPos ); break; case CLEKEY: case CNTRL_A: backword( &xCursorPos ); break; case CRIKEY: case CNTRL_F: nextword( &xCursorPos, yCursorPos ); break; case CNTRL_L: if ( source[0] != '\0' ) { if ( replaceflag == NO ) { if ( searchfwd( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } else { if ( searchreplace( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } } break; case CNTRL_B: reform( ); break; case ALTP: gotopage( ); break; case CNTRL_J: case ALTL: gotoline( ); break; case 0x5101: searching( &xCursorPos, &yCursorPos ); break; case 0x5201: replacing( &xCursorPos, &yCursorPos ); break; case 0x8501: loadtoline( curline->text ); refreshline( 0, yCursorPos ); break; case CF1KEY: insertmacro( ¯o[0][0], &xCursorPos, &yCursorPos ); break; case CF2KEY: insertmacro( ¯o[1][0], &xCursorPos, &yCursorPos ); break; case CF3KEY: insertmacro( ¯o[2][0], &xCursorPos, &yCursorPos ); break; case CF4KEY: insertmacro( ¯o[3][0], &xCursorPos, &yCursorPos ); break; case CF5KEY: insertmacro( ¯o[4][0], &xCursorPos, &yCursorPos ); break; case CF6KEY: insertmacro( ¯o[5][0], &xCursorPos, &yCursorPos ); break; case CF7KEY: insertmacro( ¯o[6][0], &xCursorPos, &yCursorPos ); break; case CF8KEY: insertmacro( ¯o[7][0], &xCursorPos, &yCursorPos ); break; case CF9KEY: insertmacro( ¯o[8][0], &xCursorPos, &yCursorPos ); break; case CF10KEY: insertmacro( ¯o[9][0], &xCursorPos, &yCursorPos ); break; case AF2KEY: inscntrl( ITALICCODE, xCursorPos, yCursorPos ); break; case AF3KEY: inscntrl( ONELINECODE, xCursorPos, yCursorPos ); break; case AF4KEY: inscntrl( TWOLINECODE, xCursorPos, yCursorPos ); break; case AF5KEY: inscntrl( BOLDCODE, xCursorPos, yCursorPos ); break; case AF6KEY: inscntrl( ENLARGECODE, xCursorPos, yCursorPos ); break; case AF7KEY: inscntrl( SUPERCODE, xCursorPos, yCursorPos ); break; case AF8KEY: inscntrl( SUBCODE, xCursorPos, yCursorPos ); break; #ifdef WANT_TO_USE_GRAPH case ALTG: insertgraph( ); break; case ALTD: deletegraph( ); break; #endif case ALTX: quitprog = YES; keymain = ESCKEY; break; default: if ( ( alt_char_map( keymain ) ) != -1 ) { keymain = alt_char_map( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } break; } /* switch ( keymain ) */ } adjustcol( &xCursorPos ); while ( ( yCursorPos = findrow( ) ) > ( wind.width - 1 ) ) { storeline( curline ); curline = curline->previous; loadtoline( curline->text ); lineno--; } if ( !keypressed( ) ) { if ( !pagecomplete ) { showpage( ); } if ( !keypressed( ) ) { writecolno( firstcol + xCursorPos ); dispstrhgc( " ", wind.col, 2, NORMALATTR ); if ( !keypressed( ) ) { writepageline( ); } } } if ( quitprog != YES ) { waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); keymain = readkbd( ); dispkey( keymain ); } } /* while */ } else { /* if filename[0] != '\0' */ errorsound( ); } } while ( !quitprog ); if ( changeflag ) { blockmsg( 5 ); dispstrhgc( "ÂѧäÁèä´é¨Ñ´à¡çºá¿éÁ¢éÍÁÙÅ µéͧ¡ÒèѴà¡çºËÃ×ÍäÁè (Y/N)?", ( 16 + center_factor ) + 7, 5, REVERSEATTR ); keymain = 0; while ( ( keymain != 'n' ) && ( keymain != 'N' ) && ( keymain != 'y' ) && ( keymain != 'Y' ) ) { keymain = ebioskey( 0 ) & 0xff; if ( ( keymain == 'y' ) || ( keymain == 'Y' ) ) { writeblk( filename, sentinel->next, 0, sentinel->previous, MAXCOL ); } } } settext( ); return 0; }
WERD_CHOICE *recog_word_recursive( //recog one owrd WERD *word, //word to do DENORM *denorm, //de-normaliser POLY_MATCHER matcher, //matcher function POLY_TESTER tester, //tester function POLY_TESTER trainer, //trainer function BOOL8 testing, //true if answer driven WERD_CHOICE *&raw_choice, //raw result //list of blob lists BLOB_CHOICE_LIST_CLIST *blob_choices, WERD *&outword //bln word output ) { inT32 initial_blob_choice_len; inT32 word_length; //no of blobs STRING word_string; //converted from tess STRING word_string_lengths; ARRAY tess_ratings; //tess results A_CHOICE tess_choice; //best word A_CHOICE tess_raw; //raw result TWERD *tessword; //tess format BLOB_CHOICE_LIST *choice_list; //fake list //iterator BLOB_CHOICE_LIST_C_IT choice_it; tess_matcher = matcher; //install matcher tess_tester = testing ? tester : NULL; tess_trainer = testing ? trainer : NULL; tess_denorm = denorm; tess_word = word; // blob_matchers[1]=call_matcher; if (word->blob_list ()->length () > MAX_UNDIVIDED_LENGTH) { return split_and_recog_word (word, denorm, matcher, tester, trainer, testing, raw_choice, blob_choices, outword); } else { if (word->flag (W_EOL)) last_word_on_line = TRUE; else last_word_on_line = FALSE; initial_blob_choice_len = blob_choices->length (); tessword = make_tess_word (word, NULL); tess_ratings = cc_recog (tessword, &tess_choice, &tess_raw, testing && tester != NULL /* ? call_tester : NULL */ , testing && trainer != NULL /* ? call_train_tester : NULL */ ); //convert word outword = make_ed_word (tessword, word); if (outword == NULL) { outword = word->poly_copy (denorm->row ()->x_height ()); } delete_word(tessword); //get rid of it //no of blobs word_length = outword->blob_list ()->length (); //convert all ratings convert_choice_lists(tess_ratings, blob_choices); //copy string word_string = tess_raw.string; word_string_lengths = tess_raw.lengths; while (word_string_lengths.length () < word_length) { word_string += " "; //pad with blanks word_string_lengths += 1; } raw_choice = new WERD_CHOICE (word_string.string (), word_string_lengths.string (), tess_raw.rating, tess_raw.certainty, tess_raw.permuter); word_string = tess_choice.string; word_string_lengths = tess_choice.lengths; if (word_string_lengths.length () > word_length) { tprintf ("recog_word: Discarded long string \"%s\"" " (%d characters vs %d blobs)\n", word_string.string (), word_string_lengths.length(), word_length); word_string = NULL; //should never happen word_string_lengths = NULL; tprintf("Word is at (%g,%g)\n", denorm->origin(), denorm->y(word->bounding_box().bottom(), 0.0)); } if (blob_choices->length () - initial_blob_choice_len != word_length) { word_string = NULL; //force rejection word_string_lengths = NULL; tprintf ("recog_word: Choices list len:%d; blob lists len:%d\n", blob_choices->length (), word_length); //list of lists choice_it.set_to_list (blob_choices); while (blob_choices->length () - initial_blob_choice_len < word_length) { //get fake one choice_list = new BLOB_CHOICE_LIST; //add to list choice_it.add_to_end (choice_list); tprintf ("recog_word: Added dummy choice list\n"); } while (blob_choices->length () - initial_blob_choice_len > word_length) { choice_it.move_to_last (); //should never happen delete choice_it.extract (); tprintf ("recog_word: Deleted choice list\n"); } } while (word_string_lengths.length () < word_length) { word_string += " "; //pad with blanks word_string_lengths += 1; } assert (raw_choice != NULL); if (tess_choice.string) { strfree(tess_choice.string); strfree(tess_choice.lengths); } if (tess_raw.string) { strfree(tess_raw.string); strfree(tess_raw.lengths); } return new WERD_CHOICE (word_string.string (), word_string_lengths.string (), tess_choice.rating, tess_choice.certainty, tess_choice.permuter); } }
void menu_enter(){ ///\fn void menu_enter() ///\brief Selectarea optiunii. /// ///Implementarea selectarii dorite in cadrul unei optiunilor din menu. system("cls"); // se ia fiecare caz de meniu si fiecare caz de element de meniu in parte. switch(current_menu){ // main menu case 0 : { switch (highlighted_item){ case 0 : {//input one word one_word(); break; } case 1 : {//From file from_file(); break; } case 2 : {//Live live_input(); break; } case 3 : {//options-menu current_menu = 1; highlighted_item = 0; break; } case 4 : {//Exit printf("\n\n\tGood bye!"); Sleep(750); exit(0); break; } } break; } //options-menu case 1 : { switch (highlighted_item){ case 0 : {//Update words apparitions update_app_words(); break; } case 1 : {//Insert an word to dictionary insert_word(); break; } case 2 : {//Delete an word from dictionary delete_word(); break; } case 3 : {//Reset dictionary reset_dict(); break; } case 4 : {//Build dictionary from file build_dict(); break; } case 5 : {//Add words to dictionary from file update_words(); break; } case 6 : {//select_suggestions_funcition current_menu = 2; highlighted_item = sugg_funct; break; } case 7 : {//back current_menu = 0; highlighted_item = 0; break; } } break; } //select suggestion functions case 2 : { switch (highlighted_item){ case 0 : {//leven sugg_funct = 0; break; } case 1 : {//leven 2.0 sugg_funct = 1; break; } case 2 : {//back current_menu = 1; highlighted_item = 0; break; } } } } print_menu(); Sleep(50); }
int main(void) { srand(time(NULL)); printf("The available commands are:\n" "I N - Inject an NxN board. This command will scan NxN letters to form a board\n" "G N - Generates a new NxN board where a letter doesn't appear more than N times\n" "P - Print the current board\n" "W N word - Insert a word into the dictionary with score N\n" "A N word - Insert a word and all prefixes in the dictionary. Non-proper prefixes get a score of 0\n" "R word - Delete a word\n" "S word - Search for a word and return its score (-1 if no such word exists)\n" "D - Dump the dictionary with the corresponding scores\n" "B - Find the best word (word with the highest score)\n" "Q - Quit\n" "> "); char **board = NULL; size_t board_dim = 0; trie = new_trie(); char op; while (scanf(" %c", &op) == 1) { if (op == 'I') { destroy_board(board, board_dim); scanf("%zu", &board_dim); board = inject_board(board_dim); } else if (op == 'P') { if (board == NULL) { printf("No board at the moment\n"); } else { print_board(board, board_dim); } } else if (op == 'G') { destroy_board(board, board_dim); scanf("%zu", &board_dim); board = generate_board(board_dim); } else if (op == 'W') { size_t word_score; scanf("%zu%s", &word_score, word_buff); insert_word(trie, word_buff, word_score); } else if (op == 'A') { size_t word_score; scanf("%zu%s", &word_score, word_buff); size_t i; for (i = 1; word_buff[i] != '\0'; i++) { char c = word_buff[i]; word_buff[i] = '\0'; insert_word(trie, word_buff, 0); word_buff[i] = c; } insert_word(trie, word_buff, word_score); } else if (op == 'R') { scanf("%s", word_buff); delete_word(trie, word_buff); } else if (op == 'S') { scanf("%s", word_buff); int s = word_score(trie, word_buff); if (s == -1) { printf("No such word: %s\n", word_buff); } else { printf("score(%s) = %d\n", word_buff, s); } } else if (op == 'D') { print_known_words(trie); } else if (op == 'B') { char *w = find_best_word(board, board_dim); if (w == NULL) { printf("No words found\n"); } else { printf("Best word: %s\n", w); } free(w); } else if (op == 'Q') { break; } else { fprintf(stderr, "Unrecognized operation: %c\n", op); } printf("> "); } destroy_trie(trie); destroy_board(board, board_dim); return 0; }
int main(void) { FILE *fp = fopen("dict.txt", "r"); //以读的方式打开文件“dict.tx t” if(fp == NULL) { perror("open file dict.txt\n"); exit(0); } while(1) { char content[1000]; char Ess[1000]; char *token; link p = make_node(); if(!fgets(content, 1000, fp)) //从文件读一行(单词),如果到末尾则跳出循环 break; if(!fgets(Ess, 1000, fp)) //从文件读一行(内容),如果到末尾了跳出寻环 break; if(head == NULL) //初始化链表 { head = p; tail = head; } else { tail -> next = p; tail = tail -> next; } // fgets(content,100,fp); if(content[strlen(content) - 1] == '\n') //如果数组到最后一个元素时候将‘\n’变为'\0' content[strlen(content) - 1] = '\0'; strcpy(p -> word, content + 1); //由于第一个为#所以把第二个以后的元素复制给p -> word // printf("%s\n",p->word); // fgets(Ess,100,fp); token = strtok(Ess, ":"); //截取:以前的内容 // printf("%s\n",token); p->count = 0; //初始化 while((token = strtok(NULL, "@"))!=NULL) { p -> Explain[p -> count] = (char *)malloc(strlen(token) + 1); strcpy(p -> Explain[p -> count], token); p->count++; } print_word(p); } fclose(fp); int i = 0; while(1) { printf("take a choice:\n0 printf_word\n1 add a new word\n2 delete a word\n3 search a word\n4 write a 2file\n5 read_2file\n6 exit\n"); scanf("%d", &i); switch(i) { case 0 : printf_word(head); break; case 1: add_word(head); break; case 2: head = delete_word(head); break; case 3: search_word(head); break; case 4: write_2file(head); break; case 5: read_2file(); break; case 6: printf("exit...\n"); save_word(head); return 0; break; default: continue; break; } } return 0; }