%% Remove N-Grams from Bag-of-N-Grams Model
% 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 top five n-grams.

topkngrams(bag,5)

%
% Remove the n-grams ["thou" "art"] and |["thou" "dost"] |from the model. View the new top 5 n-grams.

ngrams = [...
    "thou" "art"
    "thou" "dost"];
bag = removeNgrams(bag,ngrams);
topkngrams(bag,5)

%
% Copyright 2012 The MathWorks, Inc.