title: Computing the similarity between two document using cosine similarity (neo4j)
body: <p>I have two documents represented by graphs in neo4j. The basic version of the graph describing of each document is as follows:
  - DocumentNode (represents each document name)
  - TokenNode (represents token mentioned in the document)
  These two label nodes are related throughout  the relationship "HAS_token"  which contains the property frequency (frequency of a token in a document).
  I wrote the following query but I'm not sure that it allows to compute efficiency the similarity:</p>
  
  <pre><code>MATCH (p1:DocumentNode {name: 'doc1'})-[r1:HAS_token]-&gt;(tag)
  MATCH (p2:DocumentNode {name: "doc2"})-[r2:HAS_token]-&gt;(tag)
  RETURN p1.name AS from,
         p2.name AS to,
         algo.similarity.cosine(collect(r1.score), collect(r2.score)) AS similarity
  </code></pre>
  
  <p>In addition, the Tag are related to Wikipedia Category (represented by the label Category) via the relationship HAS_category. Is there any way to include the category of each tag when computing the cosine similarity?</p>