swish/commit
Updated RDF prefix handling example
author | Jan Wielemaker |
---|---|
Mon Sep 26 17:01:52 2016 +0200 | |
committer | Jan Wielemaker |
Mon Sep 26 17:01:52 2016 +0200 | |
commit | 904a702650d2b103975a060c3adb8a0793157550 |
tree | 5180ff8df1d32009eca313ace9ce149731928ddc |
parent | fdcd7e47b5632d6153e38f7b14e88d25ac465fe2 |
Diff style: patch stat
diff --git a/examples/prefix_examples.swinb b/examples/prefix_examples.swinb index b121633..3edf2fc 100644 --- a/examples/prefix_examples.swinb +++ b/examples/prefix_examples.swinb @@ -3,10 +3,28 @@ <div class="nb-cell markdown"> # Using RDF prefixes -RDF prefixes make long RDF resources readable and consistent renaming of resources. -They are supported by the Prolog predicates rdf_register_prefix/2, rdf_register_prefix/3 and rdf_current_prefix/2. In the current version, RDF prefixes are _global_ to the SWI-Prolog instance, i.e., all parts of the program share the same prefix declarations. +RDF prefixes make long RDF resources readable and allow for consistent renaming of resources. The RDF interface expands +terms of the shape Prefix:Local to a full URI, i.e., an _atom_. The library supports both **global** and **local** prefix +declarations: -A consequence of this is that prefixes cannot be defined if SWISH operates in anonymous query mode. + - **Global** prefix declarations are declared using the Prolog predicates rdf_register_prefix/2 or rdf_register_prefix/3. + They should be considered a property of the data and are normally declared with the application. Global prefixes may also + be defined through the ClioPatria interface. Global prefixes can only be added by priviledged users. + + - **Local** prefixes can de declared using `:- rdf_prefix(Prefix, URI)`. They are local to a module and take preference + over globally defined prefixes. The rdf_prefix/2 declaration can be used in SWISH programs. As they are local to the + temporary SWISH module there is no interference with other users. + +RDF Prefix declarations causes calls to predicates that are declared using rdf_meta/2 as well as the predicate head of such +predicates to be subject to **prefix expansion**. In addition, the following predicates can be used to interact with the +prefix declarations: + + - [[rdf_current_prefix/2]] + - [[rdf_global_id/2]] + - [[rdf_global_object/2]] + - [[rdf_global_term/2]] + +## Enumerating the known prefixes The currently known prefixes are easily enumerated: </div> @@ -58,19 +76,19 @@ person(P). <div class="nb-cell markdown"> Something similar to the above example happens less obviously in real code. We discuss these cases below. -### A <prefix>:<local> term is passed to a user defined predicate. +### A <prefix>:<local> term is passed to a user defined predicate. In this case Prolog does not know that the user predicates expects a resource and thus does not expand the resource. This can be fixed using an rdf_meta/1 declaration as shown in the code below, but unfortunately this is *not yet supported by SWISH*. - + ``` :- rdf_meta - instance_of(r,r). + instance_of(r,r). instance_of(I, Class) :- - rdf(I, rdf:type, Class). + rdf(I, rdf:type, Class). person(P) :- - instance_of(P, foaf:'Person'). + instance_of(P, foaf:'Person'). ``` The work-around is to use rdf_equal/2. This predicate is defines normal _unification_, but is annotated to expect an RDF resource as argument. This results in the following definition: @@ -101,4 +119,23 @@ one into the prefix and local name. Note the rendering of `Resource` as an abbr Term = foaf:'Person', rdf_global_id(Term, Resource). </div> +<div class="nb-cell markdown"> +## Defining prefixes in SWISH programs + +As stated in the beginning of this notebook, **global** prefixes cannot be defined in SWISH programs unless the user is logged on +with sufficient authorization. Any program can use **local** prefixes though. The code below illustrates this. Local prefix +declarations take precedence over global ones. +</div> + +<div class="nb-cell program"> +:- rdf_prefix(me, 'http://example.org/me/'). + +person(X) :- + rdf(X, rdf:type, me:'Person'). +</div> + +<div class="nb-cell query"> +listing(person/1). +</div> + </div>