我试图计算两篇文章之间的相似度,但是当我尝试模拟此处看到的美食示例代码时: https://neo4j.com/docs/graph-algorithms/current/algorithms/similarity-jaccard/
我遇到了类强制转换异常。
我的数据表示如下: 我的测试数据csv文件的表示如下:用于创建所有标题节点的CSV:
title_id,title
T1,Article Title 1
T2,Article Title 2
我要用于创建关系的CSV:
title_id,keyword_id,keyword
T1,K1,aaa
T1,K2,bbb
T1,K3,ccc
T1,K4,ddd
T2,K1,aaa
T2,K5,eee
T2,K6,fff
T2,K4,ddd
我使用的代码如下:
MATCH (search_query:Title)
-[:HAS_KEYWORDS]->(k_id:Keyword)
<-[:HAS_KEYWORDS]-(return_query:Title)
-[r2:HAS_KEYWORDS]->(rec_k:Keyword)
WITH {kw:id(search_query), categories: collect(k_id)} as userData
WITH collect(userData) as data
CALL algo.similarity.jaccard.stream(data, {similarityCutoff: 0.0})
YIELD item1, item2, count1, count2, intersection, similarity
RETURN algo.getNodeById(item1).name AS from,
algo.getNodeById(item2).name AS to,
intersection, similarity
ORDER BY similarity DESC
我最终收到此错误消息:
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure
`algo.similarity.jaccard.stream`: Caused by: java.lang.ClassCastException:
org.neo4j.kernel.impl.core.NodeProxy cannot be cast to java.lang.Number
我不太确定自己哪里出了问题,非常感谢任何建议。
答案 0 :(得分:0)
您必须在该过程的选项中使用正确的参数名称(item
代替kw
)和正确的数据类型(id
代替node
):< / p>
WITH {kw:id(search_query), categories: collect(k_id)} as userData
=>
WITH {items:id(search_query), categories: collect(id(k_id))} as userData