图结构数据库和 Php
我想使用 php 来使用图形数据库。您能指出一些从哪里开始的资源吗?有没有示例代码/教程?或者是否有其他方法可以在完全随机/抽象的情况下存储彼此相关的数据?
-
所需关系的非常抽象的示例:约翰与玛丽相关,两者都与学校相关,约翰高,玛丽矮,约翰有蓝眼睛,玛丽有绿眼睛,我想要的查询是哪些人与“矮个子”相关有绿眼睛去上学' ->回答 John
-
另一个例子:
TrackA -> ArtistA
-> ArtistB
-> AlbumA -----> [ label ]
-> AlbumB -----> [ A ]
-> TrackA:Remix
-> Genre:House
-> [ Album ] -----> [ label ]
TrackB -> [ C ] [ B ]
示例查询:
TrackB 更接近哪种流派?答案:House - 因为它与专辑 C 相关,而专辑 C 与 TrackA 相关且与 Genre:House
相关 获取标签 A 的所有与 Genre:House 相关的专辑:结果:AlbumA、AlbumB - 因为它们都有与 Genre 相关的 TrackA :House
-
这在 MySQL 中是可能的,但它需要每个项目有一组固定的属性/列和一个复杂的非灵活查询,相反,我需要每个属性本身就是一个项目,而不是“属于”某个东西,与某事“相关”。
I want to use a graph database using php. Can you point out some resources on where to get started? Is there any example code / tutorial out there? Or are there any other methods of storing data that relate to each other in totally random/abstract situations?
-
Very abstract example of the relations needed: John relates to Mary, both relate to School, John is Tall, Mary is Short, John has Blue Eyes, Mary has Green Eyes, query I want is which people are related to 'Short people that have Green Eyes and go to School' -> answer John
-
Another example:
TrackA -> ArtistA
-> ArtistB
-> AlbumA -----> [ label ]
-> AlbumB -----> [ A ]
-> TrackA:Remix
-> Genre:House
-> [ Album ] -----> [ label ]
TrackB -> [ C ] [ B ]
Example queries:
Which Genre is TrackB closer to? answer: House - because it's related to Album C, which is related to TrackA and is related to Genre:House
Get all Genre:House related albums of Label A : result: AlbumA, AlbumB - because they both have TrackA which is related to Genre:House
-
It is possible in MySQL but it would require a fixed set of attributes/columns for each item and a complex non-flexible query, instead I need every attribute to be an item by itself and instead of 'belonging' to something, to be 'related' to something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
另请参阅这篇有关在 PHP 中使用 OrientDB 的文章: http://www.odino.org/346/orientdb-the-graph-db-for-the-web
Take also a look to this article about the usage of OrientDB with PHP: http://www.odino.org/346/orientdb-the-graph-db-for-the-web
您还可以找到 php 的 Rexster 客户端:https://github.com/PommeVerte/rexpro-php
作为额外信息。 Rexster 可以从各种其他图形数据库(例如 Neo4j 和 OrientDb 等)加载图形。
You can also find a Rexster client for php : https://github.com/PommeVerte/rexpro-php
As extra information. Rexster can load graphs from various other graph dbs such as Neo4j and OrientDb among others.
目前正在开展一些工作,使 PHP 可以使用 Neo4j 图形数据库,请参阅 此 wiki 页面 了解更多信息!关于如何将域建模为图表,用户邮件列表往往非常棒。
更新:现在有一个简短的入门PHP neo4j REST 客户端的博客文章。
There's some work going on to make the Neo4j graph database available from PHP, see this wiki page for more information! Regarding how to model your domain as a graph, the user mailing list tends to be pretty awesome.
Update: there's now a short getting started blog post for a PHP neo4j REST client.
对我来说听起来有点像一个“典型的”Prolog 问题......这是一个相当与 PHP 不同的编程语言。但也许你可以和 popen 一起工作。
或者定义一个包含列 [ id, predicate,atom1,atom2 ] 的 SQL 表,来存储“Mary has Green Eyes”的真实性:predicate = “has”,atom1 =“Mary”,atom2 =“Green Eyes”。
现在您可以使用您选择的 SQL 连接和过滤谓词和属性。
Sounds to me a little bit like a "typical" Prolog problem... which is a quite different programming language than PHP. But perhaps you could work with popen.
Or you define an SQL table with columns [ id, predicate, atom1, atom2 ], to store the truthness of "Mary has Green Eyes": predicate = "has", atom1 = "Mary", atom2 = "Green Eyes".
Now you could join and filter the predicates and attributes with the SQL of your choice.
它看起来像一个语义网络问题。因此,您必须弄清楚如何将 PHP 和语义网结合使用。也许这个链接 http://bnode.org/blog/2009/05/25/back-from-new-york-semantic-web-for-php-developers-trip 可以帮忙吗?
It looks like a semantic web problem. So you have to figure out how you can use PHP and the semantic web together. Maybe this link http://bnode.org/blog/2009/05/25/back-from-new-york-semantic-web-for-php-developers-trip can help?
听起来您应该这样处理:
1)编写一个图形对象,让您可以按照自己想要的方式查询数据。
2) 为您的对象编写持久层
3) 优化在图形对象中执行查询的调用,以在适当时使用数据库调用(例如,如果您需要节省内存)。
It kind of sounds like you should approach it this way:
1) Code a graph object that will let you query your data the way you want.
2) Write a persistence layer for your object
3) optimize the calls that do your query's in the graph object to use database calls when appropriate (for example, if you need to conserve memory).
我的建议是选择基于 Java 的图形数据库,例如 OrientDB 或 neo4j,然后通过 PHP 使用它/Java 桥。在不久的将来,neo4j(以及在某些时候 OrientDB)应该获得本机 php 支持,并且您可以用本机访问替换桥。
My suggestion is to pick a Java-based graph DB like OrientDB or neo4j and then use it via the PHP/Java bridge. In the near future neo4j (and at some point OrientDB as well) should get native php support and you can replace the bridge with native access.
考虑到这个问题已经存在一年了,注意到您可以对每个支持 sparql 或类似语言的 rdf 数据存储进行这样的查询可能仍然很有趣。
well taking into account this question is one year old, it might still be interesting to note that you can do such a query with every rdf datastore that supports sparql or comparable languages.