如何从 apoc.path.expandConfig 或类似的 exclude/blacklist 关系类型?

How to exclude/blacklist relationship types from apoc.path.expandConfig or similar?

所以我试图找到一对不同类型的节点之间的路径。代码如下所示。该图非常大并且有许多不同类型的关系,其中一些我想从路径中 exclude/blacklisted,因为它们非常 redundant/uninteresting.

据我所知apoc.path.expandConfig does not allow for that natively.有什么办法可以做到这一点吗?

MATCH (sourceNode:SourceLabel {symbol: "<source node>"})
MATCH (targetNode:TargetLabel {name:"<target node>"})
CALL apoc.path.expandConfig(g, {
    labelFilter: "IntermediaryLabel1, IL2a|IL2b|IL2c, >TargetLabel",
    minLevel: 1,
    maxLevel: 3,
    terminatorNodes: [targetNode],
    uniqueness: "NODE_PATH",
    limit: 50
})
YIELD path
RETURN path, length(path) AS hops
ORDER BY hops

我已经 运行 解决了这个问题,但直到今天我看到你的问题时才坐下来解决它。如果你像我一样有很多人际关系,我能感受到你的痛苦。理想情况下,他们最终会为 rels 添加一个减法,但现在 DIY 并不难。

步骤

  1. 获取所有关系的列表
  2. 减去你不想要的
  3. apoc 调用中使用的格式
// get all relationships
CALL db.relationshipTypes() yield relationshipType WITH collect(relationshipType) as rt
// remove unwanted relationships
WITH [n IN rt WHERE NOT n IN ['PERTURBS','CAUSES_SIDE_EFFECT','TREATS','REPURPOSED_INDICATION','SUBSET_OF','GENE_EC','GENE_GENE']] as rt2
// format for use in apoc call
WITH REDUCE(ms = "",word IN rt2 | ms+word+'|') as js
// remove trailing pipe
WITH LEFT(js, SIZE(js)-1) as relationshipWhiteList
// your cypher here (and use the variable relationshipWhiteList)

用于拼凑此内容的参考文献

  • 减少:
  • 要过滤的列表理解: