%% Specify Source Text
% Specify source text to display context.
% Load the sonnets.txt data and split it into separate documents.

txt = extractFileText("sonnets.txt");
paragraphs = split(txt,[newline newline]);

%
% Extract the sonnets from paragraphs. The first sonnet is the fifth element of paragraphs, and the remaining sonnets appear in every second element afterward.

sonnets = paragraphs(5:2:end);
documents = tokenizedDocument(sonnets);

%
% Normalize the text, then search for the word "life".

documentsNormalized = normalizeWords(documents);
T = context(documentsNormalized,"life")

%
% Since the words are normalized, the contexts may not be easy to read. To view the contexts using the original text data, specify the source text using the 'Source' option.

T = context(documentsNormalized,"life",'Source',sonnets)

%
% Copyright 2012 The MathWorks, Inc.