How to use inference with an imported ontology and rdf data

Using the example of Importing RFD Data (with minionto and miniinstances), I want to query all nodes that are a (direct or indirect) sublass of Person which should result in the MarinaHyde node.

I tried to use the following nodesLabelled procedure (based on Inferencing/Reasoning) but it didn't give me any results.

CALL n10s.inference.nodesLabelled('Person',  {
  catNameProp: "rdfs__label",
  catLabel: "rdfs__Class",
  subCatRel: "rdfs__subClassOf"
})
YIELD node
RETURN node.uri as uri, labels(node) as categories;

Any help on how to make this work would be appreciated.

Hi @boceckts,
I think the example in the docs needs reviewing. Thanks for bringing it to my attention.

If you're fine with the IGNORE option for the handleVocabUris config param, then the easiest way to do it would be as follows:

call n10s.graphconfig.init({handleVocabUris:"IGNORE"});

call n10s.onto.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");

call n10s.inference.nodesLabelled('Person', {
  catNameProp: "name",
  catLabel: "Class",
  subCatRel: "SCO"
})
YIELD node
RETURN node.uri as uri, labels(node) as categories

Which returns:

╒═════════════════════════════════╤════════════════════════╕
│"uri"                            │"categories"            │
╞═════════════════════════════════╪════════════════════════╡
│"http://neo4j.org/ind#MarinaHyde"│["Resource","Columnist"]│
└─────────────────────────────────┴────────────────────────┘

Notice the n10s.onto.import.* instead of n10s.rdf.import.* for importing the ontology.

That said, let me think how to make it work for the case where you want to load the onto using n10s.rdf.import.*. It may need a bit of re-thinking... :thinking: ...watch this space.

Hope this helps anyway.

JB.

Hi @jesus_barrasa ,

thank you for your quick answer.

I already tried to play around with the graph config parameters by passing them to the import commands like this call n10s.rdf.import.fetch("...", "Turtle", {handleVocabUris: "IGNORE"}). Unfortunately, it didn't work that way whereas your solutions works perfectly.
I'm also not sure about what's the difference between n10s.onto.import.* vs n10s.rdf.import.* but the way you described it works for me.

In the end, this is exactly the answer I was looking for!

Thanks again!

Great to hear.

Yeah, the handleVocabIUris is no longer passed as a param of an individual import procedure but set as part of the Graph Configuration as you can see in the example I provided. This is one of the major changes in 4.0. I'd suggest you take a look at the migration guide in the manual if you're a 3.5 user or you are trying to reproduce examples from previous versions.

Also, to answer your question on the difference between rdf and onto variants of the import, I'd say that the n10s.onto.import.* procedure imports only the following from the ontology (see manual for details):

  1. Named class (category) declarations with both rdfs:Class and owl:Class .
  2. Explicit class hierarchies defined with rdf:subClassOf statements.
  3. Property definitions with owl:ObjectProperty , owl:DatatypeProperty and rdfs:Property
  4. Explicit property hierarchies defined with rdfs:subPropertyOf statements.
  5. Domain and range information for properties described as rdfs:domain and rdfs:range statements.

whereas the n10s.rdf.import.* import includes every single triple. You will use one or the other depending on your needs but for integration with the inferencing capabilities in n10s, the n10s.onto.impoort.* import makes things a lot easier.

Cheers,

JB.