This module allows you to write programs that can be executed on a triplestore or directly on the in-memory
SWI-Prolog rdf database.
Sparqlprog defines predicates such as rdf_path/3 and str_starts/2. These are usually compiled down to SPARQL queries.
This module provides prolog implementations for these predicates using predicates such as rdf/3
Many of the predicates here take an argument strlike - this can be either an atom or a string.
- lcase(+S:strlike, ?V:str)
- regex(?String, +Pattern, +Flag) is nondet
- regex(?String, +Pattern) is nondet
- equivalent to REGEX in SPARQL
corresponds to re_match/2 in SPARQL
- eval_to_atom(?X, ?A) is nondet
- evaluates expression X ensuring A is an atom
- str_starts(+S:strlike, +Sub:strlike) is semidet
- str_ends(+S:strlike, +Sub:strlike) is semidet
- str_before(+S:strlike, +Sep:strlike, ?Sub:strlike) is det
- str_after(+S:strlike, +Sep:strlike, ?Sub:strlike) is det
- str_replace(+S:strlike, +Match:strlike, +Replace:strlike, ?NewStr:strlike) is det
- concat(?S1, ?S2, ?S) is nondet
- equivalent to CONCAT in SPARQL
- concat(+S1, +S2, +S3, ?S) is nondet
- equivalent to CONCAT in SPARQL
- count(?L, ?N) is nondet
- agg_max(?L, ?N) is nondet
- group_concat(?L, ?Sep, ?V) is nondet
- aggregate_group(+AggExpression, +GroupBys:list, +Goal, ?Val) is det
- perform an aggregate query
equivalent to GROUP BY queries in SPARQL
maps to aggregate/3 in prolog
- rdf_path(?S, +Path, ?O, ?G) is nondet
- rdf_path(?S, +Path, ?O) is nondet
- Evaluate an rdf path expression in terms of rdf/3.
See https://www.w3.org/TR/sparql11-query/#propertypaths
==
Path = Pred OR \Path OR P|Q OR P\Q OR zeroOrMore(Path)
OR oneOrMore(Path)
OR inverseOf(Path)
==
- optional(?G) is det
- call G once, succeed if G fails
equivalent to OPTIONAL in SPARQL
- ensure_atom(?Str:strlike, ?Atom:atom) is det
- convert a string, literal, or any strlike entity to an atom
- ensure_string(?A, ?Str:string) is det
- convert an entity to its string representation
- ensure_atoms(?Input:list, ?Atoms:list) is det
- if(?E1, ?E2, ?E3, ?R) is nondet
- bind(?ReturnValue, +FunctionTerm)
- evaluates a function term.
The function term can be a:
- SPARQL builtin (e.g. coalesce, regex)
- An arithmetic term (e.g. 1 + (2 / X) )
- An abritrary prolog goal term in which:
- the final argument N is treated as result/output
- the arguments 1..( N-1) are treated as inputs
- inputs should be ground
- determinism or semi-determinism assumed when inputs are ground
- seval(+FunctionTerm, ?ReturnValue)
- evaluates a function term
this is the same as bind/2 with args reversed.
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.
- regex(Arg1, Arg2)
- iri_prefix_curie(Arg1, Arg2, Arg3)
- iri_prefix(Arg1, Arg2)
- iri_curie(Arg1, Arg2)
- curie_prefix(Arg1, Arg2)
- rdf_path(Arg1, Arg2, Arg3)