在文章中拆分单词并检查拼写错误

时间:2014-04-28 12:48:58

标签: matlab matlab-figure

我想检查一个aricle中的拼写错误,我有100篇文章要查看是否有拼写错误没有,如果得到一个错误然后单词返回1其他0.我必须将文章拆分为单词然后只检查。我在这里完成了所有这些,但问题是我无法检查分词的拼写错误。但是,我可以查看

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

输出: suggestion =

'table'

checkSpelling.m文件

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文件

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)

1 个答案:

答案 0 :(得分:1)

您的输入是一个单元格数组,尝试为您的函数提供单个字符串输入。适合我。