:- use_module(library(semweb/rdf11)).
![Show source Source](/linkedpolitics/swish/pldoc/res/source.png)
Triples consist of the following three terms:
- Blank nodes are encoded by atoms that start with‘_:`.
- IRIs appear in two notations:
- Full IRIs are encoded by atoms that do not start with‘_:`. Specifically, an IRI term is not required to follow the IRI standard grammar.
- Abbreviated IRI notation that allows IRI prefix aliases that are
registered by rdf_register_prefix/[2,3] to be used. Their notation is
Alias:Local
, where Alias and Local are atoms. Each abbreviated IRI is expanded by the system to a full IRI.
- Literals appear in two notations:
- String @ Lang
- A language-tagged string, where String is a Prolog string and Lang is an atom.
- Value
^
^
Type - A type qualified literal. For unknown types, Value is a
Prolog string. If type is known, the Prolog representations from the
table below are used.
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. |
- See also
- - Triple
pattern querying
- xsd_number_string/2 and xsd_time_string/3 are used to convert between lexical representations and Prolog terms.
:- use_module(library(semweb/rdf_db)).
![Show source Source](/linkedpolitics/swish/pldoc/res/source.png)
literal(Value)
if the object is a literal value. If a value of the form
NameSpaceID:LocalName is provided it is expanded to a ground atom using expand_goal/2.
This implies you can use this construct in compiled code without paying
a performance penalty. Literal values take one of the following forms:
- Atom
- If the value is a simple atom it is the textual representation of a string literal without explicit type or language qualifier.
- lang(LangID, Atom)
- Atom represents the text of a string literal qualified with the given language.
- type(TypeID, Value)
- Used for attributes qualified using the
rdf:datatype
TypeID. The Value is either the textual representation or a natural Prolog representation. See the option convert_typed_literal(:Convertor) of the parser. The storage layer provides efficient handling of atoms, integers (64-bit) and floats (native C-doubles). All other data is represented as a Prolog record.
For literal querying purposes, Object can be of the form
literal(+Query, -Value)
, where Query is one of the terms
below. If the Query takes a literal argument and the value has a numeric
type numerical comparison is performed.
- plain(+Text)
- Perform exact match and demand the language or type qualifiers to match. This query is fully indexed.
- icase(+Text)
- Perform a full but case-insensitive match. This query is fully indexed.
- exact(+Text)
- Same as
icase(Text)
. Backward compatibility. - substring(+Text)
- Match any literal that contains Text as a case-insensitive substring. The query is not indexed on Object.
- word(+Text)
- Match any literal that contains Text delimited by a non alpha-numeric character, the start or end of the string. The query is not indexed on Object.
- prefix(+Text)
- Match any literal that starts with Text. This call is intended for completion. The query is indexed using the skip list of literals.
- ge(+Literal)
- Match any literal that is equal or larger than Literal in the ordered set of literals.
- gt(+Literal)
- Match any literal that is larger than Literal in the ordered set of literals.
- eq(+Literal)
- Match any literal that is equal to Literal in the ordered set of literals.
- le(+Literal)
- Match any literal that is equal or smaller than Literal in the ordered set of literals.
- lt(+Literal)
- Match any literal that is smaller than Literal in the ordered set of literals.
- between(+Literal1, +Literal2)
- Match any literal that is between Literal1 and Literal2 in the ordered set of literals. This may include both Literal1 and Literal2.
- like(+Pattern)
- Match any literal that matches Pattern case insensitively, where the‘*' character in Pattern matches zero or more characters.
Backtracking never returns duplicate triples. Duplicates can be
retrieved using rdf/4. The predicate rdf/3
raises a type-error if called with improper arguments. If rdf/3
is called with a term literal(_)
as Subject or Predicate
object it fails silently. This allows for graph matching goals like
rdf(S,P,O)
,rdf(O,P2,O2)
to proceed without
errors.