The library(semweb/rdf11)
provides a new interface to
the SWI-Prolog RDF database based on the RDF 1.1 specification.
Triples 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.
^
^
Type
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
orfalse
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.
S | is the subject term. It is either a blank node or IRI. |
P | is the predicate term. It is always an IRI. |
O | is the object term. It is either a
literal, a blank node or IRI (except for true and false
that denote the values of datatype XSD boolean). |
G | is the graph term. It is always an IRI. |
inverse_of
and
symmetric
. See rdf_set_predicate/2.inverse_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.
Constraints on literal values
->
), the
semantics of the goal remains the same. Preferably, constraints are
placed before the graph pattern as they often help the RDF
database to exploit its literal indexes. In the example below, the
database can choose between using the subject and/or predicate hash or
the ordered literal table.
{ 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:{...}
.
Enumerating objects by role
Enumerating objects by type
Testing objects types
For 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).
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.
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).
Success 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).
Success 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 equaivalent to rdf_is_term/1.
Success 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.
Only 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)
.
Success of this goal does not imply that the RDF term is present in the database (see rdf_term/1 for that).
Prolog Term Datatype IRI float xsd:double integer xsd:integer string xsd:string true
orfalse
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'.
^
^
Type
Note that this ordering is a complete ordering of RDF terms that is consistent with the partial ordering defined by SPARQL.
Diff | is one of < , =
or > |
If 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.
_:
. Blank nodes generated by this predicate are of the form
_:genid
followed by a unique integer.
The following predicates are utilities to access RDF 1.1 collections.
A collection is a linked list created from rdf:first
and rdf:next
triples, ending in rdf:nil
.
rdf: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)
.