![](/img/trans.png)
[英]How to get the combined vertex and edge properties with gremlin and janusgraph
[英]How to get properties of vertex or edge elements in Titan DB version 1.0.0
在舊版本的Titan DB(版本0.5.2)中 , TitanVertex和TitanEdge實現了TitanElement接口,該接口具有我用來檢索元素屬性值的方法getProperties(String key)
。 在新版本的Titan中刪除了此方法(我使用的是1.0.0版)。 我發現valueOrNull(PropertyKey key)
代替這個方法,它執行相同的操作,但接收PropertyKey作為參數而不是String作為鍵名。
僅使用屬性鍵名稱作為String對象檢索屬性值/值的最佳方法是什么?
或者有沒有簡單的方法從屬性鍵名稱獲取PropertyKey對象作為String?
Titan 1.0基於TinkerPop 3.在Titan 1.0中,你會發現你之前在Titan 0.5中調用的一些方法是在TinkerPop接口中定義的,而不是在Titan接口中定義的。
看一下com.thinkaurelius.titan.core.TitanVertex
的Javadoc,你可以看到它擴展了org.apache.tinkerpop.gremlin.structure.Vertex
http://thinkaurelius.github.io/titan/javadoc/1.0.0/ COM / thinkaurelius /鈦/核心/ TitanVertex.html
你可以在org.apache.tinkerpop.gremlin.structure.Vertex
http://tinkerpop.incubator.apache.org/javadocs/3.0.1-incubating/full/org/apache/tinkerpop上找到方法VertexProperty property(String key)
。 /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
您可以在http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#vertex-properties中的TinkerPop3文檔中了解有關頂點屬性的更多信息。
我花了一些時間,找到了一些簡單的問題解決方案(基於Jason Plurad的更新答案)。
查看Javadoc for com.thinkaurelius.titan.core.TitanElement
方法valueOrNull(PropertyKey key)
接收屬性key對象。 獲取此對象的最簡單方法是使用com.thinkaurelius.titan.core.TitanTransaction
getPropertyKey(String keyName)
方法,如果Titan模式中存在屬性鍵,則返回該屬性鍵。 http://thinkaurelius.github.io/titan/javadoc/1.0.0/com/thinkaurelius/titan/core/TitanTransaction.html
Java代碼示例:
TitanTransaction tt = TitanGraph.newTransaction();
PropertyKey userNameKey = tt.getPropertyKey("userName");
TitanVertex v = tt.getVertex(someUserVertexId);
String userName = v.valueOrNull(userNameKey);
你可以這樣做
var = edge.inVertex().property("property").value();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.