Home > asr > wpaRead.m

wpaRead

PURPOSE ^

wpaRead: Read wpa file into a structure

SYNOPSIS ^

function [wpa, uniqModels]=wpaRead(wpaFile)

DESCRIPTION ^

 wpaRead: Read wpa file into a structure
    Usage: [wpa, uniqModels]=wpaRead(wpaFile)

    For example:
        wpa = wpaRead('chinese.hanyu.wpa');

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [wpa, uniqModels]=wpaRead(wpaFile)
0002 % wpaRead: Read wpa file into a structure
0003 %    Usage: [wpa, uniqModels]=wpaRead(wpaFile)
0004 %
0005 %    For example:
0006 %        wpa = wpaRead('chinese.hanyu.wpa');
0007 
0008 %    Roger Jang, 20081025, 20091022
0009 
0010 [word, pa]=textread(wpaFile, '%s\t%s');
0011 wordNum=length(word);
0012 [wpa(1:wordNum).word] = deal(word{:});
0013 [wpa(1:wordNum).pa] = deal(pa{:});
0014 
0015 if nargout>1
0016     modelInWpa={};
0017     for i=1:length(wpa)
0018         items=split(wpa(i).pa, '#');
0019         for j=1:length(items)
0020             monophones=split(items{j}, '_');
0021             for k=1:length(monophones)-1
0022                 biphone=[monophones{k}, '+', monophones{k+1}];
0023                 modelInWpa{end+1}=biphone;
0024             end
0025             biphone=[monophones{end}, '+sil'];
0026             modelInWpa{end+1}=biphone;
0027         end
0028     end
0029     uniqModels=unique(modelInWpa);
0030 end
0031 
0032 % Lines start with % are comments ===> time consuming!
0033 %index=[];
0034 %for i=1:length(wpa)
0035 %    if wpa(i).word(1)=='%'
0036 %        index=[index, i];
0037 %    end
0038 %end
0039 %wpa(index)[];
0040 
0041 % Split pa into cell string ===> time consuming
0042 %for i=1:length(wpa)
0043 %    if ~isempty(findstr('#', wpa(i).pa))
0044 %        wpa(i).pa=split(wpa(i).pa, '#');
0045 %    else
0046 %        wpa(i).pa={wpa(i).pa};
0047 %    end
0048 %end

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