在旧版本的 Titan DB(版本 0.5.2) 中,TitanVertex 和 TitanEdge 实现了 TitanElement 接口(interface)它具有我用来检索元素属性值的方法 getProperties(String key)
。此方法在新版本的 Titan 中被删除(我使用的是 1.0.0 版本)。我发现 valueOrNull(PropertyKey key)
不是这种方法,它做同样的事情,但接收 PropertyKey 作为参数而不是 String 作为键名。
仅使用属性键名称作为字符串对象来检索属性值的最佳方法是什么?
或者是否有简单的方法从属性键名称中获取 PropertyKey 对象作为字符串?
最佳答案
Titan 1.0 基于TinkerPop 3。在Titan 1.0 中,您会发现您之前在Titan 0.5 中调用的一些方法是在TinkerPop 接口(interface)中定义的,而不是在Titan 接口(interface)中定义的。
查看 com.thinkaurelius.titan.core.TitanVertex
的 Javadoc,您可以看到它扩展了 org.apache.tinkerpop.gremlin.structure.Vertex
http://thinkaurelius.github.io/titan/javadoc/1.0.0/com/thinkaurelius/titan/core/TitanVertex.html
您可以在 org.apache.tinkerpop.gremlin.structure.Vertex
上找到方法 VertexProperty property(String key)
http://tinkerpop.incubator.apache.org/javadocs/3.0.1-incubating/full/org/apache/tinkerpop/gremlin/structure/Vertex.html#property-java.lang.String-
使用属性键检索顶点属性值的最佳方式如下:
gremlin> graph = TitanFactory.build().set('storage.backend','inmemory').open()
==>standardtitangraph[inmemory:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardtitangraph[inmemory:[127.0.0.1]], standard]
gremlin> v = graph.addVertex('name', 'octopus')
==>v[4296]
gremlin> v.values('name')
==>octopus
您可以在此处的 TinkerPop3 文档中了解有关顶点属性的更多信息 http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#vertex-properties
关于java - 如何在 Titan DB 1.0.0 版中获取顶点或边元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33065724/