annotate getVocabList.m @ 3:ace890ed0ed9 default tip

Use lookup to look for all words at once
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sat, 10 Dec 2011 15:56:02 -0500
parents f602dc601e9e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
1 function vocabList = getVocabList()
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
2 %GETVOCABLIST reads the fixed vocabulary list in vocab.txt and returns a
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
3 %cell array of the words
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
4 % vocabList = GETVOCABLIST() reads the fixed vocabulary list in vocab.txt
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
5 % and returns a cell array of the words in vocabList.
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
6
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
7
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
8 %% Read the fixed vocabulary list
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
9 fid = fopen('vocab.txt');
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
10
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
11 % Store all dictionary words in cell array vocab{}
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
12 n = 1899; % Total number of words in the dictionary
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
13
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
14 % For ease of implementation, we use a struct to map the strings => integers
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
15 % In practice, you'll want to use some form of hashmap
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
16 vocabList = cell(n, 1);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
17 for i = 1:n
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
18 % Word Index (can ignore since it will be = i)
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
19 fscanf(fid, '%d', 1);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
20 % Actual Word
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
21 vocabList{i} = fscanf(fid, '%s', 1);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
22 end
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
23 fclose(fid);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
24
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
25 end