English 中文(简体)
Graph-structured databases and Php
原标题:

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.

最佳回答

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.

问题回答

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.

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?

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

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.

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.

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

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.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签