%% 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 bm25Similarity function. The output is a sparse matrix.

similarities = bm25Similarity(documents);

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

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

% The first three documents have the highest pairwise similarities which indicates that these documents are most similar. The last document has comparatively low pairwise similarities with the other documents which indicates that this document is less like the other documents.
% Copyright 2019 The MathWorks, Inc.