3

I have written a query of the form below to extract data from a schema.org/Product, however there is a isSimilarTo property associated with schema.org/Product that could have multiple values, I need to extract all the values for isSimilarTo property in an array for each product. How could I achieve that?

I am using a similar query as below:

PREFIX schema: <http://schema.org/> 
PREFIX xsd:    <http://www.w3.org/2001/XMLSchema#> 

SELECT ?productName ?modelNumber ?price ?sellerName 
WHERE {
   ?product a schema:Product . 
   ?product schema:name ?productNameVal . 
   # str() to strip any language tags
   BIND(str(?productNameVal) AS ?productName)
   ?product schema:model ?modelNumberVal . 
   BIND(str(?modelNumberVal) AS ?modelNumber)
   ?product schema:offers ?offer . 
   ?offer a schema:Offer . 
   ?offer schema:price ?priceVal . 
   # Remove $ and cast to decimal
   BIND(xsd:decimal(replace(?priceVal,"\\$","")) AS ?price)
   ?offer schema:seller ?seller. 
   # In case there's a level of indirection for seller name
   OPTIONAL {
    ?seller schema:name ?sellerSchemaName . 
   }
   BIND(str(coalesce(?sellerSchemaName,?seller)) AS ?sellerName )
}
ORDER BY ?modelNumber ?price
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
user1965449
  • 2,849
  • 6
  • 34
  • 51
  • 2
    SPARQL doesn't have a concept of array. If you want multiple values associated with another, you'd typically just get multiple rows, and perhaps order by the primary one (e.g., to get rows like "a, a1", "a, a2", etc.). However, if you absolutely need some sort of array like format, perhaps one that you can parse locally, you might find a suitable answer in [Aggregating results from SPARQL query](http://stackoverflow.com/q/18212697/1281433). – Joshua Taylor Jan 24 '15 at 16:31
  • 2
    Also see [How to concatenate a list of values in sparql?](http://stackoverflow.com/q/20231536/1281433), [RDF list subjects with their objects in a single line](http://stackoverflow.com/q/18485461/1281433), [Select (combine) multiple attribute values - SPARQL / RDF](http://stackoverflow.com/q/22584124/1281433), and [Grouping SPARQL results for the same property?](http://stackoverflow.com/q/23121038/1281433) – Joshua Taylor Jan 24 '15 at 16:32

0 Answers0