在访问图时,单词度degree常用来讨论进入一个顶点的边的数目(入度in degree),从一个顶点出来的边的数目(出度out degree)或者既进入又出来的边数(度degree)在小精灵中计算各种各样的度非常简单,如下面的例子所示:
While working with graphs, the word degree is used when discussing the number of edges coming
into a vertex (in degree), going out from a vertex (out degree) or potentially both coming in and
going out (degree). It’s quite simple with Gremlin to calculate various measures of degree as the
following examples demonstrate.
最简单的计算顶点度的方式就是像下面所示的这样统计边的数目。
The simplest way to calculate vertex degree is simply to count edges as shown below.

如果您想要统计不只一个顶点的度,那么使用group步骤更容易达成这一目标。下面的查询计算了航线图中每个机场顶点的出边的数量。如果您运行这个查询,您将会得到大量的结果数据,因为在图中有3300多个机场。

If you want to calculate the degree values for more than a single vertex, it can be done more easily
using the group step. The query below will calculate the number of outgoing routes for every
airport in the graph. If you run this query you will get quite a lot of result data back as there are
over 3,300 airports in the graph.

 下面的查询语句是基于上面的查询的,但是只选了一部分结果。

The query below builds upon the prior one but just selects a few of the results.

 如果我们运行查询,输出可能看起来像这样。

If we were to run the query the output should look like this. 

 我们可以修改一下查询来计算入度的值,注意可以看到 JFK 的入度比出度小1.

We could change the query a little to calculate the in degree values. Note that we can see that JFK
has one fewer incoming route than it has outgoing.

 下面的查询稍复杂一点,但是它能用于找到出度最大的前10个机场。local步骤的作用范围等内容将在“在集合中使用local”这一节中进行更深入的研究。

The query below is a little more complex but can be used to find the 10 airports with the highest
number of outgoing routes. Some of the concepts used such as local scope are covered in more
detail a bit later on in the "Using local scope with collections" section.

 运行查询的结果在这。如您所见,FRA的出边的数字最大。“有最多路径的机场”这一节中我们会再次仔细地讨论分析路径这一主题。

Here are the results from running the query. As you can see, Frankfurt Airport (FRA) has the
highest number of outgoing routes. The topic of analyzing routes is revisited in detail in the
"Airports with the most routes" section.

 下面的查询计算10个机场的度(入度和出度),这个查询用到了TinkerPop3.2中引入的project步骤。

The next query will calculate the route degree based on all, incoming and outgoing, routes for ten
airports. The query takes advantage of the project step that was introduced in TinkerPop 3.2.

这是运行查询的输出结果。

Here is the output that this query generates.

 我们当然可以用group步骤来重写同样的查询,如下所示。

We could of course also write the same query using a group step as shown below.

 运行查询生成的结果如下。

The results below were generated by running the query.

 

 

 

 

posted on 2022-04-20 18:14  bokeyuannicheng0000  阅读(78)  评论(0)    收藏  举报