Did you know ... Search Documentation:
rdf11.pl -- RDF 1.1 API
PublicShow source

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:

  • Literals are now represented by Value^^Type or Text@Lang. Plain literals no longer exist. Value is a Prolog representation of the value for known types. In particular:
    • xsd:double, xsd:float and xsd:decimal are represented by a Prolog float
    • Integer types are represented by a Prolog integer
    • The date/time types are presented by Prolog terms
  • Literal matching and comparison operations are represented as Prolog constraints. This replaces the 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") },
  • Graphs are always identified by the graph name only, i.e., the notation Graph:Line is no longer supported. If a graph name is an IRI then RDF prefix notation can now be used.
  • The enumeration and type-testing predicates are now more closely based on the RDF 1.1 specification and use consistent naming.
- Jan Wielemaker
- Wouter Beek
- 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:

  • 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 IRIProlog term
      xsd:decimalfloat (1)
      XSD integer sub-typesinteger
      xsd:booleantrue or false
      xsd:dateTimedate_time(Y,M,D,HH,MM,SS) (2,3)
      xsd:timetime(HH,MM,SS) (2)


(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.
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:
Changes the first field of the triple.
Changes the second field of the triple.
Changes the last field of the triple to the given resource or literal(Value).
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',
- 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:
  • Literal < BNode < IRI
  • For literals
    • Numeric < non-numeric
    • Numeric literals are ordered by value. If both are equal, floats are ordered before integers.
    • Other data types are ordered lexicographically.
  • BNodes and IRIs are ordered lexicographically.

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 >
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 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 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
true or falsexsd:boolean

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.
  • String^^Type
  • String@Lang
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 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 re-exported from other modules

Source rdf_version(-Version) is det
True when Version is the numerical version-id of this library. The version is computed as
Major*10000 + Minor*100 + Patch.
Source rdf_resource(?Resource) is nondet
True when Resource is a resource used as a subject or object in a triple.

This predicate is primarily intended as a way to process all resources without processing resources twice. The user must be aware that some of the returned resources may not appear in any visible triple.

Source rdf_member_property(?Prop, ?Index)
Deal with the rdf:_1, ... properties.
Source rdf_set_predicate(+Predicate, +Property) is det
Define a property of the predicate. This predicate currently supports the following properties:
Set/unset the predicate as being symmetric. Using symmetric(true) is the same as inverse_of(Predicate), i.e., creating a predicate that is the inverse of itself.
Sets the transitive property.
Define Predicate as the inverse of Predicate2. An inverse relation is deleted using inverse_of([]).

The transitive property is currently not used. The symmetric and inverse_of properties are considered by rdf_has/3,4 and rdf_reachable/3.

To be done
- Maintain these properties based on OWL triples.
Source rdf_predicate_property(?Predicate, ?Property)
Query properties of a defined predicate. Currently defined properties are given below.
True if the predicate is defined to be symetric. I.e., {A} P {B} implies {B} P {A}. Setting symmetric is equivalent to inverse_of(Self).
True if this predicate is the inverse of Inverse. This property is used by rdf_has/3, rdf_has/4, rdf_reachable/3 and rdf_reachable/5.
True if this predicate is transitive. This predicate is currently not used. It might be used to make rdf_has/3 imply rdf_reachable/3 for transitive predicates.
Unify Triples with the number of existing triples using this predicate as second argument. Reporting the number of triples is intended to support query optimization.
Unify Float with the average number of triples associated with each unique value for the subject-side of this relation. If there are no triples the value 0.0 is returned. This value is cached with the predicate and recomputed only after substantial changes to the triple set associated to this relation. This property is intended for path optimalisation when solving conjunctions of rdf/3 goals.
Unify Float with the average number of triples associated with each unique value for the object-side of this relation. In addition to the comments with the rdf_subject_branch_factor property, uniqueness of the object value is computed from the hash key rather than the actual values.
Same as rdf_subject_branch_factor, but also considering triples of `subPropertyOf' this relation. See also rdf_has/3.
Same as rdf_object_branch_factor, but also considering triples of `subPropertyOf' this relation. See also rdf_has/3.
See also
- rdf_set_predicate/2.
Source rdf_transaction(:Goal) is semidet
Same as rdf_transaction(Goal, user, []). See rdf_transaction/3.
Source rdf_transaction(:Goal, +Id) is semidet
Same as rdf_transaction(Goal, Id, []). See rdf_transaction/3.
Source rdf_transaction(:Goal, +Id, +Options) is semidet
Run Goal in an RDF transaction. Compared to the ACID model, RDF transactions have the following properties:
  1. Modifications inside the transactions become all atomically visible to the outside world if Goal succeeds or remain invisible if Goal fails or throws an exception. I.e., the atomicy property is fully supported.
  2. Consistency is not guaranteed. Later versions may implement consistency constraints that will be checked serialized just before the actual commit of a transaction.
  3. Concurrently executing transactions do not infuence each other. I.e., the isolation property is fully supported.
  4. Durability can be activated by loading library(semweb/rdf_persistency).

Processed options are:

Execute Goal using the state of the RDF store as stored in Snapshot. See rdf_snapshot/1. Snapshot can also be the atom true, which implies that an anonymous snapshot is created at the current state of the store. Modifications due to executing Goal are only visible to Goal.
Source rdf_active_transaction(?Id) is nondet
True if Id is the identifier of a transaction in the context of which this call is executed. If Id is not instantiated, backtracking yields transaction identifiers starting with the innermost nested transaction. Transaction identifier terms are not copied, need not be ground and can be instantiated during the transaction.
Source rdf_monitor(:Goal, +Options)
Call Goal if specified actions occur on the database.
Source rdf_save_db(+File) is det
Source rdf_save_db(+File, +Graph) is det
Save triples into File in a quick-to-load binary format. If Graph is supplied only triples flagged to originate from that database are added. Files created this way can be loaded using rdf_load_db/1.
Source rdf_save_db(+File) is det
Source rdf_save_db(+File, +Graph) is det
Save triples into File in a quick-to-load binary format. If Graph is supplied only triples flagged to originate from that database are added. Files created this way can be loaded using rdf_load_db/1.
Source rdf_load_db(+File) is det
Load triples from a file created using rdf_save_db/2.
Source rdf_reset_db
Remove all triples from the RDF database and reset all its statistics.
- This predicate checks for active queries, but this check is not properly synchronized and therefore the use of this predicate is unsafe in multi-threaded contexts. It is mainly used to run functionality tests that need to start with an empty database.
Source rdf_load(+FileOrList) is det
Same as rdf_load(FileOrList, []). See rdf_load/2.
Source rdf_load(+FileOrList, :Options) is det
Load RDF data. Options provides additional processing options. Defined options are:
How to handle equivalent blank nodes. If share (default), equivalent blank nodes are shared in the same resource.
URI that is used for rdf:about="" and other RDF constructs that are relative to the base uri. Default is the source URL.
If FileOrList is a list of files, process the input files using Jobs threads concurrently. Default is the mininum of the number of cores and the number of inputs. Higher values can be useful when loading inputs from (slow) network connections. Using 1 (one) does not use separate worker threads.
Specify the source format explicitly. Normally this is deduced from the filename extension or the mime-type. The core library understands the formats xml (RDF/XML) and triples (internal quick load and cache format). Plugins, such as library(semweb/turtle) extend the set of recognised extensions.
Named graph in which to load the data. It is not allowed to load two sources into the same named graph. If Graph is unbound, it is unified to the graph into which the data is loaded. The default graph is a file:// URL when loading a file or, if the specification is a URL, its normalized version without the optional #fragment.
When to load the file. One of true, changed (default) or not_loaded.
Unify Modified with one of not_modified, cached(File), last_modified(Stamp) or unknown.
If false, do not use or create a cache file.
If true (default false), register xmlns namespace declarations or Turtle @prefix prefixes using rdf_register_prefix/3 if there is no conflict.
If true, the message reporting completion is printed using level silent. Otherwise the level is informational. See also print_message/2.
Returns the prefixes defined in the source data file as a list of pairs.
multifile +Boolean
Indicate that the addressed graph may be populated with triples from multiple sources. This disables caching and avoids that an rdf_load/2 call affecting the specified graph cleans the graph.

Other options are forwarded to process_rdf/3. By default, rdf_load/2 only loads RDF/XML from files. It can be extended to load data from other formats and locations using plugins. The full set of plugins relevant to support different formats and locations is below:

:- use_module(library(semweb/turtle)).        % Turtle and TriG
:- use_module(library(semweb/rdf_ntriples)).
:- use_module(library(semweb/rdf_zlib_plugin)).
:- use_module(library(semweb/rdf_http_plugin)).
:- use_module(library(http/http_ssl_plugin)).
See also
- rdf_open_hook/3, library(semweb/rdf_persistency) and library(semweb/rdf_cache)
Source rdf_save(+Out) is det
Same as rdf_save(Out, []). See rdf_save/2 for details.
Source rdf_save(+Out, :Options) is det
Write RDF data as RDF/XML. Options is a list of one or more of the following options:
Save only triples associated to the given named Graph.
If false (default true) do not save blank nodes that do not appear (indirectly) as object of a named resource.
BaseURI used. If present, all URIs that can be represented relative to this base are written using their shorthand. See also write_xml_base option.
Call Convertor(-Type, -Content, +RDFObject), providing the opposite for the convert_typed_literal option of the RDF parser.
Initial xml:lang saved with rdf:RDF element.
Encoding for the output. Either utf8 or iso_latin_1.
If true (default false), inline resources when encountered for the first time. Normally, only bnodes are handled this way.
Explicitly specify saved namespace declarations. See rdf_save_header/2 option namespaces for details.
If true (default false), emit subjects sorted on the full URI. Useful to make file comparison easier.
If false, do not include the xml:base declaration that is written normally when using the base_uri option.
If false (default true), never use xml attributes to save plain literal attributes, i.e., always used an XML element as in <name>Joe</name>.
Out- Location to save the data. This can also be a file-url (file://path) or a stream wrapped in a term stream(Out).
See also
- rdf_save_db/1
Source rdf_unload(+Source) is det
Identify the graph loaded from Source and use rdf_unload_graph/1 to erase this graph.
- For compatibility, this predicate also accepts a graph name instead of a source specification. Please update your code to use rdf_unload_graph/1.
Source rdf_unload_graph(+Graph) is det
Remove Graph from the RDF store. Succeeds silently if the named graph does not exist.
Source rdf_md5(+Graph, -MD5) is det
True when MD5 is the MD5 hash for all triples in graph. The MD5 digest itself is represented as an atom holding a 32-character hexadecimal string. The library maintains the digest incrementally on rdf_load/[1,2], rdf_load_db/1, rdf_assert/[3,4] and rdf_retractall/[3,4]. Checking whether the digest has changed since the last rdf_load/[1,2] call provides a practical means for checking whether the file needs to be saved.
- New code should use rdf_graph_property(Graph, hash(Hash)).
Source rdf_atom_md5(+Text, +Times, -MD5) is det
Computes the MD5 hash from Text, which is an atom, string or list of character codes. Times is an integer >= 1. When > 0, the MD5 algorithm is repeated Times times on the generated hash. This can be used for password encryption algorithms to make generate-and-test loops slow.
- Obviously, password hash primitives do not belong in this library. The library(crypto) from the \const{ssl} package provides extensive support for hashes. The \const{clib} package provides library(crypt) to access the OS (Unix) password hash implementation as well as lightweight implementations of several popular hashes.
Source rdf_create_graph(+Graph) is det
Create an RDF graph without triples. Succeeds silently if the graph already exists.
Source rdf_graph_property(?Graph, ?Property) is nondet
True when Property is a property of Graph. Defined properties are:
Hash is the (MD5-)hash for the content of Graph.
True if the graph is modified since it was loaded or rdf_set_graph/2 was called with modified(false).
The graph is loaded from the Source (a URL)
Time is the last-modified timestamp of Source at the moment the graph was loaded from Source.
True when Count is the number of triples in Graph.

Additional graph properties can be added by defining rules for the multifile predicate property_of_graph/2. Currently, the following extensions are defined:

Source rdf_set_graph(+Graph, +Property) is det
Set properties of Graph. Defined properties are:
Set the modified state of Graph to false.
Source rdf_graph(?Graph) is nondet
True when Graph is an existing graph.
Source rdf_source(?Source)
True if Source is a loaded source.
- Use rdf_graph/1 or rdf_source/2.
Source rdf_source(?Graph, ?SourceURL) is nondet
True if named Graph is loaded from SourceURL.
- Use rdf_graph_property(Graph, source(SourceURL)).
Source rdf_make
Reload all loaded files that have been modified since the last time they were loaded.
Source rdf_gc is det
Run the RDF-DB garbage collector until no garbage is left and all tables are fully optimized. Under normal operation a separate thread with identifier __rdf_GC performs garbage collection as long as it is considered `useful'.

Using rdf_gc/0 should only be needed to ensure a fully clean database for analysis purposes such as leak detection.

Source rdf_source_location(+Subject, -Location) is nondet
True when triples for Subject are loaded from Location.
Location- is a term File:Line.
Source rdf_statistics(?KeyValue) is nondet
Obtain statistics on the RDF database. Defined statistics are:
Number of named graphs.
Total number of triples in the database. This is the number of asserted triples minus the number of retracted ones. The number of visible triples in a particular context may be different due to visibility rules defined by the logical update view and transaction isolation.
Number of resources that appear as subject or object in a triple. See rdf_resource/1.
Number of current predicates. See rdf_current_predicate/1.
Number of current literals. See rdf_current_literal/1.
gc(GCCount, ReclaimedTriples, ReindexedTriples, Time)
Information about the garbage collector.
Number of nodes expanded by rdf_reachable/3 and rdf_reachable/5.
Number of queries that have been performed for this particular instantiation pattern. Each of S,P,O,G is either + or -. Fails in case the number of performed queries is zero.
Statistics on the index for this pattern. Indices are created lazily on the first relevant query.
triples_by_graph(Graph, Count)
This statistics is produced for each named graph. See triples for the interpretation of this value.
Source rdf_set(+Term) is det
Set properties of the RDF store. Currently defines:
hash(+Hash, +Parameter, +Value)
Set properties for a triple index. Hash is one of s, p, sp, o, po, spo, g, sg or pg. Parameter is one of:
Value defines the number of entries in the hash-table. Value is rounded down to a power of 2. After setting the size explicitly, auto-sizing for this table is disabled. Setting the size smaller than the current size results in a permission_error exception.
Set maximum average collision number for the hash.
Related to resizing hash-tables. If 0, all triples are moved to the new size by the garbage collector. If more then zero, those of the last Value resize steps remain at their current location. Leaving cells at their current location reduces memory fragmentation and slows down access.
Source rdf_generation(-Generation) is det
True when Generation is the current generation of the database. Each modification to the database increments the generation. It can be used to check the validity of cached results deduced from the database. Committing a non-empty transaction increments the generation by one.

When inside a transaction, Generation is unified to a term TransactionStartGen + InsideTransactionGen. E.g., 4+3 means that the transaction was started at generation 4 of the global database and we have created 3 new generations inside the transaction. Note that this choice of representation allows for comparing generations using Prolog arithmetic. Comparing a generation in one transaction with a generation in another transaction is meaningless.

Source rdf_snapshot(-Snapshot) is det
Take a snapshot of the current state of the RDF store. Later, goals may be executed in the context of the database at this moment using rdf_transaction/3 with the snapshot option. A snapshot created outside a transaction exists until it is deleted. Snapshots taken inside a transaction can only be used inside this transaction.
Source rdf_delete_snapshot(+Snapshot) is det
Delete a snapshot as obtained from rdf_snapshot/1. After this call, resources used for maintaining the snapshot become subject to garbage collection.
Source rdf_current_snapshot(?Term) is nondet
True when Term is a currently known snapshot.
- Enumeration of snapshots is slow.
Source rdf_save_subject(+Out, +Subject:resource, +Options) is det
Save the triples associated to Subject to Out. Options:
Only save properties from Graph.
See also
- rdf_save/2 for a description of these options.
Source rdf_save_header(+Fd, +Options)
Save XML document header, doctype and open the RDF environment. This predicate also sets up the namespace notation.

Save an RDF header, with the XML header, DOCTYPE, ENTITY and opening the rdf:RDF element with appropriate namespace declarations. It uses the primitives from section 3.5 to generate the required namespaces and desired short-name. Options is one of:

Only search for namespaces used in triples that belong to the given named graph.
Where List is a list of namespace abbreviations. With this option, the expensive search for all namespaces that may be used by your data is omitted. The namespaces rdf and rdfs are added to the provided List. If a namespace is not declared, the resource is emitted in non-abreviated form.
Source rdf_save_footer(Out:stream) is det
Finish XML generation and write the document footer.
See also
- rdf_save_header/2, rdf_save_subject/3.
Source rdf_equal(?Resource1, ?Resource2)
Simple equality test to exploit goal-expansion.
Source lang_equal(+Lang1, +Lang2) is semidet
True if two RFC language specifiers denote the same language
See also
- lang_matches/2.
Source lang_matches(+Lang, +Pattern) is semidet
True if Lang matches Pattern. This implements XML language matching conform RFC 4647. Both Lang and Pattern are dash-separated strings of identifiers or (for Pattern) the wildcard *. Identifiers are matched case-insensitive and a * matches any number of identifiers. A short pattern is the same as *.
Source rdf_match_label(+How, +Pattern, +Label) is semidet
True if Label matches Pattern according to How. How is one of icase, substring, word, prefix or like. For backward compatibility, exact is a synonym for icase.
Source rdf_split_url(+Prefix, +Local, -URL) is det
rdf_split_url(-Prefix, -Local, +URL) is det
Split/join a URL. This functionality is moved to library(sgml).
- Use iri_xml_namespace/3. Note that the argument order is iri_xml_namespace(+IRI, -Namespace, -Localname).
Source rdf_url_namespace(+URL, -Namespace)
Namespace is the namespace of URL.
- Use iri_xml_namespace/2
Source rdf_warm_indexes
Warm all indexes. See rdf_warm_indexes/1.
Source rdf_warm_indexes(+Indexes) is det
Create the named indexes. Normally, the RDF database creates indexes on lazily the first time they are needed. This predicate serves two purposes: it provides an explicit way to make sure that the required indexes are present and creating multiple indexes at the same time is more efficient.
Source rdf_update_duplicates is det
Update the duplicate administration of the RDF store. This marks every triple that is potentionally a duplicate of another as duplicate. Being potentially a duplicate means that subject, predicate and object are equivalent and the life-times of the two triples overlap.

The duplicates marks are used to reduce the administrative load of avoiding duplicate answers. Normally, the duplicates are marked using a background thread that is started on the first query that produces a substantial amount of duplicates.

Source rdf_debug(+Level) is det
Set debugging to Level. Level is an integer 0..9. Default is 0 no debugging.
Source rdf_new_literal_map(-Map) is det
Create a new literal map, returning an opaque handle.
Source rdf_destroy_literal_map(+Map) is det
Destroy a literal map. After this call, further use of the Map handle is illegal. Additional synchronisation is needed if maps that are shared between threads are destroyed to guarantee the handle is no longer used. In some scenarios rdf_reset_literal_map/1 provides a safe alternative.
Source rdf_reset_literal_map(+Map) is det
Delete all content from the literal map.
Source rdf_insert_literal_map(+Map, +Key, +Value) is det
Add a relation between Key and Value to the map. If this relation already exists no action is performed.
Source rdf_insert_literal_map(+Map, +Key, +Value, -KeyCount) is det
As rdf_insert_literal_map/3. In addition, if Key is a new key in Map, unify KeyCount with the number of keys in Map. This serves two purposes. Derived maps, such as the stem and metaphone maps need to know about new keys and it avoids additional foreign calls for doing the progress in rdf_litindex.pl.
Source rdf_delete_literal_map(+Map, +Key, +Value) is det
Delete the association between Key and Value from the map.
Source rdf_delete_literal_map(+Map, +Key) is det
Delete Key and all associated values from the map.
Source rdf_find_literal_map(+Map, +KeyList, -ValueList) is det
Unify ValueList with an ordered set of values associated to all keys from KeyList. Each key in KeyList is either an atom, an integer or a term not(Key). If not-terms are provided, there must be at least one positive keywords. The negations are tested after establishing the positive matches.
Source rdf_keys_in_literal_map(+Map, +Spec, -Answer) is det
Realises various queries on the key-set:
  • all Unify Answer with an ordered list of all keys.
  • key(+Key) Succeeds if Key is a key in the map and unify Answer with the number of values associated with the key. This provides a fast test of existence without fetching the possibly large associated value set as with rdf_find_literal_map/3.
  • prefix(+Prefix) Unify Answer with an ordered set of all keys that have the given prefix. See section 3.1 for details on prefix matching. Prefix must be an atom. This call is intended for auto-completion in user interfaces.
  • ge(+Min) Unify Answer with all keys that are larger or equal to the integer Min.
  • le(+Max) Unify Answer with all keys that are smaller or equal to the integer Max.
  • between(+Min, +Max) Unify Answer with all keys between Min and Max (including).
Source rdf_statistics_literal_map(+Map, -KeyValue)
Query some statistics of the map. Provides KeyValue are:
size(-Keys, -Relations)
Unify Keys with the total key-count of the index and Relation with the total Key-Value count.
Source rdf_graph_prefixes(?Graph, -List:ord_set) is det
Source rdf_graph_prefixes(?Graph, -List:ord_set, :Options) is det
List is a sorted list of prefixes (namepaces) in Graph. Options defined are:
optional Filter argument is used to filter the results. It is called with 3 additional arguments:
call(Filter, Where, Prefix, URI)

The Where argument gives the location of the prefix ans is one of subject, predicate, object or type. The Prefix argument is the potentionally new prefix and URI is the full URI that is being processed.

Hook to generate the graph. Called using
Only include prefixes that appear at least N times. Default is 1. Declared prefixes are always returned if found at least one time.
Predicate to extract the candidate prefix from an IRI. Default is iri_xml_namespace/2.
Source rdf_graph_prefixes(?Graph, -List:ord_set) is det
Source rdf_graph_prefixes(?Graph, -List:ord_set, :Options) is det
List is a sorted list of prefixes (namepaces) in Graph. Options defined are:
optional Filter argument is used to filter the results. It is called with 3 additional arguments:
call(Filter, Where, Prefix, URI)

The Where argument gives the location of the prefix ans is one of subject, predicate, object or type. The Prefix argument is the potentionally new prefix and URI is the full URI that is being processed.

Hook to generate the graph. Called using
Only include prefixes that appear at least N times. Default is 1. Declared prefixes are always returned if found at least one time.
Predicate to extract the candidate prefix from an IRI. Default is iri_xml_namespace/2.
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.
The argument must be a resource. If it is a term prefix:local it is translated.
The argument is an object or resource. See rdf_global_object/2.
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_prefix(Arg1, Arg2)
 rdf_current_prefix(Arg1, Arg2)
 rdf_register_prefix(Arg1, Arg2)
 rdf_register_prefix(Arg1, Arg2, Arg3)
 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)