Home > asr > dictRead.m

dictRead

PURPOSE ^

dictRead: Read a dic file

SYNOPSIS ^

function [dict, uniqModels]=dictRead(dictFile)

DESCRIPTION ^

 dictRead: Read a dic file
    Usage: [dict, uniqModels]=dictRead(dictFile)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dict, uniqModels]=dictRead(dictFile)
0002 % dictRead: Read a dic file
0003 %    Usage: [dict, uniqModels]=dictRead(dictFile)
0004 
0005 %    Roger Jang, 20091021
0006 
0007 contents = textread(dictFile, '%s', 'delimiter', '\n', 'whitespace', '');
0008 n=length(contents);
0009 dict=struct('word', mat2cell(1:n, 1, ones(1,n)));    % 若不加此列,此部分之計算時間會由6.75秒暴增到290秒!!!
0010 for i=1:length(contents)
0011     if mod(i, 1000)==0
0012         fprintf('%d/%d\n', i, length(contents));
0013     end
0014     line=contents{i};
0015     if isempty(line)
0016         continue;
0017     end
0018     items=split(line, [9, 32]);    % Delimited by tab or space
0019     if isempty(items{end})
0020         items(end)=[];
0021     end
0022     dict(i).word=items{1};
0023     for j=2:length(items)
0024         dict(i).model{j-1}=items{j};
0025     end
0026 end
0027 
0028 if nargout>1
0029     uniqModels=unique([dict.model]);
0030 end

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