You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Hashim Khan <en...@gmail.com> on 2024/04/17 21:44:52 UTC

Decompose a query into Star, Path and Sink shapes

Hi,

Using Apache Jena, decomposing a SPARQL query into sub-queries based on its
shape is what I need. So far, I found a class for StartPattern and I am
wondering if someone can tell me about such a resource for "path
pattern" and "Sink pattern" ... Thanks in advance


Best,
-- 
*Hashim Khan*

Re: Decompose a query into Star, Path and Sink shapes

Posted by Hashim Khan <en...@gmail.com>.
Let me explain it with an example query below.

SELECT ?person ?name ?birthPlaceName ?occupationName ?educationName
?workName ?workDescription ?birthPlaceDescription
WHERE {
  ?person foaf:name ?name .  \\ tp1
  ?person dbo:birthPlace ?birthPlace . \\ tp2
  ?birthPlace rdfs:label ?birthPlaceName . \\ tp3
  ?person dbo:occupation ?occupation . \\tp4
  ?occupation rdfs:label ?occupationName .  \\tp5
  ?person dbo:education ?education .  \\tp6
  ?education rdfs:label ?educationName .  \\tp7
  ?person dbo:work ?work .  \\tp8
  ?work rdfs:label ?workName .  \\tp9
  ?work rdfs:comment ?workDescription .  \\tp10
  ?birthPlace rdfs:comment ?birthPlaceDescription . \\tp11
}

Structure wise I want to decompose this query into Star, Path and Sink
sub-queries.

?person are common in tp1, tp2, tp4, tp6, tp8 so it gives a
Star-shaped structure. So lets say combination of all these triples is one
sub-query
?birthPlace is common in tp3 and tp11 so it is a second such
Star-shaped sub query
Similarly ?work is common is two of the triple patterns at subject position
so it is the 3rd star shape sub query.

About path shape, ?birthPlace is at Object position in tp2 and at Subject
position in tp3 so tp2 and tp3 make a Path sub query .... in case, if the
object of tp3 comes as a subject of the other triple pattern then this Path
sub query would be of three triple patterns .....

About sink sub query, if two or more triple patterns share the same Object
then we call it a Sink sub query .... we don't have such a pattern in this
query...

I want to decompose such a BGP query into many such possible sub-queries.

On Thu, Apr 18, 2024 at 11:54 AM Lorenz Buehmann <
buehmann@informatik.uni-leipzig.de> wrote:

> Hi,
>
> can you give an example what you're trying to achieve? And what is the
> use case? Query optimization? Text to SPARQL? Are you talking about
> SPARQL, SHeX or SHACL?
>
> In case of SPARQL queries, decomposing a SPARQL query into some
> sub-structures depends on what you assume being parts for your use case.
>
> Also, I'm not sure what you consider as [Start|Path|Sink]-Patterns? Are
> those common terms?
>
>
> On 17.04.24 23:44, Hashim Khan wrote:
> > Hi,
> >
> > Using Apache Jena, decomposing a SPARQL query into sub-queries based on
> its
> > shape is what I need.
>
> Indeed, you can see a SPARQL query as a graph - some people talk about
> query graphs - and then you could apply common graph-based techniques to
> divide the graph into parts. Traversing the SPARQL structure can be done
> on the "Element" layer in Jena code.
>
> But I personally, would simply convert the SPARQL query (or maybe the
> algebra) to some JGraphT graph and then work on the method from this
> graph-driven framework. At least that's how we were doing it in the
> past. Indeed, this is mostly
>
> >   So far, I found a class for StartPattern and I am
> > wondering if someone can tell me about such a resource for "path
> > pattern" and "Sink pattern" ... Thanks in advance
> I don't see a class StartPattern in the code, that's only something in
> the context of SHeX.
> >
> >
> > Best,
>
> --
> Lorenz Bühmann
> Research Associate/Scientific Developer
>
> Email buehmann@infai.org
>
> Institute for Applied Informatics e.V. (InfAI) | Goerdelerring 9 | 04109
> Leipzig | Germany
>
>

-- 
*Hashim Khan*

Re: Decompose a query into Star, Path and Sink shapes

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
Hi,

can you give an example what you're trying to achieve? And what is the 
use case? Query optimization? Text to SPARQL? Are you talking about 
SPARQL, SHeX or SHACL?

In case of SPARQL queries, decomposing a SPARQL query into some 
sub-structures depends on what you assume being parts for your use case.

Also, I'm not sure what you consider as [Start|Path|Sink]-Patterns? Are 
those common terms?


On 17.04.24 23:44, Hashim Khan wrote:
> Hi,
>
> Using Apache Jena, decomposing a SPARQL query into sub-queries based on its
> shape is what I need.

Indeed, you can see a SPARQL query as a graph - some people talk about 
query graphs - and then you could apply common graph-based techniques to 
divide the graph into parts. Traversing the SPARQL structure can be done 
on the "Element" layer in Jena code.

But I personally, would simply convert the SPARQL query (or maybe the 
algebra) to some JGraphT graph and then work on the method from this 
graph-driven framework. At least that's how we were doing it in the 
past. Indeed, this is mostly

>   So far, I found a class for StartPattern and I am
> wondering if someone can tell me about such a resource for "path
> pattern" and "Sink pattern" ... Thanks in advance
I don't see a class StartPattern in the code, that's only something in 
the context of SHeX.
>
>
> Best,

-- 
Lorenz Bühmann
Research Associate/Scientific Developer

Email buehmann@infai.org

Institute for Applied Informatics e.V. (InfAI) | Goerdelerring 9 | 04109 Leipzig | Germany