2

I want to request the amounts of rooms in a venue: This is what i get:

ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/3>     -
ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/ajax-foyer>    -
ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/ajaxbalkon>    -
ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/bovenzaal>     -
ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/foyer>     -
ah:room     <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/room/grote-repetitielokaal> 

Next to that I want to get a multiline return.

ah:attachment   <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/attachment/1>   -
ah:attachment   <http://data.artsholland.com/venue/04df157e-fc47-4448-83ed-d0a8c577d7dd/attachment/2> 

I've allready searched to realize this. Found the group_concat solution, but I couldn't figure it out.

my used query in the sparql browser

Martijn Mellens
  • 524
  • 7
  • 23

1 Answers1

3

To get the amount of rooms, use a COUNT operator. You should use this in combination with a GROUP BY clause, this tells the operator which results to aggregate together. For example:

SELECT ?venue (COUNT(?room) as ?nrOfRooms)
WHERE { 
        ?venue a ah:Venue ;
               ah:room ?room . 
}
GROUP BY ?venue

The GROUP_CONCAT works pretty similarly actually. I haven't looked in detail at your query, so this may not quite correspond with what the actual data looks like, but roughly, what you do is the following:

SELECT ?venue (GROUP_CONCAT(?attach) as ?attachments)
WHERE { 
        ?venue a ah:Venue ;
               ah:room ?room ;
               ah:attachment ?attach . 
}
GROUP BY ?venue

As for aggregating over a variable that is inside an OPTIONAL clause, that should make no difference.

Jeen Broekstra
  • 20,156
  • 4
  • 43
  • 67
  • When I try to put the same logic to my query, it doesn't work: SELECT DISTINCT ?venue (COUNT(?room) as ?nrOfRooms) ?geometry ?openingHours ?homePage ?shortDescription ?title ?venueType ?lat ?long ?publicTransportInformation ?telephone ?email ?attachment WHERE { ?venue a ; ah:room ?room . OPTIONAL {{ ?venue ah:openingHours ?openingHours FILTER(langMatches(lang(?openingHours), "en")) . }} – Martijn Mellens Nov 05 '12 at 13:07
  • "it doesn't work"? What errors do you get? What output did you expect, and what did you actually get? Also: please edit/update your original question with these additional details, so you can properly format it, rather than just copy/pasting into a comment. It's easier to read that way. – Jeen Broekstra Nov 05 '12 at 20:20
  • Just as a small pointer: the query you paste here doesn't have a GROUP BY clause, which, as I explained in the answer, you need to direct the aggregation. – Jeen Broekstra Nov 05 '12 at 20:22