%% Remove N-Grams from Bag-of-N-Grams Model by Index
% 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);

% Create bag-of-n-grams model.

bag = bagOfNgrams(documents)

% View the first ten n-grams in the model.

bag.Ngrams(1:10,:)

% Remove the 9th and 10th n-grams from the model. View the new list of the first ten n-grams.

idx = [9 10];
bag = removeNgrams(bag,idx);
bag.Ngrams(1:10,:)

% Copyright 2012 The MathWorks, Inc.