[not loaded]All predicatesShow sourcerdf11.pl -- RDF 1.1 API

This 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:

author
- Jan Wielemaker
- Wouter Beek
version
- 2016
See also
- https://github.com/SWI-Prolog/packages-semweb/wiki/Proposal-for-Semweb-library-redesign
Source rdf(?S, ?P, ?O) is nondet
Source rdf(?S, ?P, ?O, ?G) is nondet
True if an RDF triple <S,P,O> exists, optionally in the graph G. The object O is either a resource (atom) or one of the terms listed below. The described types apply for the case where O is unbound. If O is instantiated it is converted according to the rules described with rdf_assert/3.

Triples consist of the following three terms:

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.

Arguments:
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.
Source rdf_has(?S, +P, ?O) is nondet
Source rdf_has(?S, +P, ?O, -RealP) is nondet
Similar to rdf/3 and rdf/4, but P matches all predicates that are defined as an rdfs:subPropertyOf of P. This predicate also recognises the predicate properties inverse_of and symmetric. See rdf_set_predicate/2.
Source rdf_update(+S, +P, +O, ++Action) is det
Source rdf_update(+S, +P, +O, +G, ++Action) is det
Replaces one of the three (four) fields on the matching triples depending on Action:
subject(Resource)
Changes the first field of the triple.
predicate(Resource)
Changes the second field of the triple.
object(Object)
Changes the last field of the triple to the given resource or literal(Value).
graph(Graph)
Moves the triple from its current named graph to Graph. This only works with rdf_update/5 and throws an error when used with rdf_update/4.

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')).
Errors
- instantiation_error if Action or the matching argument is not ground.
- domain_error(rdf_update_action, Action) if Action is not one of the above terms.
Source rdf_reachable(?S, +P, ?O) is nondet
Source rdf_reachable(?S, +P, ?O, +MaxD, -D) is nondet
True when O can be reached from S using the transitive closure of P. The predicate uses (the internals of) rdf_has/3 and thus matches both rdfs:subPropertyOf and the 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.

Source rdf_assert(+S, +P, +O) is det
Source rdf_assert(+S, +P, +O, +G) is det
Assert a new triple. If O is a literal, certain Prolog terms are translated to typed RDF literals. These conversions are described with rdf_canonical_literal/2.

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.

Source rdf_retractall(?S, ?P, ?O) is nondet
Source rdf_retractall(?S, ?P, ?O, ?G) is nondet
Remove all matching triples from the database. Matching is performed using the same rules as rdf/3. The call does not instantiate any of its arguments.
Source rdf_compare(-Diff, +Left, +Right) is det
True if the RDF terms Left and Right are ordered according to the comparison operator Diff. The ordering is defines as:

Note that this ordering is a complete ordering of RDF terms that is consistent with the partial ordering defined by SPARQL.

Arguments:
Diff- is one of <, = or >
Source {+Where} is semidet
Source rdf_where(+Where) is semidet
Formulate constraints on RDF terms, notably literals. These are intended to be used as illustrated below. RDF constraints are pure: they may be placed before, after or inside a graph pattern and, provided the code contains no commit operations (!, ->), 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 comparison operators are defined between numbers (of any recognised type), typed literals of the same type and langStrings of the same language.
prefix(String, Pattern)
substring(String, Pattern)
word(String, Pattern)
like(String, Pattern)
icase(String, Pattern)
Text matching operators that act on both typed literals and langStrings.
lang_matches(Term, Pattern)
Demands a full RDF term (Text@Lang) or a plain Lang term to match the language pattern Pattern.

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:{...}.

