简体   繁体   English

ArangoDB-如何查找与特定节点无关的节点?

[英]ArangoDB - How to find nodes not related to a specific one?

For clarity purpose, step names are used as identifiers 为了清楚起见,将步骤名称用作标识符

I have the following Directed Acyclic Graph (DAG): 我有以下有向无环图(DAG):

DAG图

What I'm trying to do is select a node, and find all the other nodes that are not connected directly to the selected one, only in an outbound direction. 我想做的是选择一个节点,并仅在出站方向上找到未直接连接到所选节点的所有其他节点。

For example: if I select "root step", my query should only return "test step 3", since it is the only one not connected directly to "root step". 例如:如果我选择“ root step”,则查询应该只返回“ test step 3”,因为它是唯一未直接连接到“ root step”的查询。

However , if I select "test step 2", it should only return "test step 3", and not "test step", because "test step* is at the same level that "test step 2" is. 但是 ,如果我选择“测试步骤2”,则应该返回“测试步骤3”,而不返回“测试步骤”,因为“测试步骤*”与“测试步骤2”处于同一级别。

For now, here is how I do: 现在,这是我的工作方式:

I store, in every "step", the list of parents it has as an array. 我在每个“步骤”中将其拥有的父母列表存储为一个数组。 (test step has ["root step"], etc.) (测试步骤具有[“ root step”]等)

My query is as follows ( for test step 2 as an example ): 我的查询如下(以测试步骤2为例):

FOR v, e IN 0..10 OUTBOUND "steps/test step 2" steps_relations
    FILTER e._from != "steps/test step 2"
    FILTER e._to != "steps/test step 2"
    FILTER v._id != "steps/test step 2"
    FILTER ["root step"] NONE IN v.parents
RETURN {id: v._key, name: v.name }

For now it returns an empty result instead of the expected ("test step 3"). 现在,它返回一个空结果而不是预期的结果(“测试步骤3”)。 Any help is greatly appreciated 任何帮助是极大的赞赏

I have finally managed to fix this. 我终于设法解决了这个问题。 Here is how I did it: 这是我的做法:

first, I added two fields to each one of my "steps" document: 首先,我在“步骤”文档的每个文档中添加了两个字段:

  • root: equals true when it is the root of the tree (like "root step"). 根:当它是树的根时(例如“根步骤”),等于true Otherwise it simply references the internal ID of the root step 否则,它仅引用根步骤的内部ID

  • depth: equals to 0 for the root step, but is incremented. 深度:根步长等于0,但增加。 When I add a step to another, the new step's depth equals (parent + 1) ONLY if the result is bigger than the one actually stored. 当我将一个步骤添加到另一个步骤时,仅当结果大于实际存储的结果时,新步骤的深度才等于(父级+ 1)。

Once I have this, my query looks as follows: 一旦有了这个,我的查询将如下所示:

Situation: I want to list all the steps that can be linked to "test step 2" 情况:我想列出所有可以链接到“测试步骤2”的步骤

FOR step, relation IN 0..10 ANY "steps/root step" steps_relations
    FILTER step.depth > 1 /* THE DEPTH OF test step 2 WICH IS 1 */
    FILTER relation._from != "steps/test step 2" 
RETURN item

This returns successfully "test step 3" 这将成功返回“测试步骤3”

You should rather use the min attribute to suppress edges directly connected: 您应该使用min属性来抑制直接连接的边:

FOR v, e IN 2..10 OUTBOUND "steps/test step 2" steps_relations
  RETURN {id: v._key, name: v.name }

this way you will only get paths longer than one edge-hop, and the vertices from 2 onwards. 这样,您只会获得比一个边缘跳更长的路径,并且顶点将从2开始。

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

相关问题 使用SQLAlchemy中的图,如何找到未通过边缘连接到某些特定其他节点的节点? - With graphs in SQLAlchemy, how can one find nodes that are not connected to some specific other node by an edge? 如何在没有启动节点的情况下获取ArangoDB中的所有图节点 - How to get all Graph Nodes in ArangoDB without Start-Node Neo4j:如何查找所有节点:连接到具有特定属性的0个节点或具有属性集的所有节点 - Neo4j: How to find all nodes that: connected to either 0 nodes with specific property, or all nodes with property set Gremlin搜索与2个或更多特定节点相关的顶点 - Gremlin search for vertexes related to 2 or more specific nodes 如何找到经过至少一个强制节点的两个节点之间的最短距离? - how to find the shortest distance between two nodes that pass at least one of the compulsory nodes? 查找通过图中特定节点的路径 - Find a path passing through specific nodes in a graph ArangoDB:从节点数组中获取所有链接 - ArangoDB: Get all links out of an array of nodes ArangoDB:查找路径中的最后一个节点 - ArangoDB: Find last node in path Arangodb Graph,使用哪一个 - Arangodb Graph, which one to use 如何在必须通过特定节点的有向图中找到最短路径? - How to find a shortest path in a directed graph which must pass through specific nodes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM