Thanks everyone. This gives me the insight I needed to choose a course of action. For now I’m going to look for other areas where a custom rule could be applied.
Thanks, Chris > On Dec 23, 2015, at 10:07 AM, Andy Seaborne <[email protected]> wrote: > > It is possible to have both the ontology/inference graph and the base data > available in the same query when using the general purpose dataset > implementation. > > Then, parts of the query can go to the inference graph and parts to the base > data. > > Andy > > On 23/12/15 12:40, Dave Reynolds wrote: >> Hi Chris, >> >> As Andy mentioned there is some magic support for direct relationships >> in the reasoner, but also in the Ontology API. >> >> The RDFS and various OWL reasoners (especially OWLMicro) all include the >> TransitiveReasoner underneath. The TransitiveReasoner is custom code >> (outside of the rule engine) to compute both the >> subClassOf/subPropertyOf closures and their "transitive reductions" >> (i.e. to recover the direct relationships). >> >> Note that the direct relationships might not be the same as what was >> asserted in the base model. See the diagrams (a few screens down): >> https://jena.apache.org/documentation/ontology/#the-generic-ontology-type-ontresource >> >> >> So if you have a Model with one of those reasoners then a normal query >> will see the transitive closure of rdfs:subClassOf but there is a magic >> alternative predicate which allows you to see the direct version. >> TransitiveReasoner.directSubClassOf is the Node for that magic property >> which you can then turn into a Resource if you need to or use it's URI >> in a SPARQL query: >> >> urn:x-hp-direct-predicate:http_//www.w3.org/2000/01/rdf-schema#subClassOf >> >> However, in your case you want the direct type relationship not the >> direct subclass relationship. The reasoners don't directly create that >> for you. The Ontology API offers this through: >> listRDFTypes( boolean direct ) >> The Ontology API implementation will use magic properties from the >> reasoner if available. Though the Ontology API doesn't help if you need >> to access via SPARQL. >> >> Dave >> >> On 22/12/15 21:32, Chris Snyder wrote: >>> Hi Andy, >>> >>> direct-relations.png >>> >>> I have something more like a structure of classes (iii) in the base >>> model with a named instance, let’s call it i1 that implements A. I want >>> to get back [i1, A] from a SPARQL query that looks for a instance >>> inherited from C. I can get the result I want with no reasoner enabled. >>> When I turn on the OWL reasoner the inferred relations that are >>> created as in (ii) are giving me back [i1, A], [i1, B], and [i1, C] >>> from my query. >>> >>> I’m trying to force the use of a reasoner into some aspect of my sample >>> application and I believe what this is uncovering is that my OO modeling >>> of the ontology does not require the OWL reasoning in this case. I might >>> be better off not worrying about inferring relationships within the >>> ontology. Instead I might need to use a generic reasoner and look for >>> rules that can be applied to infer some knowledge that what normally >>> need to be generated from the SPARQL results in code. >>> >>> Thanks, >>> Chris >>> >>> >>> >>>> On Dec 22, 2015, at 3:29 PM, Andy Seaborne <[email protected] >>>> <mailto:[email protected]>> wrote: >>>> >>>> On 22/12/15 19:09, A. Soroka wrote: >>>>> Were you using that with an inferring model? Because then you are >>>>> going to materialize a bunch of fresh rdf:type triples, which are >>>>> going to turn up as the other (super) classes. >>>> >>>> >>>> Chris : "directly implemented" -- do you mean direct subclasses? >>>> >>>> http://jena.apache.org/documentation/inference/index.html#directRelations >>>> >>>> >>>> C is not a direct subclass of A. >>>> >>>> There is some secret predicate when querying an inference model (not >>>> sure what it is. Dave?) that will trigger direct subclass calculation. >>>> If you want SPARQL and use the right predicate it should work. >>>> >>>> Otherwise on the base data, not the inference model: >>>> >>>> A quick hack in SPARQL for a non-inference model for direct subClassOf: >>>> >>>> # ?x is a direct subclass of ?C if >>>> # there is not a another, longer route to it. >>>> PREFIX : <http://example/> >>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> >>>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> >>>> >>>> SELECT * { >>>> ?x rdfs:subClassOf ?C . >>>> FILTER NOT EXISTS { ?x rdfs:subClassOf/rdfs:subClassOf+ ?C } >>>> } >>>> >>>> -------------------------------------- >>>> >>>> @prefix : <http://example/> . >>>> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . >>>> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . >>>> >>>> :B rdfs:subClassOf :A . >>>> :C rdfs:subClassOf :A . >>>> :C rdfs:subClassOf :B . >>>> :D rdfs:subClassOf :B . >>>> >>>> ----------- >>>> | x | C | >>>> =========== >>>> | :C | :B | >>>> | :D | :B | >>>> | :B | :A | >>>> ----------- >>>> >>>>> >>>>> --- >>>>> A. Soroka >>>>> The University of Virginia Library >>>>> >>>>>> On Dec 22, 2015, at 1:58 PM, Chris Snyder <[email protected]> >>>>>> wrote: >>>>>> >>>>>> Yeah, I tried that route but it still returns all the class in the >>>>>> inheritance structure. >>>>>> >>>>>> Thanks, >>>>>> Chris >>>>>> >>>>>> >>>>>>> On Dec 22, 2015, at 11:52 AM, A. Soroka <[email protected]> wrote: >>>>>>> >>>>>>> I am _no_ SPARQL guru, but I think you might be able to do this >>>>>>> without inference, with property paths: >>>>>>> >>>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> >>>>>>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> >>>>>>> PREFIX owl: <http://www.w3.org/2002/07/owl#> >>>>>>> PREFIX modelica: <http://mind-tap.net/kbswt/modelica#> >>>>>>> >>>>>>> SELECT ?instance ?label >>>>>>> WHERE { >>>>>>> ?instance rdf:type ?type. >>>>>>> ?type rdfs:subClassOf+ modelica:BinaryExpression . >>>>>>> ?type rdfs:label ?label. >>>>>>> } >>>>>>> >>>>>>> --- >>>>>>> A. Soroka >>>>>>> The University of Virginia Library >>>>>>> >>>>>>>> On Dec 22, 2015, at 11:41 AM, Chris Snyder <[email protected]> >>>>>>>> wrote: >>>>>>>> >>>>>>>> I’m using the Jena OWL reasoner with this ontology: >>>>>>>> http://www.mind-tap.net/kbswt/simple_no_inheritance.ttl >>>>>>>> >>>>>>>> I want to get the named individuals that are instances of a >>>>>>>> modelica:BinaryExpression along with the rdfs:label of the class >>>>>>>> directly implemented by the named individual. >>>>>>>> >>>>>>>> I hope there is a SPARQL guru who can help identify what I need to >>>>>>>> do. If adding a Jena rule to the reasoner would help I have no >>>>>>>> problem going that route either. >>>>>>>> >>>>>>>> In essence: >>>>>>>> c subClassOf b >>>>>>>> b subClassOf a >>>>>>>> >>>>>>>> c rdfs:label “class c” >>>>>>>> b rdfs:label “class b” >>>>>>>> a rdfs:label “class a” >>>>>>>> >>>>>>>> x typeOf c >>>>>>>> x rdfs:label “instance x” >>>>>>>> >>>>>>>> I need to run a query to get: >>>>>>>> “instance x”, “class c” >>>>>>>> >>>>>>>> but my SPARQL gives me: >>>>>>>> “instance x”, “class c” >>>>>>>> “instance x”, “class b” >>>>>>>> “instance x”, “class a” >>>>>>>> >>>>>>>> I’ve tried some filter expressions but they wind up filtering out >>>>>>>> all the results. I was thinking there is some path modifier that >>>>>>>> might work but haven’t been successful going down that route either. >>>>>>>> >>>>>>>> My starter SPARQL: >>>>>>>> >>>>>>>> PREFIX modelica: <http://mind-tap.net/kbswt/modelica#> >>>>>>>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> >>>>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> >>>>>>>> PREFIX : <http://mind-tap.net/kbswt/simple_no_inheritance#> >>>>>>>> >>>>>>>> select distinct * { ?s rdfs:subClassOf modelica:BinaryExpression ; >>>>>>>> rdfs:label ?equationName . >>>>>>>> ?i a ?s. >>>>>>>> } >>>>>>>> ORDER BY ?i >>>>>>>> >>>>>>>> Thanks in advance, >>>>>>>> Chris >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> >
