Did you know ... Search Documentation:
Pack sparqlprog -- prolog/sparqlprog.pl
PublicShow source

Samer Abdallah, Dept. of Computer Science, UCL (2014) Based on Yves Raimond's swic package, but completely re-written.

This module provides a little language for expressing SPARQL queries and a database of known SPARQL endpoints. Queries can be executed across multiple endpoints in parallel. When using auto-paging, multiple queries are made automatically to fetch new bindings as they are needed. For example,

EP ?? rdf(A,B,C).

will retrieve all triples from all endpoints in parallel, fetching 100 bindings at a time from each endpoint (assuming the setting sparqlprog:limit takes it's default value of 100).

 ??(+Goal:sparql_goal) is nondet
Equivalent to _ ?? Goal. Will query all endpoints in parallel. Identical bindings may be returned multiple times. See query_goal/3 for details.
 ??(EP, +Goal:sparql_goal) is nondet
Equivalent to query_goal(EP,Goal,Opts) where Opts is the value of the setting sparqlprog:select_options. See query_goal/3 for details. IF EP is unbound on entry, it is bound to the endpoint from which the current bindings were obtained.
 srule(+Pred, +Args) is det
 srule(+Pred, +Args, +Desc) is det
declare a new sparql rule
 sparql_endpoint(+EP:ground, +URL:atom, +Options) is det
 sparql_endpoint(+EP:ground, +URL:atom) is det
Declares EP as a short name for a SPARQL endpoint with the given URL. No options are defined at the moment.
 current_sparql_endpoint(-EP:ground, -Host:atom, -Port:natural, -Path:atom, -Options:list) is nondet
Succeeds once for each known endpoint.
 query_goal(+EP, +Goal:sparql_goal, +Opts) is nondet
query_goal(-EP, +Goal:sparql_goal, +Opts) is nondet
Runs a SPARQL query against one or more SPARQL endpoints. Goal is converted into a textual SPARQL query using the DCG defined in sparql_dcg.pl.

If EP is ground on entry, the query is run against the specified endpoint. If EP is unbound on entry, the query is run agains all endpoints in parallel, possibly returning multiple results from each.

(The following applies only to queries that return bindings, not to simple boolean questions, which return only true or false.) Options are as follows:

limit(L:natural)
At-most this many bindings will be returned per SPARQL call.
offset(O:natural)
Begin returning bindings from the Oth result on.
autopage(Auto:bool)
If false, a single SPARQL call is made using any limit and offset options if supplied. If true, then the offset option is ignored and multiple SPARQL queries are made as necessary to supply results, using the limit option to determine the number of results retrieved from the endpoint at a time. Other options are passed to phrase_to_sparql/2.
 create_sparql_select(+Goal, -SPARQL, +Opts) is det
 create_sparql_select(+Goal, -SPARQL) is det
Generates a sparql SELECT or ASK statement for a prolog goal without executing it.

Goal can be any prolog goal consisting of based rdf/3 or rdf/4 statements, filters, or terms that can be rewritten in this way

 inject_label_query(+Select, +Query, ?Select2, ?Query2, +Opts) is det
Add an optional(rdf(X,rdfs:label,XL)) for every variable X in Select TODO: interleave
 create_sparql_construct(+Head, +Goal, -SPARQL, +Opts) is det
 create_sparql_construct(+Head, +Goal, -SPARQL) is det
Generates a sparql CONSTRUCT statement for a prolog goal without executing it.

Goal or Head can be any prolog goal consisting of based rdf/3 or rdf/4 statements, filters, or terms that can be rewritten in this way

the Head forms the head part of the CONSTRUCT

 query_phrase(+EP, +Q:sparqle_phrase(R), R) is nondet
query_phrase(-EP, +Q:sparqle_phrase(R), R) is nondet
Phrase-based queries using the DCG defined in sparql_dcg.pl. The return type depends on the query:
select(V:list(var), sparql_goal, options) :: sparql_phrase(row(N)) :- length(V,N).
describe(resource,sparql_goal)            :: sparql_phrase(rdf).
describe(resource)                        :: sparql_phrase(rdf).
ask(sparql_goal)                          :: sparql_phrase(bool).

rdf  ---> rdf(resource,resource,object).
bool ---> true; false.

row(N) is the type of terms of functor row/N.

 query_sparql(?EP, SPARQL, -Result) is nondet
Runs textual SPARQL query against an endpoint, exactly as with sparql_query/3. If EP is unbound on entry, all known endpoints will be tried sequentially.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 sparql_endpoint(Arg1, Arg2)
 sparql_endpoint_url(Arg1, Arg2)
 srule(Arg1, Arg2, Arg3)
 srule(Arg1, Arg2, Arg3, Arg4)
 create_sparql_select(Arg1, Arg2)
 create_sparql_select(Arg1, Arg2, Arg3, Arg4)
 create_sparql_construct(Arg1, Arg2, Arg3)
 service_query_all(Arg1, Arg2, Arg3, Arg4)