query suggestion

1 view
Skip to first unread message

Tze-John Tang

unread,
Nov 10, 2015, 10:36:28 AM11/10/15
to Stardog
I was wondering if anyone had suggestions to execute a better query. I was trying to do it in a single query, but maybe it makes sense to split it up.
I have some owl classes defined. In some other graphs I have predicates associated with some of those classes.  If certain predicates exist, then via reasoning the class is a MasterEntity.

    <owl:Class rdf:about="urn:x-abbvie:rdf-service#MasterEntity">
       
<rdfs:subClassOf>
           
<owl:Restriction>
               
<owl:onProperty rdf:resource="urn:x-abbvie:rdf-service#viewConfiguration"/>
               
<owl:onClass rdf:resource="urn:x-abbvie:rdf-service#ViewConfiguration"/>
               
<owl:minQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minQualifiedCardinality>
           
</owl:Restriction>
       
</rdfs:subClassOf>
       
<rdfs:subClassOf>
           
<owl:Restriction>
               
<owl:onProperty rdf:resource="urn:x-abbvie:rdf-service#deleteConfiguration"/>
               
<owl:onClass rdf:resource="urn:x-abbvie:rdf-service#DeleteConfiguration"/>
               
<owl:minQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minQualifiedCardinality>
           
</owl:Restriction>
       
</rdfs:subClassOf>
   
</owl:Class>

I have certain named graphs where I declare instances of the classes, i.e. <xxxx> a <class>, and I also have other named graphs where I associate more triples with <xxxx>.

What I am trying to do is to query a specific named graph for where the subjects are instances of a class that are a MasterEntity, which might require checking in three separate graphs.  Here is the naive query, which is executed with reasoning enabled.  

select distinct ?s
where {
graph ?g {
?t a <urn:x-abbvie:rdf-service#MasterEntity> .
}
graph ?ig {
?s a ?t .
}
graph ?sg {
?s ?p ?o .
}
}


Any recommendations?

Thanks,

-tj

Michael Grove

unread,
Nov 10, 2015, 11:20:36 AM11/10/15
to stardog
TJ,

I'm not entirely sure what recommendation you're looking for.  Are you looking to improve the performance of the query?  Readability?  Something else?

Also, I noticed that you're looking for `?t` which are instances of `MasterEntity`, and then turning around and getting the things which are of type `?t`; so you're using `?t` as both a class and an individual.  Not sure if you intended punning there.

Cheers,

Mike
 

Thanks,

-tj

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Tze-John Tang

unread,
Nov 10, 2015, 12:04:29 PM11/10/15
to Stardog
Hi Mike,

Performance really.  The query does not return in the console.

You are right, I am intending to query the first part as an instance and then in the second part as a class.  And maybe there is a better why I could have structured that out.  I have a lot of classes. Only some of those classes are considered "Master" classes.  These are identified if they have some kind of associated configuration predicates with them.  This is why I am treating it as an instance int the first part of the query.

I am really trying to query for are all of the subjects in a specific named graph where the class of those subjects are "Master".

What I am looking for is a recommendation on maybe a better way to define the reasoning rules or a better way to query given the rule I already defined.  Ultimately, I want to be able to query separately for  classes that are master, and instances of classes that are master.

-tj

Evren Sirin

unread,
Nov 10, 2015, 12:22:21 PM11/10/15
to Stardog
Hi TJ,

Punning and unbound properties are both hard to optimize with
reasoning so their combination is even worse. Can you send us the
output of `query explain -r` for this query so we can double check the
query plan?

Splitting the query as you suggest can help the situation. You can
separate the `?s ?p ?o` part into a different query and execute it for
every result you get for the first part.

It might be possible to change the modeling such that instead of `CLS
a MasterEntity` you'd infer `CLS rdfs:subClassOf MasterEntity`. That
is probably not a trivial modeling change and it is not clear how much
it would help with the performance.

Best,
Evren

Tze-John Tang

unread,
Nov 10, 2015, 4:29:55 PM11/10/15
to Stardog
Thanks Evren.  What you state in the last paragraph might be something to try.  I did try to change the model, but I am trying to find some reference online as to how I might be able to specify the inference rule.  I want to infer that something is a MasterEntity if its class is a MasterEntityType.

The explain plan is below:

Explaining Query:

select distinct ?s
where {
graph ?g {
?t a <urn:x-abbvie:rdf-service#MasterEntity> .
}
graph ?ig {
?s a ?t .
}
graph ?sg {
?s ?p ?o .
}
}

The Query Plan:

Distinct [cardinality=41]
  Projection(?s) [cardinality=41]
    LoopJoin[_] [cardinality=41]
      MergeJoin[?t] [cardinality=41]
        Sort(?t) [cardinality=1]
          TypeOf(?s, ?t)
        Union [cardinality=25]
          Scan[PSC](?t, <urn:x-abbvie:rdf-service#deleteConfiguration>, _){?g, named} [cardinality=5]
          Scan[PSC](?t, <urn:x-abbvie:rdf-service#viewConfiguration>, _){?g, named} [cardinality=20]
      Hybrid_Property(FACT(x0, x1, x2)(Var(name=2), Var(name=5) -> Var(name=4))) [cardinality=1]


-tj

Michael Grove

unread,
Nov 11, 2015, 9:12:50 AM11/11/15
to stardog
TJ,

On Tue, Nov 10, 2015 at 4:29 PM, Tze-John Tang <tzejoh...@gmail.com> wrote:
Thanks Evren.  What you state in the last paragraph might be something to try.  I did try to change the model, but I am trying to find some reference online as to how I might be able to specify the inference rule.  I want to infer that something is a MasterEntity if its class is a MasterEntityType.

The explain plan is below:

Explaining Query:

select distinct ?s
where {
graph ?g {
?t a <urn:x-abbvie:rdf-service#MasterEntity> .
}
graph ?ig {
?s a ?t .
}
graph ?sg {
?s ?p ?o .
}
}

The Query Plan:

Distinct [cardinality=41]
  Projection(?s) [cardinality=41]
    LoopJoin[_] [cardinality=41]
      MergeJoin[?t] [cardinality=41]
        Sort(?t) [cardinality=1]
          TypeOf(?s, ?t)
        Union [cardinality=25]
          Scan[PSC](?t, <urn:x-abbvie:rdf-service#deleteConfiguration>, _){?g, named} [cardinality=5]
          Scan[PSC](?t, <urn:x-abbvie:rdf-service#viewConfiguration>, _){?g, named} [cardinality=20]
      Hybrid_Property(FACT(x0, x1, x2)(Var(name=2), Var(name=5) -> Var(name=4))) [cardinality=1]

What version of Stardog are you using?  We added a couple optimizations in 4.0 RC1 for the reasoner operators.  That query plan does not seem to reflect them.  Are you still using 3.x?

Also, would it be possible to get a copy of the ontology? I tried re-creating your example to verify we'd produce the plan I was expecting to see and I noticed that your snippet of the definition of MasterEntity is not in SL.

Cheers,

Mike

Tze-John Tang

unread,
Nov 11, 2015, 9:43:58 AM11/11/15
to Stardog
Mike, we have not moved to version 4 yet.

Attached is that specific OWL file.  We load each OWL into it's own named graph.

-tj
rdf-service.owl
Reply all
Reply to author
Forward
0 new messages