getVocabList.m 761 B

12345678910111213141516171819202122232425
  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. %% Read the fixed vocabulary list
  7. fid = fopen('vocab.txt');
  8. % Store all dictionary words in cell array vocab{}
  9. n = 1899; % Total number of words in the dictionary
  10. % For ease of implementation, we use a struct to map the strings => integers
  11. % In practice, you'll want to use some form of hashmap
  12. vocabList = cell(n, 1);
  13. for i = 1:n
  14. % Word Index (can ignore since it will be = i)
  15. fscanf(fid, '%d', 1);
  16. % Actual Word
  17. vocabList{i} = fscanf(fid, '%s', 1);
  18. end
  19. fclose(fid);
  20. end