%% Search Documents for Word Occurrences
% 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);

% Search for the word "life".

tbl = context(documents,"life");
head(tbl)

% View the occurrences in a string array.

tbl.Context

%
% Copyright 2012 The MathWorks, Inc.