java - 如何在 Titan DB 1.0.0 版中获取顶点或边元素的属性

标签 java titan

在旧版本的 Titan DB(版本 0.5.2) 中,TitanVertexTitanEdge 实现了 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/

相关文章:

java - 即使添加 Maven 依赖项后,NoClassDefFound 也会出现错误

cluster-computing - Titan(不是后端存储)集群是如何工作的?

java - gremlin 中的边缘时间戳

java - 在 Hibernate Criteria 中访问复合键

java - 绑定(bind)数据触发更改后 Swing/JTable 不更新

java - Java中的闹钟

java - Titan 接收连接两组任意节点的边

java - Jar 找不到 .fxml 文件的路径

java - 为什么 Titan 会创建配置唯一的重复顶点键?

java - 通过 Gremlin 连接到 DynamoDB Local