Source add_lang_constraint(?Term, +Constraint)[private]
Add a constraint on the language of a literal
Source add_value_constraint(?Term, +Constraint, +Value)[private]
Apply a value constraint to the RDF Term.
Source literal_condition(+Object, -Cond) is semidet[private]
True when some of the constraints on Object can be translated into an equivalent query of the form literal(Cond, _Value). Translated constraints are removed from object.
Source best_literal_cond(+Conditions, -Best, -Rest) is semidet[private]
Extract the constraints that can be translated into the Search of literal(Search, Value).
To be done
- Select the best rather than the first.
Source in_constaint_type(?Type, -SType, ++Val, -Val0)[private]
Source literal_class(+Term, -Class)[private]
Classify Term as literal and if possible as lang or typed literal on the basis of the constraints that apply to it.
Source attr_unify_hook(+AttributeValue, +Value)[private]
Source rdf_default_graph(-Graph) is det
Source rdf_default_graph(-Old, +New) is det
Query/set the notion of the default graph. The notion of the default graph is local to a thread. Threads created inherit the default graph from their creator. See set_prolog_flag/2.
Source pre_object(+APIObject, -DBObject, +APISubject, +APIPredicate)[private]
Source pre_ground_object(+Object, -RDF) is det[private]
Convert between a Prolog value and an RDF value for rdf_assert/3 and friends. Auto-conversion:
Source in_ground_type(+Type, +Input, -Lexical:atom) is det[private]
Translate the Prolog date Input according to Type into its RDF lexical form. The lecical form is represented as an atom. In future versions this is likely to become a string.
Source in_date_time(+Type, +Input, -Lexical) is det[private]
Accepts either a term as accepted by xsd_time_string/3 or a valid string for the corresponding XSD type.
Source in_boolean(?NonCanonical, ?Canonical)[private]
True when Canonical is the canonical boolean for NonCanonical.
Source in_number(+PrologType, +Domain, +XSDType, +Value, -Lexical)[private]
Lexical is the lexical representation for Value.
Errors
- type_error(PrologType, Value)
- domain_error(XSDType, Value)
Source xsd_numerical(?URI, ?TypeCheck, ?PrologType)[private]
Source xsd_date_time_type(?URI)[private]
True when URI is an XSD date or time type.
Source in_xml_literal(+Type, +Val, -Val0) is det[private]
Translate an XMLLiteral or HTML literal to its canonical textual representation. Input is either text or a Prolog XML DOM.
To be done
- Deal with partial content?
Source rdf_canonical_literal(++In, -Literal) is det
Transform a relaxed literal specification as allowed for rdf_assert/3 into its canonical form. The following Prolog terms are translated:
Prolog TermDatatype IRI
floatxsd:double
integerxsd:integer
stringxsd:string
true or falsexsd: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'.
Source rdf_lexical_form(++Literal, -Lexical:compound) is det
True when Lexical is the lexical form for the literal Literal. Lexical is of one of the forms below. The ntriples serialization is obtained by transforming String into a proper ntriples string using double quotes and escaping where needed and turning Type into a proper IRI reference.
Source out_date_time(+DateTimeType, -Val, +Val0) is det[private]
Translate an XSD lexical form for a date/time related datatype into the cannical form as defined by xsd_time_string/3.
Source invalid_lexical_form_hook(+Type, +Lexical, -Prolog)[multifile]
This hook is called if translation of the lexical form to the Prolog representation fails due to a syntax error. By default it is not defined, causing such invalid triples to be silently ignored.
Source rdf_term(?Term) is nondet
True if Term appears in the RDF database. Term is either an IRI, literal or blank node and may appear in any position of any triple. If Term is ground, it is pre-processed as the object argument of rdf_assert/3 and the predicate is semidet.
Source rdf_literal(?Term) is nondet
True if Term is a known literal. If Term is ground, it is pre-processed as the object argument of rdf_assert/3 and the predicate is semidet.
Source rdf_bnode(?BNode) is nondet
True if BNode is a currently known blank node. The predicate is semidet if BNode is ground.
Source rdf_iri(?IRI) is nondet
True if IRI is a current IRI. The predicate is semidet if IRI is ground.
Source rdf_name(?Name) is nondet
True if Name is a current IRI or literal. The predicate is semidet if Name is ground.
 rdf_subject(?S) is nondet
True when S is a currently known subject, i.e. it appears in the subject position of some visible triple. The predicate is semidet if S is ground.
Source rdf_predicate(?P) is nondet
True when P is a currently known predicate, i.e. it appears in the predicate position of some visible triple. The predicate is semidet if P is ground.
Source rdf_object(?O) is nondet
True when O is a currently known object, i.e. it appears in the object position of some visible triple. If Term is ground, it is pre-processed as the object argument of rdf_assert/3 and the predicate is semidet.
Source rdf_node(?T) is nondet
True when T appears in the subject or object position of a known triple, i.e., is a node in the RDF graph.
Source resource(?R)[private]
True if R is a node that is not a literal. Note that RDF-DB does not necessarily include predicates in the set of resources. Also note that the resource may not really exist or be visible.
Source rdf_create_bnode(--BNode)
Create a new BNode. A blank node is an atom starting with _:. Blank nodes generated by this predicate are of the form _:genid followed by a unique integer.
Source rdf_is_iri(@IRI) is semidet
True if IRI is an RDF IRI term.

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).

 rdf_is_bnode(@Term) is semidet
