You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Tayfun Gökmen Halaç <ta...@gmail.com> on 2012/05/03 17:11:13 UTC

SPARQL Property path in subquery

Hi,

We have the following tree ontology model:

     Item, Category and Product are classes
     Category and Product are subclasses of Item
     Item has a "parent" property and Category has "child" property

We want to query the sub-tree of a category and level of each
sub-node. We achieved that with the query below:

            PREFIX itemTree:<http://itemTree/>
                SELECT ?itemChildren (COUNT(?itemChildrensParents) AS
?level) WHERE
				{?itemChildren itemTree:parent+ itemTree:Giyim.
				?itemChildrensParents itemTree:child+ ?itemChildren. }
				GROUP BY ?itemChildren ORDER BY ?level
				
We want to use this query as a subquery of another one to union the
results with other results. But, if we use the query above as a
subquery (as seen below), ?level values returns null.

            PREFIX itemTree:<http://itemTree/>
				SELECT ?itemChildren ?level WHERE {
			    {SELECT ?itemChildren (COUNT(?itemChildrensParents) AS ?level) WHERE
				{?itemChildren itemTree:parent+ itemTree:Giyim.
				?itemChildrensParents itemTree:child+ ?itemChildren. }
				GROUP BY ?itemChildren ORDER BY ?level"  }
				}

If we don't use property path in the subquery (removing + sign from
the predicates), the query returns 1 for all ?level values as you can
predict. But, we need the count of property path.

We use arq 2.8.8. Is it not allowed to use property path in subqueries?

Thank you.

Tayfun

Re: SPARQL Property path in subquery

Posted by Tayfun Gökmen Halaç <ta...@gmail.com>.
2012/5/3 Andy Seaborne <an...@apache.org>:
> On 03/05/12 16:11, Tayfun Gökmen Halaç wrote:
>>
>>             PREFIX itemTree:<http://itemTree/>
>>                                SELECT ?itemChildren ?level WHERE {
>>                            {SELECT ?itemChildren
>> (COUNT(?itemChildrensParents) AS ?level) WHERE
>>                                {?itemChildren itemTree:parent+
>> itemTree:Giyim.
>>                                ?itemChildrensParents itemTree:child+
>> ?itemChildren. }
>>                                GROUP BY ?itemChildren ORDER BY ?level"  }
>>                                }
>
>
> (this is looks like it is extracted from something else - it has bad syntax
> at ")

(Yes, that's my fault while extracting the query out of Java class)

>
>
>> We use arq 2.8.8. Is it not allowed to use property path in
>> subqueries?
>
> Yes.
>
> Please try ARQ 2.9.0.
>
> If that does not work, could you provide a complete, minimal example.
> Without data and complete description of expected results, it's not possible
> to investigate.
>
>        Andy

ARQ 2.9.0-incubating worked! Thank you.

Tayfun

Re: SPARQL Property path in subquery

Posted by Andy Seaborne <an...@apache.org>.
On 03/05/12 16:11, Tayfun Gökmen Halaç wrote:
>              PREFIX itemTree:<http://itemTree/>
> 				SELECT ?itemChildren ?level WHERE {
> 			    {SELECT ?itemChildren (COUNT(?itemChildrensParents) AS ?level) WHERE
> 				{?itemChildren itemTree:parent+ itemTree:Giyim.
> 				?itemChildrensParents itemTree:child+ ?itemChildren. }
> 				GROUP BY ?itemChildren ORDER BY ?level"  }
> 				}

(this is looks like it is extracted from something else - it has bad 
syntax at ")

 > We use arq 2.8.8. Is it not allowed to use property path in
 > subqueries?

Yes.

Please try ARQ 2.9.0.

If that does not work, could you provide a complete, minimal example. 
Without data and complete description of expected results, it's not 
possible to investigate.

	Andy