Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Word-frequency/MATLAB/word-frequency.m
Normal file
14
Task/Word-frequency/MATLAB/word-frequency.m
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function [result,count] = word_frequency()
|
||||
URL='https://www.gutenberg.org/files/135/135-0.txt';
|
||||
text=webread(URL);
|
||||
DELIMITER={' ', ',', ';', ':', '.', '/', '*', '!', '?', '<', '>', '(', ')', '[', ']','{', '}', '&','$','§','"','”','“','-','—','‘','\t','\n','\r'};
|
||||
words = sort(strsplit(lower(text),DELIMITER));
|
||||
flag = [find(~strcmp(words(1:end-1),words(2:end))),length(words)];
|
||||
dwords = words(flag); % get distinct words, and ...
|
||||
count = diff([0,flag]); % ... the corresponding occurance frequency
|
||||
[tmp,idx] = sort(-count); % sort according to occurance
|
||||
result = dwords(idx);
|
||||
count = count(idx);
|
||||
for k = 1:10,
|
||||
fprintf(1,'%d\t%s\n',count(k),result{k})
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue