neo4j-labs/neosemantics

Ontology schema and instance data are not linked

CarMoreno opened this issue · 3 comments

Hi all,
First of all, thank you for this amazing tool. I am checking some examples on the online documentation, and I came across this example: https://neo4j.com/labs/neosemantics/4.0/import/#classes-as-nodes. Basically, using that approach we can import an ontology and then, the instance data. Information will be linked with the ontology through rdf__type. I am doing the steps proposed in that section of the documentation, but the results are not the same. I am getting both, the ontology graph and the data instance graph unlinked.

image

I have tried different Neo4j/Neosemantics versions. Currently, I am using Neo4j v4.4.12 and n10s v4.4.0.3. However, I have used Neo4j v5.7 and n10s v5.7 with the same result.

I do not know if I am doing something wrong, I am a Neo4j beginner. To summarise, the steps I am doing are:

  1. CALL n10s.graphconfig.init();
  2. CREATE CONSTRAINT n10s_unique_uri ON (r:Resource) ASSERT r.uri IS UNIQUE;
  3. CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/minionto.ttl","Turtle");
  4. CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/miniinstances.ttl","Turtle", { typesToLabels: false });

I would really appreciate whatever help here.

Hi @CarMoreno , apologies for the late response!
Thanks for bringing this to our attention; the example needs updating 😱
The way rdf:type statemens are loaded now is controlled in the config with the parameter handleRDFTypes (see reference).

You have two options.
(note that in both cases you have to create the constraint, so I'll exclude the CREATE CONSTRAINT n10s_unique_uri... part)

Option 1: persist all rdf:type statements as both neo4j labels and "type" relationships.

CALL n10s.graphconfig.init({handleRDFTypes: "LABELS_AND_NODES"});
CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/minionto.ttl","Turtle");
CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/miniinstances.ttl","Turtle");

You get the expected result but you would get some additional elements, namely a new node representing the rdfs:Class type (the green node in the image below) and a relationship connecting every class in the ontology to it.

image

Usually, the objective of storing in the graph the rdf:type statements is to connect instances to classes. That's why the additional node and links described, while correct, may not be desired. How do we avoid this?

Option 2: For loading the ontology, we set the handleRDFTypes param to labels only, and before we start loading the instance data we change it to persist all rdf:type statements as both neo4j labels and "type" relationships. The config cannot be changed once the graph has been populated to avoid inconsistencies, but you can overrule that behavior using the force: true parameter (this will give you superpowers but it assumes you know what you're doing 😉) .

CALL n10s.graphconfig.init({handleRDFTypes: "LABELS"}); //this is the default option anyway
CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/minionto.ttl","Turtle");
CALL n10s.graphconfig.set({ handleRDFTypes: "LABELS_AND_NODES", force: true});
CALL n10s.rdf.import.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/miniinstances.ttl","Turtle");

Which produces exactly the expected graph:
image

I hope this helps.

JB

Hi @jbarrasa !,
Thank you for the clarifications, I will try again this week :D and I will let you know asap.

It works, thank you!