True if Term is an RDF blank node identifier.

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.

Source rdf_is_literal(@Term) is semidet
True if Term is an RDF literal term.

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).

Source rdf_is_name(@Term) is semidet
True if Term is an RDF Name, i.e., an IRI or literal.

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).

Source rdf_is_object(@Term) is semidet
True if Term can appear in the object position of a triple.

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.

Source rdf_is_predicate(@Term) is semidet
True if Term can appear in the predicate position of a triple.

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.

Source rdf_is_subject(@Term) is semidet
True if Term can appear in the subject position of a triple.

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).

Source rdf_is_term(@Term) is semidet
True if Term can be used as an RDF term, i.e., if Term is either an IRI, a blank node or an RDF literal.

Success of this goal does not imply that the RDF term is present in the database (see rdf_term/1 for that).

Source rdf_list(?RDFTerm) is semidet
True if RDFTerm is a proper RDF list. This implies that every node in the list has an 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).

Source rdf_list(+RDFList, -PrologList) is det
True when PrologList represents the rdf:first objects for all cells in RDFList. Note that this can be non-deterministic if cells have multiple rdf:first or rdf:rest triples.
Source rdf_length(+RDFList, -Length:nonneg) is nondet
True when Length is the number of cells in RDFList. Note that a list cell may have multiple rdf:rest triples, which makes this predicate non-deterministic. This predicate does not check whether the list cells have associated values (rdf:first). The list must end in rdf:nil.
Source rdf_member(?Member, +RDFList) is nondet
True when Member is a member of RDFList
Source rdf_nextto(?X, ?Y) is nondet
Source rdf_nextto(?X, ?Y, ?RdfList) is nondet
True if Y directly follows X in RdfList.
Source rdf_nth0(?Index, +RDFList, ?X) is nondet
Source rdf_nth1(?Index, +RDFList, ?X) is nondet
True when X is the Index-th element (0-based or 1-based) of RDFList. This predicate is deterministic if Index is given and the list has no multiple rdf:first or rdf:rest values.
Source rdf_last(+RDFList, -Last) is det
True when Last is the last element of RDFList. Note that if the last cell has multiple rdf:first triples, this predicate becomes nondet.
Source rdf_estimate_complexity(?S, ?P, ?O, -Estimate) is det
Source rdf_assert_list(+PrologList, ?RDFList) is det
Source rdf_assert_list(+PrologList, ?RDFList, +Graph) is det
Create an RDF list from the given Prolog List. PrologList must be a proper Prolog list and all members of the list must be acceptable as object for rdf_assert/3. If RDFList is unbound and PrologList is not empty, rdf_create_bnode/1 is used to create RDFList.
Source rdf_retract_list(+RDFList) is det
Retract the rdf:first, rdf:rest and rdf:type=rdf:'List' triples from all nodes reachable through rdf:rest. Note that other triples that exist on the nodes are left untouched.

Re-exported predicates

The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.

Source rdf_meta(+Heads)
This directive defines the argument types of the named predicates, which will force compile time namespace expansion for these predicates. Heads is a coma-separated list of callable terms. Defined argument properties are:
:
Argument is a goal. The goal is processed using expand_goal/2, recursively applying goal transformation on the argument.
+
The argument is instantiated at entry. Nothing is changed.
-
The argument is not instantiated at entry. Nothing is changed.
?
The argument is unbound or instantiated at entry. Nothing is changed.
@
The argument is not changed.
r
The argument must be a resource. If it is a term prefix:local it is translated.
o
The argument is an object or resource. See rdf_global_object/2.
t
The argument is a term that must be translated. Expansion will translate all occurences of prefix:local appearing anywhere in the term. See rdf_global_term/2.

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 explicitely 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.

Undocumented predicates

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

