随机种子节点遍历图数据库

随机种子节点遍历图数据库

本文介绍了随机种子节点遍历图数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是为可视化Neptune Graph数据库的前端应用程序编写查询。让我们说第一个顶点是项,而第二个顶点用户。用户可以创建一个项目。存在项目与项目之间的关系,以显示从另一个项目派生的项目,例如在从原始媒体剪辑切出的媒体剪辑的情况下。创建的第一组项目应在诸如 SERVER 的顶点中创建,并在用户界面中将其分组。

I am tasked with writing a query for a front-end application that visualizes a Neptune Graph database. Let us say that the first vertex are items while the second vertex user. A user can create an item. There are item to item relationships to show items derived from another item like in the case of media clips cut out of an original media clip. The first set of items created should be created in a vertex such as a SERVER which they are grouped by in the UI.

以下是要求:

    Find (Y) seed nodes that are not connected by any ITEM-ITEM relationships on the graph (relationships via USERs etc... are fine)
    Populate the graph with all relationships from these (Y) seed nodes with no limits on the relationships that are followed (relationships through USERs for example is fine).
    Stop populating the graph once the number of nodes (not records limit) hits the limit specified by (X)


$ b指定的限制,停止填充图形$ b

这里是图形的直观表示。

Here is a visual representation of the graph.

下面是重现此图的示例代码。该图甚至可能更深。这只是一个简单的例子。请看下图:

A sample code to reproduce this graph is below. This graph could even get deeper. This is a just a simple example. Kindly see diagram:

g.addV('SERVER').property(id, 'server1')
g.addV('SERVER').property(id, 'server2')
g.addV('ITEM').property(id, 'item1')
g.addV('ITEM').property(id, 'item2')
g.addV('ITEM').property(id, 'item3')
g.addV('ITEM').property(id, 'item4')
g.addV('ITEM').property(id, 'item5')
g.addV('USER').property(id, 'user1')


g.V('item1').addE('STORED IN').to(g.V('server1'))
g.V('item2').addE('STORED IN').to(g.V('server2'))
g.V('item2').addE('RELATED TO').to(g.V('item1'))
g.V('item3').addE('DERIVED FROM').to(g.V('item2') )
g.V('item3').addE('CREATED BY').to(g.V('user1'))
g.V('user1').addE('CREATED').to(g.V('item4'))
g.V('item4').addE('RELATED TO').to(g.V('item5'))

结果应尽可能采用以下格式:

The result should be in the form below if possible:

[
 [
   {
     "V1": {},
     "E": {},
     "V2": {}
   }
 ]
]

我们有一个API,该API的端点允许开放式gremlin查询。我们在客户端应用程序中将此端点称为获取可视化呈现的数据。我写了一个我认为不正确的查询。此外,我想知道如何过滤经过的节点数并在X个节点处停止。

We have an API with an endpoint that allows for open-ended gremlin queries. We call this endpoint in our client app to fetch the data that is rendered visually. I have written a query that I do not think is quite right. Moreover, I would like to know how to filter the number of nodes traversed and stop at X nodes.

g.V().hasLabel('USER','SERVER').sample(5).aggregate('v1').repeat(__.as('V1').bothE().dedup().as('E').otherV().hasLabel('USER','SERVER').as('V2').aggregate('x').by(select('V1', 'E', 'V2'))).until(out().count().is(0)).as('V1').bothE().dedup().as('E').otherV().hasLabel(without('ITEM')).as('V2').aggregate('x').by(select('V1', 'E', 'V2')).cap('v1','x','v1').coalesce(select('x').unfold(),select('v1').unfold().project('V1'))

如果能得到一个查询将提取此数据集的查询,我将不胜感激。如果结果中的顶点没有连接任何东西,我想检索它们并像在UI上那样渲染它们。

I would appreciate if I can get a single query that will fetch this dataset if it is possible. If vertices in the result are not connected to anything, I would want to retrieve them and render them like that on the UI.

推荐答案

我再次查看了此内容并提出了此查询

I have looked at this again and came up with this query

g.V().hasLabel(without('ITEM')).sample(2).aggregate('v1').
  repeat(__.as('V1').bothE().dedup().as('E').otherV().as('V2').
      aggregate('x').by(select('V1', 'E', 'V2'))).
    until(out().count().is(0)).
  as('V1').bothE().dedup().as('E').otherV().as('V2').
  aggregate('x').
    by(select('V1', 'E', 'V2')).
  cap('v1','x','v1').
  coalesce(select('x').unfold(),select('v1').unfold().project('V1')).limit(5)

要满足节点数而不是记录数(或限制)的标准,我可以将用户传递的数目限制为一半输入节点数,然后从UI上呈现的内容中排除最后一条记录的边E和顶点V2。

To meet the criteria for the node count rather than records count (or limit), I can pass to limit half the number passed in by the user as an input for nodes count and then exclude the edge E and vertice V2 of the last record from what will be rendered on the UI.

方式。

这篇关于随机种子节点遍历图数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:28