首页 > 解决方案 > Cypher query: How to compute cosine similarity in Agensgraph, and SAP HANA

问题描述

I wanna test simple graph analysis performance among GraphDBes using cypher.

I referred this site and reproduce the example in Neo4j, Agensgraph, SAP HANA, and Redis.

but the cypher query(see below) is not operate in Agensgraph, and SAP HANA.

MATCH (p1:Person {name:'Michael Sherman'})-[r1:RATED]->(m:Movie)<-[r2:RATED]-(p2:Person {name:'Michael Hunger'}) RETURN m.name AS Movie, r1.rating AS `M. Sherman's Rating`, r2.rating AS `M. Hunger's Rating`

I think the second arrow pattern doesn't works in Agensgraph, and SAP HANA.

How can I edit this query to operate in Agensgraph, and SAP HANA?

标签: cypherhanaagens-graph

解决方案


我已经采取了由查询语言语法差异引起的类似问题。

这是我在 AgesnGraph 中找出相似性的查询。您只需稍作修改即可计算余弦相似度。

MATCH (u1:users {userid:'Toby'})-[r1:hasrated]->(m:movies)<-[r2:hasrated]-(u2:users) 
WITH distinct u1.userid as u1name, u2.userid as u2name, 
SUM(r1.rating::float*r2.rating::float) as xyDotProduct, 
SQRT(SUM(r1.rating::float^2)) as xLength, 
SQRT(SUM(r2.rating::float^2)) as yLength 
RETURN u1name, u2name, xyDotProduct::float/(xLength::float*yLength::float) as similarity;

推荐阅读