简体   繁体   English

从边缘集合创建arango图

[英]Create arango graph from an edge collection

I'm working in arangosh (the ArangoDB Shell) trying to put together some graph analyses (which I'll move over to Foxx later, if I can get this working). 我正在arangosh(ArangoDB Shell)中尝试将一些图形分析放在一起(如果可以的话,我将在以后移至Foxx)。

I have two collections. 我有两个收藏。 A collection of vertices we'll call People , and an edge collection, Relationships . 我们称其为People一组顶点,以及一个名为Relationships的边缘。

Following the manual I can create a graph based on People : 按照手册,我可以基于People创建一个图形:

var graph_module = require("@arangodb/general-graph");
var graph = graph_module._create("population");

graph._addVertexCollection("People");

But I know that People does not contain the information necessary to connect the vertices in this graph. 但是我知道People不包含连接此图中顶点的必要信息。 If anything, I'd rather simply create the graph from the edge collection Relationships since, by definition, all docs in edge collections have the _to and _from fields, from which the graph can be fully specified. 如果有的话,我宁愿简单地从边缘集合Relationships创建图形,因为根据定义,边缘集合中的所有文档都具有_to_from字段,可以从中完全指定图形。

I find the next pages of the manual to be absolutely baffling (my apologies to the authors) and would appreciate any guidance on how to either directly create a graph from an edge collection, or incorporate information from an edge collection into an existing graph. 我发现手册下一页绝对令人困惑(对作者致歉),并且希望获得有关如何直接从边缘集合中创建图形或将边缘集合中的信息合并到现有图形中的任何指导。

So it looks like you want to create a graph with no defined vertex collection, but with an edge collection only. 因此,看起来您想创建一个没有定义顶点集合但仅具有边集合的图形。 As far as I'm aware of, you must have some sort of vertex collection from which edges may emanate from or go to. 据我所知,您必须具有某种顶点集合,边缘可能从该顶点集合发出或进入。 But you do not need to explicitly include this vertex collection into your graph. 但是,您无需将此顶点集合显式包括到图形中。 According to the 2.8 docs which admittedly doesn't exactly detail everything, you can create a graph with just edge collections: 根据2.8文档 ,它不能完全详细描述所有内容,因此您可以创建仅包含边缘集合的图形:

arangosh> var graph_module = require("org/arangodb/general-graph");
arangosh> var edgeDefinitions = [ { collection: "edges", "from": [ "vertices" ], "to" : [ "vertices" ] } ];
arangosh> graph = graph_module._create("myGraph", edgeDefinitions);
[ Graph myGraph EdgeDefinitions: [ 
  "edges: [vertices] -> [vertices]" 
] VertexCollections: [ ] ]

Note that the collection "vertices" must exist. 请注意,集合“顶点”必须存在。 You do not necessarily need for the nodes that are referenced in the "edges" collection to exist. 您不一定需要存在“ edges”集合中引用的节点。 But if you want to do anything like a traversal, the nodes must exist in the "vertices" collection, otherwise you'll get "null" as a response for those traversals. 但是,如果您想进行遍历之类的操作,则这些节点必须存在于“顶点”集合中,否则,对于这些遍历,您将获得“ null”作为响应。

(Pretty sure this answer is applicable to 3.0 as well, but I've mainly been using 2.8 and have yet to upgrade.) (当然,这个答案也适用于3.0,但我主要是在使用2.8,但尚未升级。)

The following remarks have been verified using ArangoDB 3.2. 以下说明已使用ArangoDB 3.2进行了验证。

In brief, ArangoDB supports meta-graphs. 简而言之,ArangoDB支持元图。 That is, it is possible to have graphs whose "nodes" are objects in an Edge collection. 即, 可能具有其“节点”是Edge集合中的对象的图。

Indeed, such graphs are quite ordinary. 确实,这样的图很普通。

For example, suppose we have a Graph, "knows_graph", relating Person to Person, and that the edges of the graph are in the "who_knows_who" Edge collection. 例如,假设我们有一个图,“ knows_graph”,将“人与人”关联起来,并且图的边缘在“ who_knows_who” Edge集合中。

We can create an additional graph, say "causation_graph", relating the "who_knows_who" edges. 我们可以创建一个附加图,例如“ causation_graph”,它与“ who_knows_who”边相关。 For example, maybe "Alice knows Bob" resulted in Bob getting to know Charles: 例如,也许“爱丽丝知道鲍勃”导致鲍勃认识了查尔斯:

 knows(_from: Alice, _to: Bob) => knows(_from: Bob, _to: Charles)

Let's suppose we gave the name "caused" to the Edge collection in the "causation_graph". 假设我们在“ causation_graph”中为Edge集合命名为“ caused”。 Then we can say that in the normal course of things, we started with a Document collection (Person), created an Edge collection (who_knows_who) with Person as the substrate, and then created a "meta-edge" Edge collection whose substrate is the Edge collection, caused . 然后我们可以说,在正常情况下,我们从文档集合(Person)开始,创建以Person为基材的Edge集合(who_knows_who),然后创建以基材为基材的“元边缘” Edge集合。 导致边缘收集。

When using the ArangoDB GUI, one cannot create a Graph without a pre-existing Edge collection, and normally an Edge collection has one or more Document collections as its substrate. 使用ArangoDB GUI时,如果没有预先存在的Edge集合就无法创建图,并且通常Edge集合具有一个或多个Document集合作为其基础。

However, it is actually possible to create a self-referential Edge collection: let's call it "selfie". 但是,实际上可以创建一个自引用的Edge集合:我们称其为“ selfie”。 It's likely to tie you up in knots, so be warned. 可能会使您陷入困境,因此请注意。 But technically it is possible to have an ArangoDB Graph that is "edges" all the way down. 但是从技术上讲,可能有一个ArangoDB Graph一直处于“边缘”状态。

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

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