在支持TinkerPop3的图中,所有的属性都是Property接口的实现。顶点的属性是VertexPropery接口的实现,它本身又是Property的扩展。这些接口中作为阿帕奇TinkerPop3 JavaDoc的一部分记录在文档中。这些接口定义了一些方法,您可以在您的代码中使用这些方法来做与顶点属性对象相关的工作。有一件重要的事要注意:顶点的属性它们是不可改变的。您可以创建它们,但是一旦创建了,它们就不可以更新了。
In a TinkerPop 3 enabled graph, all properties are implementations of the Property interface.
Vertex properties implement the VertexProperty interface which itself extends the Property
interface. These interfaces are documented as part of the Apache TinkerPop 3 JavaDoc. The
interface defines the methods that you can use when working with a vertex property object in your
code. One important thing to note about vertex properties is that they are immutable. You can
create them but once created they cannot be updated.
 在本书后边的“从Java应用程序来操作廷克图”这一节中,我们会更进一步的看到TinkerPop3中定义的Java接口。
We will look more closely at the Java interfaces that TinkerPop 3 defines in the "Working with
TinkerGraph from a Java Application" section a bit later in this book.
顶点属性VertexProperty接口没有定义任何超过了它的基本的构造方法的“setter”方法。对此您的即刻的反应可能会是这样“但是我知道您可以使用property步骤来改变属性的值”。确实是,我们已经在本书讨论过程中这么做了。然而,在这个场景后面,当您修改一个属性时,真正发生的是什么?创建了一个新的属性对象,它替代了原先的属性对象。我们稍后来解释这个,但这之前我们先一起回础几个属性的基本的概念。
The VertexProperty interface does not define any "setter" methods beyond the basic constructor
itself. Your immediate reaction to this is likely to be "but I know you can change a property’s value
using the property step". Indeed we have already discussed doing just that in this book. However,
behind the scenes, what actually happens when you change a property, is that a new property
object is created and used to replace the prior one. We will examine this more in a minute but first
let’s revisit a few of the basic concepts of properties.
在一个属性图中顶点和边都可以包含一个或多个属性。我们已在前边看过像下面这样的查询,从DFW机场顶点的相关属性中从每个属性的键中获取对应的值。
In a property graph both vertices and edges can contain one or more properties. We have already
seen a query like the one below that retrieves the values from each of the property keys associated
with the DFW airport vertex.

到止前为目我们没有提到的是,然而前边的查询是这个查询的一个简写的形式。

What we have not mentioned so far, however, is that the previous query is a shortened form of this
one.

 

如果我们想要获取与DFW顶点相关的每个属性的VertexProperty对象,我们也可以这么做。在很多情况下,只使用values或者valueMap方法来访问一个或多个属性就已经足够了。但是有一些情况,就像我们可以看见的:当我们查看属性ID的时候,可以访问顶点属性对象这是相当有用的。

If we wanted to retrieve the VertexProperty (vp) objects for each of the properties associated with
the DFW vertex we could do that too. In a lot of cases it will be sufficient just to use values or
valueMap to access the values of one or more properties but there are some cases, as we shall see
when we look at property IDs, where having access to the vertex property object itself is useful.
 

 

我们已经看到了顶点或者边的每个属性是如何以键和值呈现的。如果我们想要获取指定顶点相关的所有属性键的列表,我们可以写像下面这样一条查询语句:在航线图中找到与DFW顶点相关的所有属性键。

We have already seen how each property on a vertex or edge is represented as a key and value
pair. If we wanted to retrieve a list of all of the property keys associated with a given vertex we
could write a query like the one below that finds all of the property keys associated with the DFW
vertex in the air-routes graph.
 

 

就像找名称一样,移除冗余的,用这个查询找到从DFW顶点出发的所有出边的属性键。注意边属性是Property的实现而不是VertexProperty的实现。

We could likewise find the names, with duplicates removed, of any property keys associated with
any outgoing edges from the DFW vertex using this query. Note that edge properties are
implementations of Property and not VertexProperty.

 

基于这样的事实:我们现在知道了怎么去指任一属性的定键值对,这样去构建一个查询,像下面:在图中增加所有最长的跑道的总长度和跑道数,先把它们按属性键分组,再计算值的总和。

We can use the fact that we now know how to specifically reference both the key and value parts of
any property to construct a query like the one below that adds up the total length of all the longest
runway values and number of runways in the graph and groups them by property key first and
sum of the values second.

 

 

 

posted on 2022-04-22 15:39  bokeyuannicheng0000  阅读(96)  评论(0)    收藏  举报