Moving course1 to course1 subdir.
This commit is contained in:
25
machine_learning/course1/mlclass-ex6-008/mlclass-ex6/getVocabList.m
Executable file
25
machine_learning/course1/mlclass-ex6-008/mlclass-ex6/getVocabList.m
Executable file
@@ -0,0 +1,25 @@
|
||||
function vocabList = getVocabList()
|
||||
%GETVOCABLIST reads the fixed vocabulary list in vocab.txt and returns a
|
||||
%cell array of the words
|
||||
% vocabList = GETVOCABLIST() reads the fixed vocabulary list in vocab.txt
|
||||
% and returns a cell array of the words in vocabList.
|
||||
|
||||
|
||||
%% Read the fixed vocabulary list
|
||||
fid = fopen('vocab.txt');
|
||||
|
||||
% Store all dictionary words in cell array vocab{}
|
||||
n = 1899; % Total number of words in the dictionary
|
||||
|
||||
% For ease of implementation, we use a struct to map the strings => integers
|
||||
% In practice, you'll want to use some form of hashmap
|
||||
vocabList = cell(n, 1);
|
||||
for i = 1:n
|
||||
% Word Index (can ignore since it will be = i)
|
||||
fscanf(fid, '%d', 1);
|
||||
% Actual Word
|
||||
vocabList{i} = fscanf(fid, '%s', 1);
|
||||
end
|
||||
fclose(fid);
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user