virtuoso-opensource icon indicating copy to clipboard operation
virtuoso-opensource copied to clipboard

Is there a way to get a list of triples (or subgraph) that can validate an ASK query

Open johnwick42n opened this issue 4 years ago • 4 comments

I'm looking to generate a subgraph which the query engine traverses through to validate an ASK query.

Example Query:

ASK WHERE {
    :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ .
}

Result = true

List of triples that form a solution: :personA :isSonOf :personB . :personB :isSisterOf :personC . :personC :isCousinOf :personD . :personD :isCousinOf :personZ .

Is there a way I can get that information? I'm not assuming it would be an easy task to keep listing the triples looked by Virtuoso. But if there's any chance I can make this work, I'll be more than happy to invest time implementing this on my fork.

Can someone please point me in the right direction?

johnwick42n avatar Oct 27 '20 01:10 johnwick42n

On Tue, 27 Oct 2020 at 01:35, johnwick42n [email protected] wrote:

I'm looking to generate a subgraph which the query engine traverses through to validate an ASK query.

Example Query:

ASK WHERE { :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ . }

Result = true

List of triples that form a solution: :personA :isSonOf :personB . :personB :isSisterOf :personC . :personC :isCousinOf :personD . :personD :isCousinOf :personZ .

Is there a way I can get that information? I'm not assuming it would be an easy task to keep listing the triples looked by Virtuoso. But if there's any chance I can make this work, I'll be more than happy to invest time implementing this on my fork.

Can someone please point me in the right direction?

Isn't that just a SELECT or CONSTRUCT?

~Tim

Tim Haynes Product Development Consultant OpenLink Software http://www.openlinksw.com/ http://twitter.com/openlink

timhaynesopenlink avatar Oct 27 '20 11:10 timhaynesopenlink

Isn't that just a SELECT or CONSTRUCT?

What do you think the SELECT query would look like that gives me the following triples? :

:personA :isSonOf :personB . :personB :isSisterOf :personC . :personC :isCousinOf :personD . :personD :isCousinOf :personZ .

Note: I do not know the number of nodes between :personA and :personZ (and the properties connecting them) exactly. All I have is :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ ..

johnwick42n avatar Oct 27 '20 16:10 johnwick42n

On Tue, 27 Oct 2020 at 16:32, johnwick42n [email protected] wrote:

Isn't that just a SELECT or CONSTRUCT?

What do you think the SELECT query would look like that gives me the following information? :

List of triples that form a solution: :personA :isSonOf :personB . :personB :isSisterOf :personC . :personC :isCousinOf :personD . :personD :isCousinOf :personZ .

Note: I do not know the number of nodes between :personA and :personZ (and the properties connecting them) exactly. All I have is :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ ..

You could try something like this - add an extra generic pattern and use the pattern above to refine it:

select distinct ?s ?p ?people { ?s ?p ?people . ?s :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ ?people . :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ . :personA ?p :people . }}

Not complete, not tested, definitely not working, and tbh not something I've had to do with property-paths in the mix before, but maybe as a pointer: the idea is to get a list of all triple statements and then refine it by those that are pinned on :personA or :personZ. The point of ?people is to get a list of everyone who's on the end of such a property-path, somewhere.

~Tim

Tim Haynes Product Development Consultant OpenLink Software http://www.openlinksw.com/ http://twitter.com/openlink

timhaynesopenlink avatar Oct 27 '20 16:10 timhaynesopenlink

Not complete, not tested, definitely not working

Yes, I tried. thanks for the quick reply though. 😄

the idea is to get a list of all triple statements and then refine it by those that are pinned on :personA or :personZ. The point of ?people is to get a list of everyone who's on the end of such a property-path, somewhere.

Good though! Trying to look at all elements connected to :personA and then looking at all the elements connected to those elements, eventually reaching :personZ (meanwhile, making sure that the relationships justify the property path expression) is one solution. But, isn't this something that Virtuoso does anyway (internally) when it runs any of the following queries?

 ASK WHERE {
     :personA :isSonOf/(:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ .
 }
 SELECT ?someone WHERE {
     :personA :isSonOf ?someone .
     ?someone (:isBrotherOf|:isSisterOf|:isCousinOf)+ :personZ .
 }

If only there was a way to keep track of the triples it traverses through. 😞

johnwick42n avatar Oct 27 '20 18:10 johnwick42n