0001 function out=pa2pa(in, paList)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if nargin<1, selfdemo; return; end
0014 if nargin<2
0015
0016 [yinma, hanyu, zhuyin, cgu]=textread('chinese.pa', '%s\t%s\t%s\t%s');
0017 count=length(yinma);
0018 [paList(1:count).yinma] = deal(yinma{:});
0019 [paList(1:count).hanyu] = deal(hanyu{:});
0020 [paList(1:count).zhuyin] = deal(zhuyin{:});
0021 end
0022
0023 if isstr(in)
0024 hanyu={paList.hanyu};
0025 zhuyin={paList.zhuyin};
0026 index=find(strcmp(in, hanyu));
0027 if length(index)==1
0028 out=zhuyin{index};
0029 return
0030 end
0031 index=find(strcmp(in, zhuyin));
0032 if length(index)==1
0033 out=hanyu{index};
0034 return
0035 end
0036 error(sprintf('Cannot find %s in the dictionary!\n', in));
0037 end
0038 if iscell(in)
0039 for i=1:length(in)
0040 out{i}=pa2pa(in{i}, paList);
0041 end
0042 end
0043
0044
0045 function selfdemo
0046 input='guo';
0047 output=pa2pa(input);
0048 fprintf('input=%s, output=%s\n', input, output);
0049 input='£¡£¸£«';
0050 output=pa2pa(input);
0051 fprintf('input=%s, output=%s\n', input, output);
0052 input={'qing', 'hua', 'da', 'xue'};
0053 output=pa2pa(input);
0054 fprintf('input=%s, output=%s\n', cell2str(input), cell2str(output));
0055 input={'£~£¯', '£¡£¸£±', '£¢£¸', '£~£±'};
0056 output=pa2pa(input);
0057 fprintf('input=%s, output=%s\n', cell2str(input), cell2str(output));