回复 10# qixiaobin0715
我简单写了一个进行拼音分词的批处理,由于是最大匹配,有时会有问题- @echo off
- set /p input=请输入拼音:
- set "input=%input: =%"
- if "%input%"=="" (echo,输入为空&exit)
- call :dict
- setlocal enabledelayedexpansion
- call :split "!%input:~0,1%!"
- echo,%result%
- pause
-
- :split
- if /i "%~1"=="" goto :eof
- set "qstring=%~1"
- for /l %%a in (5,-1,0) do if not "!input:~%%a,1!"=="" (
- set /a in=%%a+1
- call set "py=%%input:~0,!in!%%"
- goto :next
- )
- :next
- if /i "!qstring:%py% =!"=="%qstring%" (
- set "py=%py:~0,-1%"
- goto :next) else (
- set "result=!result! %py%"
- set "input=!input:%py%=!"
- if "!input!"=="" goto :eof
- call :split "%%!input:~0,1!%%"
- )
- goto :eof
-
-
- :dict
- set "a=a ai an ang ao "
- set "b=ba bai ban bang bao bei ben beng bi bian biao bie bin bing bo bu "
- set "c=ca cai can cang cao ce ceng cha chai chan chang chao che chen cheng chi chong chou chu chuai chuan chuang chui chun chuo ci cong cou cu cuan cui cun cuo "
- set "d=da dai dan dang dao de deng di dian diao die ding diu dong dou du duan dui dun duo "
- set "e=e en er "
- set "f=fa fan fang fei fen feng fo fou fu "
- set "g=ga gai gan gang gao ge gei gen geng gong gou gu gua guai guan guang gui gun guo "
- set "h=ha hai han hang hao he hei hen heng hong hou hu hua huai huan huang hui hun huo "
- set "j=ji jia jian jiang jiao jie jin jing jiong jiu ju juan jue jun "
- set "k=ka kai kan kang kao ke ken keng kong kou ku kua kuai kuan kuang kui kun kuo "
- set "l=la lai lan lang lao le lei leng li lia lian liang liao lie lin ling liu long lou lu lv luan lue lun luo "
- set "m=ma mai man mang mao me mei men meng mi mian miao mie min ming miu mo mou mu "
- set "n=na nai nan nang nao ne nei nen neng ni nian niang niao nie nin ning niu nong nu nv nuan nue nuo "
- set "o=o ou "
- set "p=pa pai pan pang pao pei pen peng pi pian piao pie pin ping po pu "
- set "q=qi qia qian qiang qiao qie qin qing qiong qiu qu quan que qun "
- set "r=ran rang rao re ren reng ri rong rou ru ruan rui run ruo "
- set "s=sa sai san sang sao se sen seng sha shai shan shang shao she shen sheng shi shou shu shua shuai shuan shuang shui shun shuo si song sou su suan sui sun suo "
- set "t=ta tai tan tang tao te teng ti tian tiao tie ting tong tou tu tuan tui tun tuo "
- set "w=wa wai wan wang wei wen weng wo wu "
- set "x=xi xia xian xiang xiao xie xin xing xiong xiu xu xuan xue xun "
- set "y=ya yan yang yao ye yi yin ying yo yong you yu yuan yue yun "
- set "z=za zai zan zang zao ze zei zen zeng zha zhai zhan zhang zhao zhe zhen zheng zhi zhong zhou zhu zhua zhuai zhuan zhuang zhui zhun zhuo zi zong zou zu zuan zui zun zuo "
复制代码 。 |