-2

I have a dump of N-Triples which I want to convert to Cypher Text, So that it can be loaded into Neo4j Database directly. For simple ontologies like rdf-syntax-ns#type I can convert easily using a script i.e

<http://www.foo.org/triple1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.foo.org/Human>

Can be easily converted as

CREATE (t1:Human { type : "triple1" })

and it is accurate and as I want it to be. But for complicated stuff like <http://www.w3.org/2002/07/owl#equivalentProperty> it gets damn crapped.

Thus my question is How to convert any triple using <http://www.w3.org/2002/07/owl#equivalentProperty> as the predicate to Cypher text?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

3

See this related question for general issues of how to get RDF into Neo4J.

For specifically the equivalentProperty stuff, the reason you're getting messed up here is that equivalentProperty is a "meta" statement that references the model itself; namely in this case, it's making a statement about properties rather than about data. In Neo4J, you don't have an explicit model in the database (we're hoping this may change over time, but for now that's how it is). So you can't talk about a property in general as such. Probably your best bet is to create a new kind of node that stands in for that property metadata.

E.g. if you had RDF:

<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#equivalentProperty> <http://my-ns.org/vocab#foobar>

Then you might turn that into:

MERGE (p1:Property { ns: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", name:"type" },
      (p2:Property { ns: "http://my-ns.org/vocab#", name: "foobar" }),
      (p1)-[:equivalentProperty]->(p2);

The reason this works is because we're creating :Property nodes that make property metadata real. You don't get that by default with neo4j, whereas in RDF, by nature of the fact that those properties have their own URIs, they are "nodes" in RDF.

Community
  • 1
  • 1
FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • Thanks buddy for the answer, even few things like `sameAs` and `hasType` get crappy with Neo4j. The sad part is that this stuff will go into an ACM paper submission, in which they go into all sorts of detail. I have incorporated what you have suggested and am running the script . I will mark the answer as accurate once it is fine. Thanks again. – Bhargav Rao Dec 23 '14 at 20:58
  • Things like `sameAs` will have the same problem for the same reason. SameAs marks one model item the same as another. You have to "model the model", so to speak. – FrobberOfBits Dec 23 '14 at 21:07
  • Yeah, Hope the Neo4j team comes up with something more to handle such stuff. – Bhargav Rao Dec 23 '14 at 21:08
  • 1
    See also my answer on another related question: http://stackoverflow.com/questions/24931059/metadata-in-neo4j-graph-database – FrobberOfBits Dec 23 '14 at 21:10
  • I have a doubt linked to this question. Now that Neo4j doesn't maintain the predicate structure of nTriples, we can as-well merge both sides of `equivalentProperty` as one instead of having different attributes. Is it wrong to do so? – Bhargav Rao Dec 24 '14 at 16:46
  • 1
    Maybe. The premise behind `equivalentProperty` is that you have 2 different props from different namespaces. In general, I think it's a bad idea to merge them, because you destroy the distinction between the two vocabs. That **might** be OK depending on your use case, but RDF keeps those separated for good reasons. Note that in the properties I suggested, I added an `ns` attribute so you could tell the difference between two properties even if they had the same name. Merging will destroy that difference. So ultimately it depends on if you need to differentiate by namespace. – FrobberOfBits Dec 24 '14 at 18:08