windows的碼表生成器為人們提供了自制漢字輸入法的手段,但在編譯前需做大量的預備工作,在實際操作過程中存在著以下三方面的問題,現(xiàn)以制作五筆字型輸入法為例加以分析:
1.格式問題 我們雖然能從許多漢字系統(tǒng)中取得五筆字型碼表,但這些碼表格式很少與windows碼表格式相同,因此在用碼表生成器編譯前需進行格式調整;
2.編碼問題 從任何一個漢字系統(tǒng)都只能得到數(shù)量有限的詞條,因此我們有必要根據(jù)需要自建詞組,或把非五筆字型輸入法(如windows3.2中的鄭碼)中大量的詞組增加到五筆字型輸入法中,而為這些詞組逐一人工編碼既費時又易錯;
3.編譯限制 windows中的碼表生成器在對沒有按編碼排序的碼表文件編譯時需要排序,但這時它能實際接受的最大編碼數(shù)為16000條左右,超過的部分則無法處理,而且排序時間較長。針對上述問題,我用foxpro編制了一段程序,能較滿意地解決以上問題,其特點為:
自動生成編碼。只需從任一漢字輸入法中提取詞組并舍去其編碼,再不需做任何格式調整,這樣我們就會有眾多詞組源可以利用。
自動生成windows的碼表文件。由于在生成碼表文件時就已對編碼做了排序處理,因而無需windows的碼表編譯器再排序(sort=0),從而不但省去了費時的排序過程,而且使編碼數(shù)目幾乎沒有限制。
一、程序說明
本程序涉及的庫文件結構為:
fieldfieldnametypewidthdec
1codecharacter4
2wordcharacter22
程序運行之前,需制作兩個庫文件:"單字.dbf"和"字碼.dbf"。"單字.dbf"存放每個漢字的一、二、三、四級五筆字型編碼。"單字.dbf"可以從其他漢字系統(tǒng)的五筆字型碼表文件中取得。將取得的單個漢字及其編碼添加到"單字.dbf"即可。
"字碼.dbf"中的word字段是6850個漢字,code字段是每個漢字五筆字型編碼的前二碼。"字碼.dbf"可以利用"單字.dbf"制作:先刪除其中的一級簡碼,再取得每個漢字和其編碼的前兩碼,最后刪除相同的記錄。
二、運行過程
1.運行程序的第一步,將要增加的詞組文本文件&appfile..txt增補到庫文件&appdbfile..dbf的word字段中;
2.調用過程delexistword刪除庫文件&appdbfile..dbf中與詞組庫文件"詞組庫.dbf"重復的記錄,以保證增加時不會重復加入"詞組庫.dbf"中已有的詞組;
3.調用過程generate_wbcode生成庫文件&appdbfile..dbf中code字段的五筆字型編碼。首次運行時,本程序將生成庫文件"詞組庫.dbf",以后運行時,會把欲增加的詞組及其編碼增補到庫文件"詞組庫.dbf"中。在生成編碼時要用到庫文件"字碼.dbf"及其關于word字段的索引文件"字碼.cdx";
4.調用過程towinform生成windows碼表文件。運行中用"單字.dbf"和"詞組庫.dbf"合成所有漢字、詞組的編碼庫文件mbase.dbf并生成其索引文件mbase.cdx。最后由mbase.bdf生成windows的碼表文件"五筆字型.txt"。
三、程序清單
settalkoff
setnotifyoff
clear
*將此程序所在路徑設為默認路徑
progpath=substr(sys(16),1,rat(’/’,sys(16))-1)
setdefaultto&progpath
appfile=getfile(’txt’,’要增加的詞組文件.txt:’,’選擇’)
appdbfile=stuff(appfile,at(’txt’,appfile),3,’dbf’)
iffile(appdbfile)
deletefile&appdbfile
endif
create&appdbfilefromstruc
use&appdbfilealiasapp
appendfrom&appfilefieldsworddeli
deleteallforlen(alltrim(word))=0
pack
iffile(’詞組庫.dbf’)
setmessageto"刪除與’詞組庫.dbf’重復的詞組"
dodelexistword
endif
setmessageto’正在生成編碼’
dogenerate_wbcode
iffile(’詞組庫.dbf’)
setmessageto’增補到詞組庫并重新索引’
use詞組庫
appendfrom&appdbfile
else
setmessageto’建立詞組庫和其索引’
copyfile&appdbfileto詞組庫.dbf
use詞組庫
indexoncodetagcode
indexonwordtagwordof詞組庫
endif
use
deletefile&appdbfile
setmessageto’正在生成windows的碼表文件’
dotowinform
setmessageto’windows格式碼表文件生成完畢!’
waitwindowtimeout5
settalkon
setnotifyon
setmessageto
return
*********子過程***********
&&檢查是否和’詞組庫.dbf’有重碼
proceduredelexistword
select0
use詞組庫
setordertoword
selectapp
setrelationtowordinto詞組庫
gotop
dowhile.not.eof(’app’)
if.not.eof(’詞組庫’)
delete
endif
skip
enddo
pack
select詞組庫
use
return
&&生成五筆字型編碼
proceduregenerate_wbcode
privatewbcode,wordstring,wordlength,i
select0
use字碼ordertagwordof字碼
selectapp
gototop
dowhile.not.eof(’app’)
wbcode=’’
wordstring=word
wordlength=len(alltrim(wordstring))
select字碼
docase
casewordlength=4
fori=1to2
zi=substr(wordstring,2*i-1,2)
find&zi
wbcode=wbcode+code
next
casewordlength=6
fori=1to3
zi=substr(wordstring,2*i-1,2)
find&zi
docase
casei=1.or.i=2
wbcode=wbcode+substr(code,1,1)
casei=3
wbcode=wbcode+code
endcase
next
casewordlength=8
fori=1to4
zi=substr(wordstring,2*i-1,2)
find&zi
wbcode=wbcode+substr(code,1,1)
next
casewordlength>8
fori=1to3
zi=substr(wordstring,2*i-1,2)
find&zi
wbcode=wbcode+substr(code,1,1)
next
zi=substr(wordstring,wordlength-1,2)
find&zi
wbcode=wbcode+substr(code,1,1)
endcase
selectapp
replacecodewithwbcode
skip
enddo
closedatabases
return
&&生成windows格式碼表文件
proceduretowinform
privatehead,word_code,txt,i
iffile(’mbase.dbf’)
deletefilembase.dbf
deletefilembase.cdx
endif
creatembasefromstruc
appendfrom單字
appendfrom詞組庫
indexoncodetagcodeofmbase
dimensionmbhead[7]
dimensionword_code[2]
mbhead[1]=’[description]’
mbhead[2]=’name=五筆字型’
mbhead[3]=’maxcodes=4’
mbhead[4]="usedcodes=’abcdefghijklmnopqrstuvwxy"
mbhead[5]=’wildchar=z’
mbhead[6]=’sort=0’
mbhead[7]=’[text]’
mbtext=’五筆字型.txt’
txt=fcreate(mbtext)
fori=1to7
=fputs(txt,mbhead[i])
next
gototop
dowhile.not.eof()
scattertoword_code
skip
=fputs(txt,alltrim(word_code[2])+alltrim(word_code[1]))
enddo
use
=fclose(txt)
deletefilembase.dbf
deletefilembase.cdx
return
該程序使用的機器為386dx33,4m,在foxproforwindows2.5b環(huán)境下運行通過。
技術交流 永無止境
新聞熱點
疑難解答