Match(n:A)-->(t:B)
WITH collect(t.state) AS state, n
WITH [val IN state WHERE val = "good"] AS good, [val IN state WHERE val = "average"] AS avg, [val IN state WHERE val = "bad"] AS bad, n
WITH size(good) as goodCount, size(avg) as avgCount, size(bad) as badCount, n
SET n.embedding = [goodCount, badCount, avgCount]
return n.key, n.embedding
MATCH(n:A)-->(t:B)
WITH apoc.coll.indexOf(["good", "bad", "average"], t.state) as inx, n, [0,0,0] as k
WITH apoc.coll.set(k, inx, 1) AS k, n
WITH collect(k) as kk, n
WITH REDUCE(s = [], sublist IN kk | CASE
WHEN SIZE(s) = 0 THEN sublist
ELSE [i IN RANGE(0, SIZE(s)-1) | s[i] + sublist[i]]
END) AS result, n
SET n.embedding = result
RETURN n.key, n.embedding
match (c:ref)
with c order by c.order
with collect(c.name) as cn
MATCH(n:A)-->(t:B)
WITH apoc.coll.indexOf(cn, t.state) as inx, n, [0,0,0] as k
WITH apoc.coll.set(k, inx, 1) AS k, n
WITH collect(k) as kk, n
WITH REDUCE(s = [], sublist IN kk | CASE
WHEN SIZE(s) = 0 THEN sublist
ELSE [i IN RANGE(0, SIZE(s)-1) | s[i] + sublist[i]]
END) AS result, n
SET n.embedding = result
RETURN n.key, n.embedding
2条答案
按热度按时间b09cbbtk1#
一种方法是:
这会找到所有的
A
和它们的B
,将B
的状态收集到一个列表中,然后为每个状态创建不同的列表。接下来,我们会根据顺序得到每个状态列表的大小和SET
的embedding
值。最后一部分是返回A
的embedding
。您可以在以下示例数据上进行检查:
key
而不是id
。它会传回:
如果您有许多状态选项,则可以执行以下操作:
灵感源自this answer by @cybersam
pw9qyyiw2#
为了将其扩展到更多的州类别,我们可以在尼姆罗德的解决方案的基础上进行构建。
使用您类别设置引用节点集:
则查询变为
也可以将查询作为
在任何一种情况下,您都可以根据需要添加任意多个类别