cypher - 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?
解决方案
我已经采取了由查询语言语法差异引起的类似问题。
这是我在 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;
推荐阅读
- python - 使用 row 函数获取 nan。但是,在将行与 nan 进行比较时,条件变为 False
- docusignapi - 如何在 NetSuite 中将文件(例如 PDF)编码为 base64
- c# - 从不在 MyList 中的实体中选择
(字段)使用实体框架 - php - 使用一个键数组过滤另一个数组,保持“顺序”
- rust - 将参数/标志传递给`build.rs`
- matlab - 在matlab的列中拆分行
- php - 脚本更新 database.php Laravel
- intellij-idea - 无法在 Intellij 中打开 sample.fxml Javafx
- java - Jboss 7.1.1 ssl (https) 配置
- regex - 如何搜索与正则表达式不匹配的字符串