如何知道段落中最出现的单词? (Matlab) [英] How to know what word appears most in a paragraph? (Matlab)

查看:85
本文介绍了如何知道段落中最出现的单词? (Matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段很长的段落,想知道其中最出现的词.有人可以为此指出正确的方向吗?任何示例和解释都将有所帮助.谢谢!

I have a huge paragraph and want to know what word appears most in it. Could anyone please point me in the right direction with this? Any examples and explanations would be helpful. Thanks!

推荐答案

这是一个简单的解决方案,应该相当快.

Here is a simple solution, should be quite fast.

example_paragraph = 'This is an example corpus. Is is a verb?';

words = regexp(example_paragraph, ' ', 'split');
vocabulary = unique(words);
n = length(vocabulary);
counts = zeros(n, 1);
for i=1:n
    counts(i) = sum(strcmpi(words, vocabulary{i}));
end

[frequency_of_the_most_frequent_word, idx] = max(counts);
most_frequent_word = vocabulary{idx};

您还可以在此处签出答案,以从单词数组中获取最常用的单词.

You can also check out answers here for getting the most frequent word out of the array of words.

这篇关于如何知道段落中最出现的单词? (Matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