同义词的Matlab计算时间

时间:2014-04-10 13:58:36

标签: matlab matlab-guide matlab-compiler

我在下面给出的matlab代码中导入wordnet库,但是给我每个单词的同义词需要大约5-10秒。

可以以某种方式缩短它的时间,因为我必须在无数的单词上进行测试

由于

代码:

function [status,varargout] = dictionary(text)

%DICTIONARY checks the spelling status of word(s) and returns synonyms if found.
%
% [status,synonyms] = dictionary(text);
% status = dictionary(text);
% 
%     text:         word(s) separated by a single space.
%     status:       returns '1' if word(s) exist in dictionary or '0' otherwise.
%     synonyms:     an array of synonyms of word(s) or otherwise returns
%                   a message 'No Synonyms Found!' or 'Incorrect Spelling!'.
% 
% Examples:
%      [status,synonyms] = dictionary('peddler');
%      [status,synonyms] = dictionary('walk match ground');
%      status = dictionary('hysteria');
%
% Separating string of words into arrays of words.
k=1;
temp='';
% t=fopen('Crime.txt');
% text=textscan(t,'%s');
% text=texts{1,1};
% fclose(t);
%text='ignorevbnnn';
for n=1:length(text);
if ~isspace(text(n))
    temp = [temp text(n)];
else
    if ~isspace(text(n-1))
        words{k} = temp;
    end
    temp='';
    k=k+1;
end
end
    words{k} = temp;

% Opening MS Word and Starting the Spelling Check & Finding Synonyms

Doc = actxserver('Word.Application');
m=1;
for n=1:length(words)
if ~isempty(words{n})
    status(m) = invoke(Doc,'CheckSpelling',words{n},[],1,1);
    if nargout==2
        X = invoke(Doc,'SynonymInfo',words{n});
        Synonyms = get(X,'MeaningList');
        Meanings{m,1} = words{n};
        if length(Synonyms)==0 & status(m)==1
            Meanings{m,2} = 'No Synonyms Found!';
        elseif status(m)==0
            Meanings{m,2} = 'Incorrect Spelling!';
        else
            for k=2:length(Synonyms)+1
                Meanings{m,k} = Synonyms{k-1};
            end
        end
    end
    m=m+1;
end
end

if exist('Meanings','var')
varargout = {Meanings}; 
end
status = all(status);

invoke(Doc,'Quit');
delete(Doc);

0 个答案:

没有答案
相关问题