Source rdf(Arg1, Arg2, Arg3, Arg4)
Source rdf_has(Arg1, Arg2, Arg3, Arg4)
Source rdf_update(Arg1, Arg2, Arg3, Arg4, Arg5)
Source rdf_reachable(Arg1, Arg2, Arg3, Arg4, Arg5)
Source rdf_assert(Arg1, Arg2, Arg3, Arg4)
Source rdf_retractall(Arg1, Arg2, Arg3, Arg4)
Source rdf_where(Arg1)
Source rdf_default_graph(Arg1, Arg2)
Source rdf_assert_list(Arg1, Arg2, Arg3)
Source rdf_nextto(Arg1, Arg2, Arg3)
Source rdf_nth1(Arg1, Arg2, Arg3)
 rdf_version(Arg1)
 rdf_resource(Arg1)
 rdf_member_property(Arg1, Arg2)
 rdf_set_predicate(Arg1, Arg2)
 rdf_predicate_property(Arg1, Arg2)
 rdf_transaction(Arg1)
 rdf_transaction(Arg1, Arg2)
 rdf_transaction(Arg1, Arg2, Arg3)
 rdf_active_transaction(Arg1)
 rdf_monitor(Arg1, Arg2)
 rdf_save_db(Arg1)
 rdf_save_db(Arg1, Arg2)
 rdf_load_db(Arg1)
 rdf_reset_db
 rdf_load(Arg1)
 rdf_load(Arg1, Arg2)
 rdf_save(Arg1)
 rdf_save(Arg1, Arg2)
 rdf_unload(Arg1)
 rdf_unload_graph(Arg1)
 rdf_md5(Arg1, Arg2)
 rdf_atom_md5(Arg1, Arg2, Arg3)
 rdf_create_graph(Arg1)
 rdf_graph_property(Arg1, Arg2)
 rdf_set_graph(Arg1, Arg2)
 rdf_graph(Arg1)
 rdf_source(Arg1)
 rdf_source(Arg1, Arg2)
 rdf_make
 rdf_gc
 rdf_source_location(Arg1, Arg2)
 rdf_statistics(Arg1)
 rdf_set(Arg1)
 rdf_generation(Arg1)
 rdf_snapshot(Arg1)
 rdf_delete_snapshot(Arg1)
 rdf_current_snapshot(Arg1)
 rdf_save_subject(Arg1, Arg2, Arg3)
 rdf_save_header(Arg1, Arg2)
 rdf_save_footer(Arg1)
 rdf_equal(Arg1, Arg2)
 lang_equal(Arg1, Arg2)
 lang_matches(Arg1, Arg2)
 rdf_prefix(Arg1, Arg2)
 rdf_current_prefix(Arg1, Arg2)
 rdf_register_prefix(Arg1, Arg2)
 rdf_register_prefix(Arg1, Arg2, Arg3)
 rdf_unregister_prefix(Arg1)
 rdf_current_ns(Arg1, Arg2)
 rdf_register_ns(Arg1, Arg2)
 rdf_register_ns(Arg1, Arg2, Arg3)
 rdf_global_id(Arg1, Arg2)
 rdf_global_object(Arg1, Arg2)
 rdf_global_term(Arg1, Arg2)
 rdf_match_label(Arg1, Arg2, Arg3)
 rdf_split_url(Arg1, Arg2, Arg3)
 rdf_url_namespace(Arg1, Arg2)
 rdf_warm_indexes
 rdf_warm_indexes(Arg1)
 rdf_update_duplicates
 rdf_debug(Arg1)
 rdf_new_literal_map(Arg1)
 rdf_destroy_literal_map(Arg1)
 rdf_reset_literal_map(Arg1)
 rdf_insert_literal_map(Arg1, Arg2, Arg3)
 rdf_insert_literal_map(Arg1, Arg2, Arg3, Arg4)
 rdf_delete_literal_map(Arg1, Arg2, Arg3)
 rdf_delete_literal_map(Arg1, Arg2)
 rdf_find_literal_map(Arg1, Arg2, Arg3)
 rdf_keys_in_literal_map(Arg1, Arg2, Arg3)
 rdf_statistics_literal_map(Arg1, Arg2)
 rdf_graph_prefixes(Arg1, Arg2)
 rdf_graph_prefixes(Arg1, Arg2, Arg3)