0001 function output=text2pa4english(text, wpa)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if nargin<1, selfdemo; return; end
0016 if nargin<2,
0017 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0018 exeDir=[parentDir, '\exe'];
0019 englishWpaFile=[exeDir, '\asraData\english\english.wpa'];
0020 fprintf('Reading %s...\n', englishWpaFile);
0021 wpa=wpaRead(englishWpaFile);
0022 end
0023 words={wpa.word};
0024 tokens=textNormalize4english(text);
0025
0026
0027 for i=1:length(tokens)
0028 output(i).word=tokens{i};
0029 index=find(strcmp(tokens{i}, words));
0030 if length(index)==0
0031 fprintf('Warning: Cannot find "%s" in the WPA list!\n', tokens{i});
0032 end
0033 if length(index)==1
0034 output(i).pa=wpa(index).pa;
0035 end
0036 output(i).pa=split(output(i).pa, '#');
0037 end
0038
0039
0040 function selfdemo
0041 text='What are you allergic to?';
0042 output=text2pa4english(text)
0043 for i=1:length(output)
0044 fprintf('word=%s, pa=%s\n', output(i).word, cell2str(output(i).pa));
0045 end