Search code examples
nlpmatlabmatlab-deploymentmatlab-compiler

Fast Synonyms' Calculations in Matlab


ok I have now got code in Matlab, which compute synonym in less than a second...

clc
clear all
close all
warning off
text = 'good';

Doc = actxserver('Word.Application');
X = invoke(Doc,'SynonymInfo',text);
Synonyms = get(X,'MeaningList');

But now issue is, its computing it for one word. How can I use it in an array? Like if I have file of words? Please guide

Thanks a lot


Solution

  • You could use cellfun and organize the words in a cell array:

    words = {'good', 'bad', 'apple'};
    
    Doc = actxserver('Word.Application');
    X = cellfun(@(word) invoke(Doc,'SynonymInfo',word), words, 'UniformOutput', false);
    Synonyms = cellfun(@(X) get(X,'MeaningList'), X, 'UniformOutput', false);
    

    Now you can access Synonyms{3}, for example, to retrieve the synonyms of "apple".