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

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

问题描述

在查看 Tinkerpop-Blueprints API 时,它很简单使用一种类型的顶点,但如何存储两个?例如.用户及其兴趣?

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?

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

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?

-

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

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.)

嗯,好的.我只是使用组合 id(名称+类型)的顶点和类型的单独索引.更好的解决方案?

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

推荐答案

一般来说最好依赖底层图数据库的自动 ID 系统(例如 Neo4j、InfiniteGraph、OrientDB 等).添加所需信息的方式如下:

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")

简而言之,顶点/边的 ID 是一种检索顶点/边的非域特定方式.通常,最好使用域模型中的属性进行索引.

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天全站免登陆