Study Vault Search notes, aliases and full text
Graph
ConceptADISAI-written · not yet proofread

SPARQL BIND

Also BIND

`BIND (expr AS ?v)` in a SPARQL WHERE clause evaluates the expression expr for every result row and adds its value as a new column ?v.

Know these firstSPARQL Query Structure

Properties#

  • expr is built from variables, constants and functions. The lecture uses STR(x) (the IRI xx as a string), REPLACE(s, regex, replacement) (replace the matches of a regular expression in ss), and LANG(x) from the FILTER examples.
  • ?v can then be selected, filtered and sorted like any other variable.
  • The (… AS ?v) syntax is the same as for aggregates in the SELECT clause (SPARQL Aggregation). BIND computes a value per row, an aggregate one value per group.
  • In the lecture, BIND replaces the triple ?venue rdfs:label ?name of the sub-SELECT query: the “name” is derived from the IRI itself instead of being looked up in the knowledge graph.

Example#

REPLACE(STR(?venue), ".*/", ""): STR turns the IRI into a string, and the regular expression .*/ matches the longest prefix ending in /. Replacing it by "" leaves the part after the last /. For the toy IRI <http://example.org/streams/conf/xyz>:

"http://example.org/streams/conf/xyz"  →  "xyz"\texttt{"http://example.org/streams/conf/xyz"} \;\to\; \texttt{"xyz"}

Lecture query (Slide 23):

SELECT ?venue ?name ?num_papers WHERE {
  {
    SELECT ?venue (COUNT(?paper) AS ?num_papers) WHERE {
      ?paper dblp:publishedInStream ?venue .
    } GROUP BY ?venue
  }
  BIND (REPLACE(STR(?venue), ".*/", "") AS ?name)
}
ORDER BY DESC(?num_papers)

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only