How to get triple set from the imported ontology?

Hello
I imported owl file into Neo4J successfully, however, I cannot get the triples from the graph.

I want to get the triples as I can execute in SPARQL.

I've already tried that

match (n1)-[r]-(n2) return n1, r, n2

However, this only returns the triples that based on the hierarchy only.

Please let me know how to search or get the triple as a return value

Hi @yujin000731 welcome to the community,
Could you share a bit more detail on what you're trying to do?
You've imported an ontology using which method? Is it n10s.rdf.import or did you use n10s.onto.import? There are differences between the two explained both in the manual and in some other topics in this channel. Have a look as they may help.

Also when you say getting the triples you mean get the output of your query as RDF?

It would be great if you could share the whole script you're using so we could try to reproduce and give you better guidance.

Cheers,

JB.

Thank you for your kind reply.
The below code are that I used for import turtle file.

CALL n10s.graphconfig.init();
CREATE CONSTRAINT n10s_unique_uri ON (r:Resource) ASSERT r.uri IS UNIQUE

CALL n10s.onto.import.fetch("http://localhost:11001/project-23a8e4aa-62a1-4e39-8852-387b71c83156/FruitJuice.ttl","Turtle", {
  classLabel : 'Category',
  objectPropertyLabel: 'Rel',
  dataTypePropertyLabel: 'Prop'
});

After executing these code, I could get the return the table that shows information about terminationStatus, triplesLoaded, triplesParsed, namespaces, extraInfo, callParams.
Among the return values, I want to get the triplesParsed, but I don't know how to get it.

For example, in the ontology there is triple (GrapeJuice - madeOf - Grape).
However, now there are only (Juice - SCO - GrapeJuice) , (Fruit - SCO - Grape).

###  http://www.semanticweb.org/yujin/ontologies/2021/0/untitled-ontology-95#GrapeJuice
:GrapeJuice rdf:type owl:Class ;
            rdfs:subClassOf :Juice ,
                            [ rdf:type owl:Restriction ;
                              owl:onProperty :madeOf ;
                              owl:someValuesFrom :Grape
                            ] .

I need to search the information above.
Please give me your kind guidance.

Thanks,

Hello @yujin000731, did you fix your problem? I have the same one and I don't know how to fix it

Hi @abarkova and @yujin000731 . Sorry for the delayed response.

The n10s.onto.* procedures do not preserve all triples. They import elements from the ontology selectively. If you want to preserve all imported triples you need to use the n10s.rdf.* procedures.

The way to export triples out of neo4j is either using the n10s.export.* procedures or the HTTP endpoint.

May I ask what are you trying to achieve? Maybe with a bit more context I could be of more help.

Regards,

JB.

Hello @jesus_barrasa , thank you very much for your reply!

I would like to import several ontologies into an already existing neo4j database. The context is biology-related in my case. This is why preserving the triples matters, because I want to preserve the hierarchy between items. For example, if I import an ontology about organs and tissues (for example this one), I want to be able to retrieve the relationship 'derives from/develops from' which is lost with n10s.onto.import.fetch. Those relationships are imported as a node called 'Relationship'.

When I do the same with n10s.rdf.import.fetch, I still do not get all the relationships as wanted. Some of them that are interesting to me appear in a node called 'ObjectProperty'.
I am very new to neo4j and ontologies so I am sorry in advance if this question is stupid! :sweat_smile:

Anastasia

Hi @abarkova, I think what you're seeing is the normal behaviour. Let me explain.

Let's assume that you've loaded your ontology using the following script:

//define graph configuration]
call n10s.graphconfig.init({ handleVocabUris: "IGNORE"});

//import ontology
call n10s.onto.import.fetch("https://raw.githubusercontent.com/BRENDA-Enzymes/BTO/master/bto.owl", "RDF/XML");

// producing this as output:
╒═══════════════════╤═══════════════╤═══════════════╤════════════╤═══════════╤════════════╕
│"terminationStatus"│"triplesLoaded"│"triplesParsed"│"namespaces"│"extraInfo"│"callParams"│
╞═══════════════════╪═══════════════╪═══════════════╪════════════╪═══════════╪════════════╡
│"OK"               │27029          │87688          │null        │""         │{}          │
└───────────────────┴───────────────┴───────────────┴────────────┴───────────┴────────────┘

The relationship that you refer to "derives from/develops from" looks like this in your ontology:

You can see the rdfs:label and the URI highlighted in yellow.
This can be looked up in neo4j by label

match (r:Relationship { label : "derives from/develops from"}) 
return r

or also by URI

match (r:Relationship { uri: "http://purl.obolibrary.org/obo/RO_0002202"}) 
return r

both return the same node representing that relationship. Something like this:

In the ontology, you can find other definitions like the one below where in the context of an owl:Restriction, you refer to the "derives from/develops from" relationship by its URI (highlighted).
This Class definition actually states that "intestinal cell line" is a subclass of the things that are connected to instances of http://purl.obolibrary.org/obo/BTO_0000648 through the "derives from/develops from" (http://purl.obolibrary.org/obo/RO_0002202).

You'll find this information if you look up the class "intestinal cell line" by its label or URI (http://purl.obolibrary.org/obo/BTO_0000003) just like we did before with the rel.

match (c1:Class { uri: "http://purl.obolibrary.org/obo/BTO_0000003"})-[r:SCO_RESTRICTION]->(c2) 
return c1, r, c2

This should return the following:

As you can see, the relationship representing the restriction contains the onProperty element.

You can use that if you want to get all the restrictions that refer to the "derives from/develops from" by using its URI (http://purl.obolibrary.org/obo/RO_0002202) as follows (I'm limiting it to the first 100, because there are loads of them) :

MATCH (c1:Class)-[r:SCO_RESTRICTION { onPropertyURI : "http://purl.obolibrary.org/obo/RO_0002202"}]->(c2:Class) 
RETURN c1, r, c2 limit 100

This should return a bunch of classes connected through restrictions that refer to your relationship:

You can also get them all in textual form with this query:

MATCH (c1:Class)-[r:SCO_RESTRICTION { onPropertyURI : "http://purl.obolibrary.org/obo/RO_0002202"}]->(c2:Class) 
return c1.label, c1.uri, r.onPropertyURI, r.restrictionType, c2.label, c2.uri

Which should return the following:

Hope this helps.

JB.

2 Likes

Hello @jesus_barrasa ,
Thank you so so much for this detailed answer!! This is exactly what I was trying to understand.
This helped me a lot!! :grinning:

Have a good day!!

1 Like