Home > asr > wpaRead2.m

wpaRead2

PURPOSE ^

wpaRead: Read a wpa file

SYNOPSIS ^

function wpa=wpaRead(wpaFile)

DESCRIPTION ^

 wpaRead: Read a wpa file
    Usage: wpa=wpaRead(wpaFile)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function wpa=wpaRead(wpaFile)
0002 % wpaRead: Read a wpa file
0003 %    Usage: wpa=wpaRead(wpaFile)
0004 
0005 contents = textread(wpaFile, '%s', 'delimiter', '\n', 'whitespace', '');
0006 
0007 % Remove comments line that start with "%"
0008 index=[];
0009 for i=1:length(contents)
0010     if contents{i}(1)=='%'            % Comment
0011         index=[index, i];
0012     end
0013 end
0014 contents(index)=[];
0015 
0016 n=length(contents);
0017 wpa=struct('word', mat2cell(1:n, 1, ones(1,n)));    % 若不加此列,此部分之計算時間會由6.75秒暴增到290秒!!!
0018 for i=1:length(contents)
0019     if mod(i, 1000)==0
0020         fprintf('%d/%d\n', i, length(contents));
0021     end
0022     line=contents{i};
0023     if isempty(line)
0024         continue;
0025     end
0026     items=split(line, [9]);        % Delimited by tab
0027     if isempty(items{end})
0028         items(end)=[];
0029     end
0030     wpa(i).word=items{1};
0031     wpa(i).pa=items{2};
0032 end

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