如何使用Tinkerpop / Blueprints图API存储和检索不同类型的顶点? [英] How to store and retrieve different types of Vertices with the Tinkerpop/Blueprints graph API?

查看:86
本文介绍了如何使用Tinkerpop / Blueprints图API存储和检索不同类型的顶点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当查看 Tinkerpop-Blueprints API 时,它非常直接使用一种类型的顶点,但我怎么能存储两个?例如。用户和他们的兴趣?

以及如何通过id获得Vertex?我的意思是,可能有用户名为'timetabling'以及兴趣'时间表' - 如何处理该ID冲突?



-



我知道第一个问题可以通过引入一个类型属性的索引来解决,对于第二个问题,我可以自动生成id并为name属性创建另一个索引。 但是为什么我需要顶点ID呢?例如。对于内存中有一个HashMap的所有顶点,这是没有用的,浪费内存! (我可以通过组合类型和名称作为id来区别解决问题,但如果我列出所有用户,则效率会很低。)



$ hr
$ b $嗯,好的。我只是使用组合ID(名称+类型)的顶点和一个单独的类型索引。更好的解决方案是什么?

解决方案

通常最好依靠底层图形数据库的自动ID系统(例如Neo4j,InfiniteGraph ,OrientDB等)。您可以添加所需信息的方式如下:

 顶点v = graph.addVertex(null)
v.setProperty(name,timetabling)

顶点marko = graph.addVertex(null)
graph.addEdge(null,marko,v,hasInterest)
Verte aType = graph.addVertex(null)
graph.addEdge(null,aType,v,hasType)

简而言之,顶点/边的ID是检索顶点/边的非特定领域的方式。一般来说,最好在您的域模型中使用属性进行索引。



希望您的问题能够解释,
Marko。



http://markorodriguez.com


When looking at the Tinkerpop-Blueprints API it is quite straight forward to use one type of vertices but how can I store two? E.g. Users and their interests?

And how can I get a Vertex by id? I mean, there could be a user named 'timetabling' as well as the interests 'timetabling' - how to handle that id conflict?

-

I know that the first problem could be solved via introducing an index for a type-property and for the second problem I could auto generate the id and create another index for the name-property. BUT why would I then need the vertex id at all? E.g. for the in-memory there is a HashMap for all vertices which would be of no use and wasting memory! (I could solve the problem differently via combining type and name as the id but then it would inefficient if I e.g. list all users.)


Hmmh, ok. I'm just using the vertices for the combined id (name+type) and a separate index for type. Better solutions?

解决方案

In general it is best to rely on the automatic ID system of the underlying graph database (e.g. Neo4j, InfiniteGraph, OrientDB, etc.). The way in which you would add the information you want is as follows:

Vertex v = graph.addVertex(null)
v.setProperty("name","timetabling")

Vertex marko = graph.addVertex(null)
graph.addEdge(null, marko, v, "hasInterest")
Verte aType = graph.addVertex(null)
graph.addEdge(null, aType, v, "hasType")

In short, the ID of a vertex/edge is a non-domain-specific way of retrieving vertices/edges. Generally, it is best to use properties in your domain model for indexing.

Hope that speaks to your question, Marko.

http://markorodriguez.com

这篇关于如何使用Tinkerpop / Blueprints图API存储和检索不同类型的顶点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