[英]Tinkerpop Frames: Query vertices based on interface type
我正在使用Tinkerpop Frames
創建一組頂點和邊緣。 添加新頂點很簡單,但是根據類型來取回頂點似乎有點困難。
假設我有一個班級A
和B
,我想添加一個新班級:
framedGraph.addVertex(null, A.class);
framedGraph.addVertex(null, B.class);
這很簡單。 但是,如果我想檢索所有類型為A
頂點怎么辦?
這樣做失敗,因為它返回了所有頂點( A
和B
)。
framedGraph.query().vertices(A.class);
有任何可能的方法來做到這一點。 我嘗試檢查文檔和測試用例沒有運氣。 如何僅檢索A
型頂點列表
這個問題似乎與- 如何使用Tinkerpop Frames查找特定類的頂點 (今天也問)相同。
據我了解,Tinkerpop框架框架充當頂點周圍的包裝類。 頂點實際上沒有存儲為接口類。 因此,我們需要一種將頂點識別為特定type
。
我的解決方案是,我在Frame類中添加了@TypeField
和@TypeValue
批注。 然后,我使用這些值查詢我的FramedGraph
。
這些注釋的文檔可以在以下位置找到: https : //github.com/tinkerpop/frames/wiki/Typed-Graph
@TypeField("type")
@TypeValue("person")
interface Person extends VertexFrame { /* ... */ }
然后通過添加TypedGraphModuleBuilder
定義FramedGraphFactory
。
static final FramedGraphFactory FACTORY = new FramedGraphFactory(
new TypedGraphModuleBuilder()
.withClass(Person.class)
//add any more classes that use the above annotations.
.build()
);
然后檢索Person
類型的頂點
Iterable<Person> people = framedGraph.getVertices('type', 'person', Person.class);
我不確定這是否是最有效/簡潔的解決方案(我想看看@stephen mallette的建議)。 它目前尚不可用,但是能夠執行以下操作是合乎邏輯的:
// framedGraph.getVertices(Person.class)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.