%% Similarity to Query
% Create an array of input documents.

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

% Create an array of query documents.

str = [
    "a brown fox leaped over the lazy dog"
    "another fox leaped over the dog"];
queries = tokenizedDocument(str)

% Calculate the similarities between input and query documents using the cosineSimilarity function. The output is a sparse matrix.

similarities = cosineSimilarity(documents,queries);

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

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

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