Home > asr > pa2pa.m

pa2pa

PURPOSE ^

pa2pa: PA (phonetic alphabet) to PA conversion (mainly Hanyu vs. Zhuyin)

SYNOPSIS ^

function out=pa2pa(in, paList)

DESCRIPTION ^

pa2pa: PA (phonetic alphabet) to PA conversion (mainly Hanyu vs. Zhuyin)
    Usage: out=pa2pa(in, paList)

    For example:
        pa2pa('guo')
        pa2pa('£¡£¸£«')
        pa2pa({'qing', 'hua', 'da', 'xue'})
        pa2pa({'£~£¯', '£¡£¸£±', '£¢£¸', '£~£±'})

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out=pa2pa(in, paList)
0002 %pa2pa: PA (phonetic alphabet) to PA conversion (mainly Hanyu vs. Zhuyin)
0003 %    Usage: out=pa2pa(in, paList)
0004 %
0005 %    For example:
0006 %        pa2pa('guo')
0007 %        pa2pa('£¡£¸£«')
0008 %        pa2pa({'qing', 'hua', 'da', 'xue'})
0009 %        pa2pa({'£~£¯', '£¡£¸£±', '£¢£¸', '£~£±'})
0010 
0011 %    Roger Jang, 20081026
0012 
0013 if nargin<1, selfdemo; return; end
0014 if nargin<2
0015 %    paList=tableRead('chinese.pa', 1, {'yinma', 'hanyu', 'zhuyin', 'cgu'});        % Too slow!
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 % ====== Selfdemo
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));

Generated on Tue 01-Jun-2010 09:50:19 by m2html © 2003