3

I'm new to the semantic web concept, and I have a diploma work based on the semantic web. In my OWL ontology, I have defined the individuals in he following manner:

<Announce rdf:ID="Ann1" ...>
  <...>
  <...>
  <requiredTechnologies>
    <Technology rdfs:resource="tech1"/>
  </requiredTechnologies>
  <requiredTechnologies>
    <Technology rdfs:resource="tech2"/>
  </requiredTechnologies>
</Announce>
...

Basically, there are some properties that appear only once for a given individual, but the property "required technologies" can be used multiple times in one record (for one individual). So, when I run a SPARQL query, selecting all the data (I use Jena), I get this output:

=====================================
| "Ann1"      | ... | ... | "tech1" |
| "Ann1"      | ... | ... | "tech2" |
| "Ann2"      | ... | ... | "tech3" |
| "Ann3"      | ... | ... | "tech4" |
| "Ann3"      | ... | ... | "tech5" |
| "Ann3"      | ... | ... | "tech6" |
| ...         | ... | ... | ...     |
=====================================

The records where multiple "requiredTechnologies" attribute is present appear more then once. My question is how to get all the technologies that belong to a given individual in one line (something like this):

===================================================
| "Ann1"      | ... | ... | "tech1, tech2"        |
| "Ann2"      | ... | ... | "tech2"               |
| "Ann3"      | ... | ... | "tech4, tech5, tech6" |
| ...         | ... | ... | ...                   |
===================================================

Is there a way in SPARQL to get the multiple attribute in a list? Or any other workaround?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
icemanblas
  • 93
  • 1
  • 1
  • 10
  • 2
    Possible duplicate of [Aggregating results from SPARQL query](http://stackoverflow.com/q/18212697/1281433). Another similar question (but looking for JSON output) was asked this morning, too: [Returning object oriented json from sparql queries](http://stackoverflow.com/q/18404342/1281433). – Joshua Taylor Aug 23 '13 at 16:36
  • 1
    No problem; this is is a good question, and it's hard to know what to search for until you know the answer. – Joshua Taylor Aug 24 '13 at 03:15

1 Answers1

3

Yes, use the GROUP BY clause in conjunction with the GROUP_CONCAT aggregate.

Here's a generic example, you should easily be able to adapt to your data model:

SELECT ?s (GROUP_CONCAT(?value ; SEPARATOR = ",") AS ?values)
WHERE
{
  ?s <http://somePredicate> ?value .
}
GROUP BY ?s
RobV
  • 28,022
  • 11
  • 77
  • 119
  • 1
    **thanks** so much @RobV, it worked like magic, that's what I needed!!! I appreciate it, it's very helpful... cheers!!! – icemanblas Aug 23 '13 at 18:30