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