简体   繁体   English

什么食谱与苹果烤饼最相似-按照与该食谱相似的顺序输出其他食谱的成分列表

[英]What recipe is the most similar to apple scones - output list of ingredients from other recipes in order of similarity to this recipe

Here is what I have done so far: 到目前为止,这是我所做的:

MATCH (:Cake{name: 'Apple Scones'})-[n]-(a)
WITH COLLECT(a) AS list
MATCH (b)-[:CONTAINS]->(a)
RETURN list

I am trying to get the cake that is most similar to the ingredients in apple scones. 我试图得到与苹果烤饼中的食材最相似的蛋糕。 I have the list of all ingredients in apple scones, but am not sure how to compare it with the rest of the cakes. 我有苹果烤饼中所有成分的清单,但不确定如何将其与其他蛋糕进行比较。

Any feedback will be greatly appreciated. 任何反馈将不胜感激。

Thanks 谢谢

This query may do what you want: 此查询可能会执行您想要的操作:

MATCH (:Cake {name: 'Apple Scones'})-[:CONTAINS]->(i)<-[:CONTAINS]-(recipe)
RETURN recipe, COLLECT(i) AS sharedIngredients
ORDER BY SIZE(sharedIngredients) DESC;

It returns each recipe that has at least one ingredient in common with Apple Scones , along with a list of shared ingredients. 它返回每种食谱,这些食谱至少具有与Apple Scones相同的一种成分,以及一系列共享成分。 The results are returned in descending order by the number of shared ingredients. 结果按共享成分数的降序返回。

That query won't work so well...in the WITH you didn't bring over a , so your subsequent match will match on all nodes that have a :CONTAINS relationship to anything. 该查询无法很好地进行...在WITH中,您没有带来a ,因此您的后续匹配将在与任何对象具有:CONTAINS关系的所有节点上进行匹配。 That's going to be a ton of nodes. 那将是大量的节点。

You might look at this knowledge base article for insight. 您可以查看此知识库文章以获取洞见。

Here's one query that will find recipes that contain exactly the same ingredients: 这是一个查询,将查找包含完全相同成分的配方:

MATCH (:Cake{name: 'Apple Scones'})-[:CONTAINS]-(a) 
WITH a, size((a)<-[:CONTAINS]-()) as degree
ORDER BY degree ASC
WITH collect(a) as ingredients
WITH tail(ingredients) as list, head(ingredients) as first
MATCH (first)<-[:CONTAINS]-(recipe)
WHERE ALL(i in tail(list) WHERE (i)<-[:CONTAINS]-(recipe))
RETURN recipe

Otherwise you might look for a query that matches all ingredients to all recipes that contain them, and then order by those with the most ingredients in common and take some limited set of results: 否则,您可能会寻找一个查询,将所有成分与包含它们的所有配方匹配,然后按那些具有最常见成分的配方进行排序,并获得一些有限的结果:

MATCH (:Cake{name: 'Apple Scones'})-[:CONTAINS*2]-(recipe)
WITH recipe, count(recipe) as commonIngredients
ORDER BY commonIngredients DESC
LIMIT 5
RETURN recipe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM