%% Map Words to Encoding Indices
% Load the example data. The file sonnetsPreprocessed.txt contains preprocessed versions of Shakespeare's sonnets. The file contains one sonnet per line, with words separated by a space. Extract the text from sonnetsPreprocessed.txt, split the text into documents at newline characters, and then tokenize the documents.

filename = "sonnetsPreprocessed.txt";
str = extractFileText(filename);
textData = split(str,newline);
documents = tokenizedDocument(textData);
documents(1:10)

% Create a word encoding.

enc = wordEncoding(documents)

% Map the words "rose", "love", and "beauty" to encoding indices using the word2ind function.

words = ["rose" "love" "beauty"];
idx = word2ind(enc,words)

% Copyright 2018 The MathWorks, Inc.