Question

I want to check the spelling error within an aricle, I have 100 articles to check to see got spelling error of not, if got one error then word return 1 else 0. I have to split the article into words by word then only check. I have done all of these here, but the problem is i could not check the spelling error of the split word.However, I could check with

deliberate_mistake = 'tabel';
suggestion = checkSpelling(deliberate_mistake)   

output: suggestion =

'table'

checkSpelling.m file

function suggestion = checkSpelling(word)

h = actxserver('word.application');
h.Document.Add;
correct = h.CheckSpelling(word);
if correct
  suggestion = []; %return empty if spelled correctly
else
  %If incorrect and there are suggestions, return them in a cell array
  if h.GetSpellingSuggestions(word).count > 0
      count = h.GetSpellingSuggestions(word).count;
      for i = 1:count
          suggestion{i} = h.GetSpellingSuggestions(word).Item(i).get('name');
      end
  else
      %If incorrect but there are no suggestions, return this:
      suggestion = 'no suggestions';
  end
end
%Quit Word to release the server
h.Quit

f20.m file

for i = 1:1

data2=fopen(strcat('DATA\',int2str(i),''),'r')
CharData = fread(data2, '*char')';  %read text file and store data in CharData
fclose(data2);

word =regexp(CharData,' ','split')

[sizeData b] = size(word);

suggestion = checkSpelling(word)
Was it helpful?

Solution

Your input is a cell array, try to give your function a single string input. Works for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top