%% Similarity Between Documents
% Create an array of tokenized documents.

textData = [
    "the quick brown fox jumped over the lazy dog"
    "the fast brown fox jumped over the lazy dog"
    "the lazy dog sat there and did nothing"
    "the other animals sat there watching"];
documents = tokenizedDocument(textData)

% Calculate the similarities between them using the cosineSimilarity function. The output is a sparse matrix.

similarities = cosineSimilarity(documents);

% Visualize the similarities between the documents in a heat map.

figure
heatmap(similarities);
xlabel("Document")
ylabel("Document")
title("Cosine Similarities")

% Scores close to one indicate strong similarity. Scores close to zero indicate weak similarity.
%
% Copyright 2019 The MathWorks, Inc.