16.2.8. Default and Named Graphs

Sometimes the default graph IRI is not known when the SPARQL query is composed. It can be added at the very last moment by providing the IRI in a 'define' clause as follows:

define input:default-graph-uri <http://example.com&gt

Such a definition overrides the default graph URI set in query by the 'FROM ...' clause (if any).

The query may contain more than one define input:default-graph-uri . The set of values of input:default-graph-uri has the highest possible priority and cannot be redefined in the rest of the text of the query by FROM clauses.

FROM NAMED clauses can be used multiple times in one query:

  SELECT ?id
  FROM NAMED <http://example.com/user1.ttl>
  OPTION (get:soft "soft", get:method "GET")
  FROM NAMED <http://example.com/user2.ttl>
  OPTION (get:soft "soft", get:method "GET")
  WHERE { GRAPH ?g { ?id a ?o } }

Similarly, define input:named-graph-uri <http://example.com> is a replacement for a FROM NAMED clause

When Virtuoso receives a SPARQL request via HTTP, the value of the default graph can be set in the protocol using a default-graph-uri HTTP parameter. Multiple occurrences of this parameter are allowed. This HTTP parameter is converted into define input:default-graph-uri . There's similar support for named-graph-uri HTTP parameter. For debugging purposes, graph names set in the protocol are sent back in the reply header as X-SPARQL-default-graph: ... and X-SPARQL-named-graph: ... header lines, one line per graph.

A web service endpoint may provide different default configurations for different host names mentioned in HTTP requests. This facility is configured via table DB.DBA.SYS_SPARQL_HOST .

create table DB.DBA.SYS_SPARQL_HOST (
  SH_HOST	varchar not null primary key, -- host mask
  SH_GRAPH_URI varchar,                 -- default graph uri
  SH_USER_URI	varchar,                  -- reserved for any use in applications
  SH_BASE_URI varchar,                  -- for future use (not used currently) to set BASE in sparql queries. Should be NULL for now.
  SH_DEFINES long varchar,              -- additional defines for requests

When the SPARQL web service endpoint receives a request it checks the Host HTTP header line. This line contains zero or more target host names, delimited by commas. For every host name in the line, the service scans the DB.DBA.SYS_SPARQL_HOST table in search of a row containing a matching host name in SH_HOST . The SH_HOST field acts as 'pattern' argument for the SQL string operator LIKE. If a matching row is found, the text of SPARQL request is extended.

If a default graph is not explicitly set by the HTTP parameters and SH_GRAPH_URI is not null then the default graph is set to SH_GRAPH_URI .

If SH_DEFINES is not null then it is added in front of the query; so this field is a good place for the text for any DEFINE options. See various DEFINE examples usage.

SH_USER_URI is for arbitrary user data and can be used in any way by the application that is "responsible" for the declared host.

The search of DB.DBA.SYS_SPARQL_HOST stops at the first found row, other possible matches are silently ignored.

Example Usage:

('example.com', 'urn:example:com', 'urn:example:user', NULL, 'define input:inference "http://mygraph.com"');