Warning:
This wiki has been archived and is now read-only.

CommentResponse:JP-3

From SPARQL Working Group
Jump to: navigation, search

JP-3

Jorge,

You asked:

SUM (?A)
:me (:friend)+/:age ?A

The query is navigating to all the friends of my friends, then to the
age value of every one, and then taking the SUM. Isn't this natural?
But, consider the following data

:me :friend :f1
:me :friend :f2
:f1 :friend :f2
:f1 :age 20
:f2 :age 20

Is there a way to correctly answer the above query with the current
design of property paths?

One way to query to get the sum of ages is:

SELECT SUM(?A)
WHERE
{ ?F :age ?A
 { SELECT DISTINCT ?F
   WHERE
    { :me (:friend)+ ?F } }} 

This puts the uniqueness on the friends, then combines it with the ages and calculates the SUM. There is a split in the property path because your query requires distinctness on one part but not another.


Consider also, the following simplified purchase order, which includes one units of :item1, by different paths (part of :compound and directly as a entry on the purchase order.

Data:

@prefix : <http://example/> .

:order :contains :thing1 .
:order :contains :compound1 .

:thing1 :unitOf :item1 .
:thing2 :unitOf :item2 .
:thing3 :unitOf :item1 .

:item2 :price 2 .
:item1 :price 2 .

:compound1 :contains :thing2 .
:compound1 :contains :thing3 .

Query:

PREFIX : <http://example/>

SELECT (SUM(?itemPrice) AS ?price)
{
  :order :contains+/:unitOf/:price ?itemPrice .
}

This returns 6 for ?price. Making the path match with DISTINCT would results in 2. Here, all the prices are the same but we wish to retain duplicates as they relate to different parts of the :order.

We would be grateful if you would acknowledge that your comment has been answered by sending a reply to this mailing list.

Andy
On behalf of the SPARQL working group.