This module provides a SPARQL client. For example:
?- sparql_query('select * where { ?x rdfs:label "Amsterdam" }', Row, [ host('dbpedia.org'), path('/sparql/')]). Row = row('http://www.ontologyportal.org/WordNet#WN30-108949737') ; false.
Or, querying a local server using an ASK
query:
?- sparql_query('ask { owl:Class rdfs:label "Class" }', Row, [ host('localhost'), port(3020), path('/sparql/')]). Row = true.
HTTPS servers are supported using the scheme(https)
option:
?- sparql_query('select * where { ?x rdfs:label "Amsterdam"@nl }', Row, [ scheme(https), host('query.wikidata.org'), path('/sparql') ]).
rdf(S,P,O)
for CONSTRUCT
and DESCRIBE
queries, row(...)
for
SELECT
queries and true
or false
for ASK
queries.
Options are
Variables that are unbound in SPARQL (e.g., due to SPARQL optional
clauses), are bound in Prolog to the atom '$null$'
.
SELECT
query.
Remaining options are passed to http_open/3.
The defaults for Host, Port and Path can be set using sparql_set_server/1.
The initial default for port is 80 and path is /sparql/
.
For example, the ClioPatria server understands the parameter
entailment
. The code below queries for all triples using
_rdfs_entailment.
?- sparql_query('select * where { ?s ?p ?o }', Row, [ search([entailment=rdfs]) ]).
sparql_set_server([ host(localhost), port(8080) path(world) ])
The default for port is 80 and path is /sparql/
.
v(Name, ...)
and Rows
is a list of row(....)
containing the column values in the
same order as the variable names.true
or false
v(Name, ...)
and Rows
is a list of row(....)
containing the column values in the
same order as the variable names.true
or false