Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 7/Programming Assignment - 6/ex6/getVocabList.m
863 views
1
function vocabList = getVocabList()
2
%GETVOCABLIST reads the fixed vocabulary list in vocab.txt and returns a
3
%cell array of the words
4
% vocabList = GETVOCABLIST() reads the fixed vocabulary list in vocab.txt
5
% and returns a cell array of the words in vocabList.
6
7
8
%% Read the fixed vocabulary list
9
fid = fopen('vocab.txt');
10
11
% Store all dictionary words in cell array vocab{}
12
n = 1899; % Total number of words in the dictionary
13
14
% For ease of implementation, we use a struct to map the strings => integers
15
% In practice, you'll want to use some form of hashmap
16
vocabList = cell(n, 1);
17
for i = 1:n
18
% Word Index (can ignore since it will be = i)
19
fscanf(fid, '%d', 1);
20
% Actual Word
21
vocabList{i} = fscanf(fid, '%s', 1);
22
end
23
fclose(fid);
24
25
end
26
27