
rdf11.pl -- RDF 1.1 APIThis library provides a new API on top of library(semweb/rdf_db). The new API follows the RDF 1.1 terminology and notation as much as possible. It runs on top of the old API, which implies that applications can use the new API in one file and the other in another one. Once the new API is considered stable and robust the old API will be deprecated.
In a nutshell, the following issues are addressed:
literal(+Search,-Value)
construct used by library(semweb/rdf_db). For example, the following
query returns literals with prefix "ams", exploiting the RDF literal
index.
{ prefix(Name, "ams") },
rdf(S,P,Name).
rdf(?S, ?P, ?O) is nondet
rdf(?S, ?P, ?O, ?G) is nondetTriples consist of the following three terms:
Alias:Local, where Alias and
Local are atoms. Each abbreviated IRI is expanded by the
system to a full IRI.| Datatype IRI | Prolog term |
|---|---|
| xsd:float | float |
| xsd:double | float |
| xsd:decimal | float (1) |
| xsd:integer | integer |
| XSD integer sub-types | integer |
| xsd:boolean | true or false |
| xsd:date | date(Y,M,D) |
| xsd:dateTime | date_time(Y,M,D,HH,MM,SS) (2,3) |
| xsd:gDay | integer |
| xsd:gMonth | integer |
| xsd:gMonthDay | month_day(M,D) |
| xsd:gYear | integer |
| xsd:gYearMonth | year_month(Y,M) |
| xsd:time | time(HH,MM,SS) (2) |
Notes:
(1) The current implementation of xsd:decimal values
as floats is formally incorrect. Future versions
of SWI-Prolog may introduce decimal as a subtype
of rational.
(2) SS fields denote the number of seconds. This can either be an integer or a float.
(3) The date_time structure can have a 7th field that
denotes the timezone offset in seconds as an
integer.
In addition, a ground object value is translated into a properly typed RDF literal using rdf_canonical_literal/2.
There is a fine distinction in how duplicate statements are handled in rdf/[3,4]: backtracking over rdf/3 will never return duplicate triples that appear in multiple graphs. rdf/4 will return such duplicate triples, because their graph term differs.
rdf_has(?S, +P, ?O) is nondet
rdf_has(?S, +P, ?O, -RealP) is nondetinverse_of and
symmetric. See rdf_set_predicate/2.
rdf_update(+S, +P, +O, ++Action) is det
rdf_update(+S, +P, +O, +G, ++Action) is detliteral(Value).
The argument matching Action must be ground. If this argument is
equivalent to the current value, no action is performed. Otherwise,
the requested action is performed on all matching triples. For
example, all resources typed rdfs:Class can be changed to
owl:Class using
?- rdf_update(_, rdf:type, rdfs:'Class',
object(owl:'Class')).
rdf_reachable(?S, +P, ?O) is nondet
rdf_reachable(?S, +P, ?O, +MaxD, -D) is nondetinverse_of and
symmetric predicate properties. The version rdf_reachable/5
maximizes the steps considered and returns the number of steps
taken.
If both S and O are given, these predicates are semidet. The
number of steps D is minimal because the implementation uses
breadth first search.
rdf_assert(+S, +P, +O) is det
rdf_assert(+S, +P, +O, +G) is detIf a type is provided using Value^^Type syntax, additional conversions are performed. All types accept either an atom or Prolog string holding a valid RDF lexical value for the type and xsd:float and xsd:double accept a Prolog integer.
rdf_retractall(?S, ?P, ?O) is nondet
rdf_retractall(?S, ?P, ?O, ?G) is nondet
rdf_compare(-Diff, +Left, +Right) is detNote that this ordering is a complete ordering of RDF terms that is consistent with the partial ordering defined by SPARQL.
{+Where} is semidet
rdf_where(+Where) is semidet
{ Date >= "2000-01-01"^^xsd:date },
rdf(S, P, Date)
The following constraints are currently defined:
The predicates rdf_where/1 and {}/1 are identical. The
rdf_where/1 variant is provided to avoid ambiguity in
applications where {}/1 is used for other purposes. Note that it
is also possible to write rdf11:{...}.
rdf_default_graph(-Graph) is det
rdf_default_graph(-Old, +New) is det
rdf_canonical_literal(++In, -Literal) is det| Prolog Term | Datatype IRI |
|---|---|
| float | xsd:double |
| integer | xsd:integer |
| string | xsd:string |
true or false | xsd:boolean |
date(Y,M,D) | xsd:date |
date_time(Y,M,D,HH,MM,SS) | xsd:dateTime |
date_time(Y,M,D,HH,MM,SS,TZ) | xsd:dateTime |
month_day(M,D) | xsd:gMonthDay |
year_month(Y,M) | xsd:gYearMonth |
time(HH,MM,SS) | xsd:time |
For example:
?- rdf_canonical_literal(42, X). X = 42^^'http://www.w3.org/2001/XMLSchema#integer'.
rdf_lexical_form(++Literal, -Lexical:compound) is det
invalid_lexical_form_hook(+Type, +Lexical, -Prolog)[multifile]
rdf_term(?Term) is nondet
rdf_literal(?Term) is nondet
rdf_bnode(?BNode) is nondet
rdf_iri(?IRI) is nondet
rdf_name(?Name) is nondet
rdf_subject(?S) is nondet
rdf_predicate(?P) is nondet
rdf_object(?O) is nondet
rdf_node(?T) is nondet
rdf_create_bnode(--BNode)_:. Blank nodes generated by this predicate are of the form
_:genid followed by a unique integer.
rdf_is_iri(@IRI) is semidetFor performance reasons, this does not check for compliance to the syntax defined in RFC 3987. This checks whether the term is (1) an atom and (2) not a blank node identifier.
Success of this goal does not imply that the IRI is present in the database (see rdf_iri/1 for that).
rdf_is_bnode(@Term) is semidet
A blank node is represented by an atom that starts with
_:.
Success of this goal does not imply that the blank node is present in the database (see rdf_bnode/1 for that).
For backwards compatibility, atoms that are represented with
an atom that starts with __ are also considered to be a
blank node.
rdf_is_literal(@Term) is semidet
An RDF literal term is of the form `String@LanguageTag or
Value^^Datatype`.
Success of this goal does not imply that the literal is well-formed or that it is present in the database (see rdf_literal/1 for that).
rdf_is_name(@Term) is semidetSuccess of this goal does not imply that the name is well-formed or that it is present in the database (see rdf_name/1 for that).
rdf_is_object(@Term) is semidetSuccess of this goal does not imply that the object term in well-formed or that it is present in the database (see rdf_object/1 for that).
Since any RDF term can appear in the object position, this is equivalent to rdf_is_term/1.
rdf_is_predicate(@Term) is semidetSuccess of this goal does not imply that the predicate term is present in the database (see rdf_predicate/1 for that).
Since only IRIs can appear in the predicate position, this is equivalent to rdf_is_iri/1.
rdf_is_subject(@Term) is semidetOnly blank nodes and IRIs can appear in the subject position.
Success of this goal does not imply that the subject term is present in the database (see rdf_subject/1 for that).
Since blank nodes are represented by atoms that start with
`_:` and an IRIs are atoms as well, this is equivalent to
atom(Term).
rdf_is_term(@Term) is semidetSuccess of this goal does not imply that the RDF term is present in the database (see rdf_term/1 for that).
rdf_list(?RDFTerm) is semidetrdf:first and rdf:rest property and
the list ends in rdf:nil.
If RDFTerm is unbound, RDFTerm is bound to each maximal RDF
list. An RDF list is maximal if there is no triple rdf(_,
rdf:rest, RDFList).
rdf_list(+RDFList, -PrologList) is det
rdf_length(+RDFList, -Length:nonneg) is nondet
rdf_member(?Member, +RDFList) is nondet
rdf_nextto(?X, ?Y) is nondet
rdf_nextto(?X, ?Y, ?RdfList) is nondet
rdf_nth0(?Index, +RDFList, ?X) is nondet
rdf_nth1(?Index, +RDFList, ?X) is nondet
rdf_last(+RDFList, -Last) is det
rdf_estimate_complexity(?S, ?P, ?O, -Estimate) is det
rdf_assert_list(+PrologList, ?RDFList) is det
rdf_assert_list(+PrologList, ?RDFList, +Graph) is det
rdf_retract_list(+RDFList) is detThe following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
rdf_current_prefix(:Alias, ?URI) is nondetrdf_current_prefix(Prefix, Expansion), atom_concat(Expansion, Local, URI),
rdf_prefix(:Alias, +URI) is det
rdf_register_prefix(+Prefix, +URI) is det
rdf_register_prefix(+Prefix, +URI, +Options) is dettrue, replace existing namespace alias. Please note
that replacing a namespace is dangerous as namespaces
affect preprocessing. Make sure all code that depends on
a namespace is compiled after changing the registration.true and Alias is already defined, keep the
original binding for Prefix and succeed silently.Without options, an attempt to redefine an alias raises a permission error.
Predefined prefixes are:
rdf_register_prefix(+Prefix, +URI) is det
rdf_register_prefix(+Prefix, +URI, +Options) is dettrue, replace existing namespace alias. Please note
that replacing a namespace is dangerous as namespaces
affect preprocessing. Make sure all code that depends on
a namespace is compiled after changing the registration.true and Alias is already defined, keep the
original binding for Prefix and succeed silently.Without options, an attempt to redefine an alias raises a permission error.
Predefined prefixes are:
rdf_unregister_prefix(+Alias) is det
rdf_current_ns(:Prefix, ?URI) is nondet
rdf_register_ns(:Prefix, ?URI) is det
rdf_register_ns(:Prefix, ?URI, +Options) is det
rdf_register_ns(:Prefix, ?URI) is det
rdf_register_ns(:Prefix, ?URI, +Options) is det
rdf_global_id(?IRISpec, :IRI) is semidetNote that this predicate is a meta-predicate on its output argument. This is necessary to get the module context while the first argument may be of the form (:)/2. The above mode description is correct, but should be interpreted as (?,?).
rdf_global_object(+Object, :GlobalObject) is semidet
rdf_global_term(+TermIn, :GlobalTerm) is det
Terms of the form Prefix:Local that appear in TermIn for which
Prefix is not defined are not replaced. Unlike rdf_global_id/2 and
rdf_global_object/2, no error is raised.
rdf_meta(+Heads)
As it is subject to term_expansion/2, the rdf_meta/1 declaration
can only be used as a directive. The directive must be processed
before the definition of the predicates as well as before
compiling code that uses the rdf meta-predicates. The atom
rdf_meta is declared as an operator exported from
library(semweb/rdf_db). Files using rdf_meta/1 must explicitly
load this library.
Beginning with SWI-Prolog 7.3.17, the low-level RDF interface
(rdf/3, rdf_assert/3, etc.) perform runtime expansion of
Prefix:Local terms. This eliminates the need for rdf_meta/1
for simple cases. However, runtime expansion comes at a
significant overhead and having two representations for IRIs (a
plain atom and a term Prefix:Local) implies that simple
operations such as comparison of IRIs no longer map to native
Prolog operations such as IRI1 == IRI2.
The following predicates are exported, but not or incorrectly documented.
lang_equal(Arg1, Arg2)
rdf_load(Arg1)
rdf_resource(Arg1)
rdf_equal(Arg1, Arg2)
rdf_reset_literal_map(Arg1)
rdf_generation(Arg1)
rdf_save(Arg1, Arg2)
rdf_save_db(Arg1, Arg2)
rdf_atom_md5(Arg1, Arg2, Arg3)
rdf_save_footer(Arg1)
rdf_make
rdf_warm_indexes(Arg1)
rdf_version(Arg1)
rdf_snapshot(Arg1)
rdf_create_graph(Arg1)
rdf_monitor(Arg1, Arg2)
rdf_load_db(Arg1)
rdf_load(Arg1, Arg2)
rdf_save_db(Arg1)
rdf_unload(Arg1)
rdf_graph_property(Arg1, Arg2)
rdf_transaction(Arg1)
rdf_save_header(Arg1, Arg2)
rdf_predicate_property(Arg1, Arg2)
rdf_delete_snapshot(Arg1)
rdf_url_namespace(Arg1, Arg2)
rdf_match_label(Arg1, Arg2, Arg3)
rdf_member_property(Arg1, Arg2)
rdf_insert_literal_map(Arg1, Arg2, Arg3)
rdf_destroy_literal_map(Arg1)
rdf_set_graph(Arg1, Arg2)
rdf_graph_prefixes(Arg1, Arg2)
rdf_set(Arg1)
rdf_set_predicate(Arg1, Arg2)
rdf_new_literal_map(Arg1)
rdf_split_url(Arg1, Arg2, Arg3)
rdf_md5(Arg1, Arg2)
rdf_graph(Arg1)
rdf_source(Arg1, Arg2)
rdf_gc
rdf_reset_db
rdf_debug(Arg1)
rdf_save_subject(Arg1, Arg2, Arg3)
rdf_keys_in_literal_map(Arg1, Arg2, Arg3)
rdf_unload_graph(Arg1)
rdf_graph_prefixes(Arg1, Arg2, Arg3)
rdf_source_location(Arg1, Arg2)
rdf_active_transaction(Arg1)
rdf_current_snapshot(Arg1)
rdf_update_duplicates
rdf_warm_indexes
rdf_delete_literal_map(Arg1, Arg2, Arg3)
rdf_find_literal_map(Arg1, Arg2, Arg3)
rdf_statistics_literal_map(Arg1, Arg2)
rdf_transaction(Arg1, Arg2, Arg3)
lang_matches(Arg1, Arg2)
rdf_statistics(Arg1)
rdf_save(Arg1)
rdf_delete_literal_map(Arg1, Arg2)
rdf_source(Arg1)
rdf_transaction(Arg1, Arg2)
rdf_insert_literal_map(Arg1, Arg2, Arg3, Arg4)