我有一个使用NEO4j的图表,目前正在尝试构建一个比基于文本的搜索更好的简单推荐系统。
创建节点,例如:相册,人物,类型,图表
创建关系,例如:
People - [:role] -> Album
角色是:艺术家,制片人,歌曲作者
Album-[:is_a_type_of]->Type
(类型基本上是Pop,Rock,Disco ......)
People -[:POPULAR_ON]->Chart
(图表是他们可能的Billboard)
People -[:SIMILAR_TO]->People
(预定的相似性连接)
我写了以下密码:
MATCH (a:Album { id: { id } })-[:is_a_type_of]->(t)<-[:is_a_type_of]-(recommend)
WITH recommend, t, a
MATCH (recommend)<-[:ARTIST_OF]-(p)
OPTIONAL MATCH (p)-[:POPULAR_ON]->()
RETURN recommend, count(DISTINCT t) AS type
ORDER BY type DESC
LIMIT 25;
然而,如果只有一种类型的音乐连接到它,它很容易重复,因此有相同的邻居。
是否有建议的说法:
答案 0 :(得分:1)
您可以按此顺序使用4个配置并根据更高的值订购相册。保持配置在0到1之间(例如0.6)
a. People Popular on Chart and People are similar
b. People Popular on Chart and People are Not similar
c. People Not Popular on Chart and People are similar
d. People Not Popular on Chart and People are Not similar
计算每张专辑的4个值并将其相加。值越高,推荐的专辑越高。
我暂时将配置设为a = 1,b = 0.8,c = 0.6,d = 0.4。并假设存在一些关系,这表明一些人喜欢专辑。如果你只是基于图表制作逻辑,那么使用&amp;只有。
MATCH (me:People)
where id(me) = 123
MATCH (a:Album { id: 456 })-[:is_a_type_of]->(t:Type)<-[:is_a_type_of]-(recommend)
OPTIONAL MATCH (recommend)<-[:ARTIST_OF]-(a:People)-[:POPULAR_ON]->(:Chart)
WHERE exists((me)-[:SIMILAR_TO]->(a))
OPTIONAL MATCH (recommend)<-[:ARTIST_OF]-(b:People)-[:POPULAR_ON]->(:Chart)
WHERE NOT exists((me)-[:SIMILAR_TO]->(b))
OPTIONAL MATCH (recommend)<-[:LIKES]-(c:People)
WHERE exists((me)-[:SIMILAR_TO]->(a))
OPTIONAL MATCH (recommend)<-[:LIKES]-(d:People)
WHERE NOT exists((me)-[:SIMILAR_TO]->(a))
RETURN recommend, (count(a)*1 + count(b)*0.8 + count(c)* 0.6+count(d)*0.4) as rec_order
ORDER BY rec_order DESC
LIMIT 10;