%% 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 documents and query documents using the bm25Similarity function. The output is a sparse matrix. The score in similarities(i,j) represents the similarity between documents(i) and queries(j).

similarities = bm25Similarity(documents,queries);

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

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

% In this case, the first input document is most like the first query document.
% Copyright 2019 The MathWorks, Inc.