Virtuoso SPARQL 1.1. BIND Usage Examples

What?

This guide contains Virtuoso SPARQL 1.1. BIND Usage example queries which you can run against any SPARQL endpoint that supports SPARQL 1.1 and the ability to allow a verified user perform INSERT operations.

Why?

To make a SPARQL query more flexible by assigning value(s) to variable(s) and having options for more precised filtering the query results by these variables.

How?

  1. Assume the following Raw Data Representation in Turtle:

    @prefix: <http://example.org/book/> . @prefix ns: <http://example.org/ns#> . :book1 <http://purl.org/dc/elements/1.1/title> "SPARQL Tutorial" . :book1 ns:price 42 . :book1 ns:discount 0.2 . :book2 <http://purl.org/dc/elements/1.1/title> "The Semantic Web" . :book2 ns:price 23 . :book2 ns:discount 0.25 .

  2. Load the sample data:

    PREFIX : <http://example.org/book/> PREFIX ns: <http://example.org/ns#> INSERT { GRAPH <urn:sparql:bind:tests> { :book1 <http://purl.org/dc/elements/1.1/title> "SPARQL Tutorial" . :book1 ns:price 42 . :book1 ns:discount 0.2 . :book2 <http://purl.org/dc/elements/1.1/title> "The Semantic Web" . :book2 ns:price 23 . :book2 ns:discount 0.25 . } }

  3. Assume the following SPARQL query using BIND:

    PREFIX ns: <http://example.org/ns#> SELECT ?title ?price FROM <urn:sparql:bind:tests> { ?x ns:price ?p . ?x ns:discount ?discount . ?x <http://purl.org/dc/elements/1.1/title> ?title . BIND (?p*(1-?discount) AS ?price) FILTER( ?price < 20 ) }

  4. View the SPARQL Query Definition via SPARQL Protocol URL
  5. View the SPARQL Query Results via SPARQL Protocol URL

Related