TinkerPop3引入了图变量的概念。图变量是一个键值对,它与图自身相关联。图变量不能被认为是您将让小精灵遍历处理的图的一部分,但是它是一种向图关联元数据的方法。我们可以使用图对象的多种方法来设置和获取图变量。现在假设我们想要加一些元数据,这些元数据将提示我记录航线图是谁维护的。它上次更新是什么时候。我们可以像下面这么做。
TinkerPop 3 introduced the concept of graph variables. A graph variable is a key/value pair that can
be associated with the graph itself. Graph variables are not considered part of the graph that you
would process with Gremlin traversals but are in essence a way to associate metadata with a graph.
You can set and retrieve graph variables using the variables method of the graph object. Let’s
assume I wanted to add some metadata that allowed me to record who the maintainer of the air
routes graph is and when it was last updated. We could do that as follows.
您可使用任何对您来说有意义的字符串,当您给您的图变量关键字命名的时候。我们可以用到keys方法来获取当前图中的任何键的名称(即图变量),
You can use any string that makes sense to you when naming your graph variable keys. We can use
the keys method to retrieve the names of any keys currently in place as graph variables.
asMap方法将返回现在设置成键值对表形式的图变量
The asMap method will return any graph variables that are currently set as a map of key/value
pairs.
我们可以用get方法来取得指定键的值。注意返回的值是java.util.Optional类的一个实例。
We can use the get method to retrieve the value of a particular key. Note that the value returned is
an instance of the java.util.Optional class.
如果您想要删除图变量,您可以用到remove方法。在下面这个例子中,我们将删除图的maintainer图变量,再次查询变量map,证明它已经被删掉了。
If you want to delete a graph variable you can use the remove method. In this next example we will
delete the maintainer graph variable and re-query the variable map to prove it has been deleted.
浙公网安备 33010602011771号