0001 function output=syl2css(syl, dict)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if nargin<1; selfdemo; return; end
0021 if nargin<2; dict=[]; end
0022
0023 output={syl};
0024
0025 beginPhone1={'ch', 'r', 'c', 'q'};
0026 beginPhone2={'zh', 'l', 'z', 'j'};
0027 for i=1:length(beginPhone1)
0028 pat=['^', beginPhone1{i}];
0029 newSyl=regexprep(syl, pat, beginPhone2{i});
0030 if ~strcmp(syl, newSyl)
0031 output={output{:}, newSyl};
0032 break;
0033 end
0034 end
0035
0036 endPhone1={'an', 'eng', 'en', 'iu'};
0037 endPhone2={'ang', 'en', 'eng', 'iu2'};
0038 base=output;
0039 for j=1:length(base)
0040 syl=base{j};
0041 for i=1:length(endPhone1)
0042 pat=[endPhone1{i}, '$'];
0043 newSyl=regexprep(syl, pat, endPhone2{i});
0044 if ~strcmp(syl, newSyl)
0045 output={output{:}, newSyl};
0046 break;
0047 end
0048 end
0049 end
0050
0051 endPhone1={'bo', 'fo', 'mo', 'po'};
0052 endPhone2={'bo2', 'fo2', 'mo2', 'po2'};
0053 base=output;
0054 for j=1:length(base)
0055 syl=base{j};
0056 for i=1:length(endPhone1)
0057 pat=['^', endPhone1{i}, '$'];
0058 newSyl=regexprep(syl, pat, endPhone2{i});
0059 if ~strcmp(syl, newSyl)
0060 output={output{:}, newSyl};
0061 break;
0062 end
0063 end
0064 end
0065
0066 if ~isempty(dict)
0067
0068 allSyls={dict.word};
0069 index=[];
0070 for i=1:length(output)
0071 if ~any(strcmp(output{i}, allSyls))
0072 index=[index, i];
0073 end
0074 end
0075 output(index)=[];
0076 end
0077
0078
0079 function selfdemo
0080 syl='ren'
0081 css1=syl2css(syl)
0082 dictFile='hanyu.dic';
0083 dict=dictRead(dictFile);
0084 css2=syl2css(syl, dict)