?? blind_ime_more.h~
字號:
/* blind_ime.h 080907 BY 吳文騰 080929 Modify by StevenZ*/#ifndef _BLIND_IME_H#define _BLIND_IME_H#include "create.h"#include <string.h>#define MAXFIELD 20#define MAXLINE 50/*區域判斷所需宏*/#define BIME_MAXX 3400 #define BIME_MAXY 3600#define BIME_MINX 240#define BIME_MINY 450#define BIME_MXA (BIME_MINX+(BIME_MAXX-BIME_MINX)/2)/*觸摸屏返回值結構體*/typedef struct{ unsigned short pressure;/*0:松開 1:首次按下 2:按住*/ unsigned short x; unsigned short y; unsigned short pad;}BIME_TS_RET;typedef struct index{ char syllable[MAXFIELD]; /* 拼音 */ char sequence[MAXFIELD]; /* 同音字起始序列號 */ char character[MAXFIELD]; /* 漢字(存放最后輸入的漢字) */}INDEX;typedef struct words{ char sequence[MAXFIELD]; /* 同音字起始序列號 */ char character[MAXFIELD]; /* 漢字 */ int freq; /* 字頻 */ char phrase[MAXLINE]; /* 詞組 */}WORDS;struct cha{ char sequence[MAXFIELD]; /* 同音字起始序列號 */ char character[MAXFIELD]; /* 漢字 */ char phrase[MAXLINE]; /* 詞組 */ int freq; /* 字頻 */ struct cha * link;};typedef struct blind{ char array[MAXFIELD]; /* 統計序列 */ char syllable[MAXLINE]; /* 拼音(one or two) */ }BLIND;/************************/STOCK_DBS my_stock;char * array; //接收觸摸屏程序的字符串struct cha * first; //同音字鏈表首址char character[MAXFIELD]; //存放當前被選擇的漢字或詞組struct cha * cur; //指向語音當前所讀的漢字 /************************/int find_input_files(char *,char *,char *);int get_words_record(STOCK_DBS *, const char *, FILE *, char *);void get_index_record(STOCK_DBS * , const char * , FILE *, char *,char *);void get_blind_record(STOCK_DBS * , const char * , FILE *, char *,char *);int database_get(STOCK_DBS * , const char * , FILE * );void display(WORDS); void freq_change( STOCK_DBS *, char *);/*[語音識別]或觸摸控制判斷是否選擇左或右,選左返回1,否則返回0*/static int bime_left_or_right(){ int ts_fd; BIME_TS_RET ts_ret; ts_fd=open("/dev/touchscreen/0raw",O_RDONLY); if(ts_fd<0) { printf("open device error!!"); exit(1); } do{ read(ts_fd,&ts_ret,1); }while(ts_ret.pressure); close(ts_fd); if(ts_ret.x<BIME_MXA) { return 1; } return 0;}//**根據字符串序列檢索得到拼音**void get_blind_record(STOCK_DBS *my_stock , const char *program_name , FILE *error_file_pointer, char * array, char *cret){ int ret,i,flg; char array_cp[16]; char c,t2s_str[300]; char * syllable; char * str1, *str2; DBC * cursor_blind; DBT key,data; BLIND my_blind; strcpy( array_cp, array ); //將array的值賦給數組seq,保證其穩定性 memset(&my_blind, 0, sizeof(BLIND)); memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); ret = my_stock->sta_dbp->cursor( my_stock->sta_dbp, NULL, &cursor_blind, 0); print_error(ret); key.data = array_cp ; key.size = strlen( array_cp ) +1 ; ret = cursor_blind->get( cursor_blind, &key, &data, DB_SET_RANGE ) ; print_error( ret ); data.data = &my_blind; data.size = sizeof( my_blind ); data.ulen = sizeof( BLIND ); data.flags = DB_DBT_USERMEM; ret = cursor_blind->get( cursor_blind, &key, &data, DB_CURRENT ) ; print_error( ret ); printf("\t字符串:%s", my_blind.array); printf("\t拼音:%s\n", my_blind.syllable); str1 = my_blind.syllable ; flg=0; for(i=0; i<strlen(str1); i++) { if( isdigit( my_blind.syllable[i] ) != 0 ) { flg=1; break; } } if(flg) { str1[i]='\0'; //截取第一個拼音 printf( "拼音1:%s\n", str1); str2 = &my_blind.syllable[i+1] ; //截取第二個拼音 printf( "拼音2:%s\n", str2); if( cursor_blind != NULL) cursor_blind->close(cursor_blind); sprintf(t2s_str,",[i1],請再選擇拼音,左:%s1,右:%s1,[i0],",str1,str2); printf("t2s_str=%s\n",t2s_str); T2S_t2s(t2s_str); //c = speech(0x01); if( bime_left_or_right()) { strcpy(cret,str1); } else strcpy(cret,str2); } else { printf("no slection!!!\n"); strcpy(cret,str1); }}/* 根據拼音查找并顯示拼音字庫索引表記錄, 并返回同音字起始序列號 */void get_index_record(STOCK_DBS *my_stock , const char *program_name, FILE *error_file_pointer, char * input,char *cret){ int ret; char * sequence; DBC * cursor_index; DBT key,data; INDEX my_index; /* 創建數據庫游標 */ ret = my_stock->words_index_dbp->cursor( my_stock->words_index_dbp, NULL, &cursor_index, 0); print_error(ret); memset(&my_index, 0, sizeof(INDEX)); memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); key.data = input; //關鍵字賦值 key.size = strlen(input) + 1; ret = cursor_index->get( cursor_index, &key, &data, DB_SET); //get函數根據關鍵字進行游標查詢數據庫 print_error(ret); data.data = &my_index; data.ulen = sizeof(INDEX); data.flags = DB_DBT_USERMEM; ret = cursor_index->get( cursor_index, &key, &data, DB_CURRENT); //游標定位 print_error(ret); sequence = my_index.sequence; strcpy(cret,sequence); //printf("***********拼音字庫索引表*********\n"); printf("\t拼音;%s\n", my_index.syllable); printf("\t起始序列號:%s\n", my_index.sequence); printf("\t最近輸入的漢字:%s\n", my_index.character); if( cursor_index != NULL) cursor_index->close(cursor_index); //同音字起始序列號為返回值}char last_character[4]; //存放最后輸入的漢字char last_phrase[MAXFIELD]; //存放最后輸入的漢字的詞組/* 將檢索到的同音字按字頻排序,并返回鏈表的頭指針 */#define LEN sizeof( struct cha )void display( WORDS my_words ){ struct cha *prt, *next; struct cha *newnode; newnode = (struct cha *)malloc(LEN); //創建新結點 if( !newnode) exit(1); strcpy(newnode->sequence, my_words.sequence); //為新結點賦值 strcpy(newnode->character, my_words.character); strcpy(newnode->phrase, my_words.phrase); newnode->freq = my_words.freq; newnode->link = NULL; if(first == NULL) //鏈表為空時 { // newnode->link =first; first = newnode; } else { if( newnode->freq >= first->freq ) //新結點字頻大于等于鏈表頭結點的字頻時 { newnode->link = first; first = newnode; } else //新結點字頻小于鏈表頭結點的字頻時 { prt = next = first; while( newnode->freq <= next->freq && next->link != NULL) { prt = next; next = next ->link; } if(newnode->freq <= next->freq) { next->link = newnode; } else { prt->link = newnode; newnode->link = next; } } }}void get_first_phrase(char *s_tmp,char *phrase){ int i=0; while(phrase[i]!=','&&phrase[i]!='\0') { s_tmp[i]=phrase[i]; i++; } s_tmp[i]='\0';}void * display_th(void * data) //語音讀同音字鏈表線程{ char s_tmp[20];// T2S_option( FEMALE, 1, 1 ); //調用語音函數讀出漢字 //T2S_t2s("由同音字詞語選漢字");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -