如何将图形数据存储在数据库中? [英] How to store graph data in a database?

查看:197
本文介绍了如何将图形数据存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的图形和它非常有趣的。这个问题可能是小白鼠,但请网站一些很好的材料。



我正在尝试制作一个小型社交网络其中每个用户是一个节点,并与他的朋友无方向连接。



它的工作正常,但现在我想将它存储在数据库中。 b

如何存储数据?如何存储节点的所有连接节点(指针)。



删除内存在用户注销并从数据库中读取它时,他登录或应该登录和注销应该不会对节点有任何影响?



我知道它的理论。任何引用都将非常有用。

解决方案

使用实际的图形数据库来存储数据。

http://www.neo4j.org/



然后你可以使用像Gremlin这样的东西来查询/遍历所有的关键字/值对,并且你可以存储连接节点的边。图 - https://github.com/tinkerpop/gremlin 。请参阅他们的文档以下载示例并运行示例查询: https://github.com/tinkerpop/gremlin/wiki/Getting - 开始



一个语法的概念:

 的gremlin> //只让'知道'标签边缘
gremlin> v.out('knows')
==> v [2]
==> v [4]
gremlin> //让我们遍历从'1'marko顶点到它的传出边缘。
gremlin> //在属性图世界中,边是可以遍历的第一类公民。
gremlin> v.outE
==> e [7] [1-knows-> 2]
==> e [9] [1-created-> 3]
= => e [8] [1-know-> 4]


I am new to graphs and its very interesting.This question may be noob one but please site some good materials.

I am trying to make a small social Network where each user is a node and has undirected connection with his friend.

Its working fine but now I want to store it in a database.

How can I store the data?How to store all the connected nodes(pointer) of a node.

Is it better to delete the memory after the user log out and read it from database when he logs in or should logging in and logging out shouldnot have any impact on the node?

I know its theoretical. Any references will be really helpful.

解决方案

Use an actual graph database to store your data.

http://www.neo4j.org/

You can store key/value pairs in a node and you can also store edges that connect nodes.

Then you can use something like Gremlin to query/traverse the graph -https://github.com/tinkerpop/gremlin. See their documentation to download examples and run sample queries: https://github.com/tinkerpop/gremlin/wiki/Getting-Started

An idea of the syntax:

gremlin> // lets only take 'knows' labeled edges
gremlin> v.out('knows')
==>v[2]
==>v[4]
gremlin> // lets do a traversal from the '1' marko vertex to its outgoing edges.
gremlin> // in the property graph world, edges are first class citizens that can be traversed to.
gremlin> v.outE
==>e[7][1-knows->2]
==>e[9][1-created->3]
==>e[8][1-knows->4]

这篇关于如何将图形数据存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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