annotate cpack/p2r/README.md @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
rev   line source
Daniel@0 1 # P2R
Daniel@0 2
Daniel@0 3 A set of modules allowing you to export
Daniel@0 4 prolog predicates as RDF just by declaring
Daniel@0 5 mappings, and access them through a SPARQL
Daniel@0 6 end-point.
Daniel@0 7
Daniel@0 8 Yves Raimond (c) 2007
Daniel@0 9 Centre for Digital Music, Queen Mary,
Daniel@0 10 University of London
Daniel@0 11
Daniel@0 12 Samer Abdallah (c) 2010, 2014
Daniel@0 13 Department of Computer Science, UCL
Daniel@0 14
Daniel@0 15 ## Installation & running
Daniel@0 16
Daniel@0 17 1. Get ClioPatria from here:
Daniel@0 18 http://cliopatria.swi-prolog.org/home
Daniel@0 19 and set it up as per instructions.
Daniel@0 20
Daniel@0 21 2. Copy or link this p2r directory into the cpacks directory of
Daniel@0 22 your working ClioPatria server.
Daniel@0 23
Daniel@0 24 3. Register the cpack by doing (at the Prolog prompt)
Daniel@0 25
Daniel@0 26 ?- cpack_configure(p2r).
Daniel@0 27
Daniel@0 28 4. In your code, do
Daniel@0 29
Daniel@0 30 :- use_module(entailment(p2r)).
Daniel@0 31
Daniel@0 32 Register any prefixes you need with rdf_register_prefix/2, declare any
Daniel@0 33 macros with uripattern:def(_,_), and write your mapping rules.
Daniel@0 34
Daniel@0 35 5. Use the triples:
Daniel@0 36
Daniel@0 37 a) Select p2r\_entailment on ClioPatria's SPARQL/SeRQL page...
Daniel@0 38
Daniel@0 39 b) ...or call p2r\_entailment:rdf/3 directly (not recommended)
Daniel@0 40
Daniel@0 41 c) ...or dump all the p2r\_entailment:rdf/3 triples into the main rdf database, using, eg
Daniel@0 42
Daniel@0 43 forall(p2r_entailment:rdf(A,B,C), rdf_assert(A,B,C,p2r)).
Daniel@0 44
Daniel@0 45 Asserting the triples into a named graph (p2r) makes it easy
Daniel@0 46 to delete them all and re-import when things change.
Daniel@0 47
Daniel@0 48
Daniel@0 49 ## Pattern language
Daniel@0 50
Daniel@0 51 Resources URIs and literals are expressed using a pattern language.
Daniel@0 52 See the README in the lib directory.
Daniel@0 53
Daniel@0 54 ## Example mappings
Daniel@0 55
Daniel@0 56 Suppose you have a predicate widget/3 which holds a database of
Daniel@0 57 widget identifiers, names, and weights, and another predicate
Daniel@0 58 connectable/2 which describes which widgets can be connected
Daniel@0 59 to each other. Suppose also that the widgets are kept in a cabinet
Daniel@0 60 with pidgeon holes arranged in a matrix, and that the location of
Daniel@0 61 each widget is given by the predicate widget\_location/3.
Daniel@0 62 We could expose this as RDF using the following mappings:
Daniel@0 63
Daniel@0 64 :- rdf_register_prefix(eg,'http://www.example.org/').
Daniel@0 65 uripattern:def(loc(X,Y),num(X)/num(Y)).
Daniel@0 66
Daniel@0 67 rdf(eg:widgets/enc(ID), rdf:type, eg:schema/'Widget') <== widget(ID,_,_).
Daniel@0 68
Daniel@0 69 widget(ID,Name,Weight) ==>
Daniel@0 70 rdf(eg:widget/enc(ID), rdf:label, literal(Name)),
Daniel@0 71 rdf(eg:widget/enc(ID), eg:weight, literal(type(xsd:double,Weight)).
Daniel@0 72
Daniel@0 73 rdf(eg:widget/enc(ID1), eg:connectsTo, eg:widget/enc(ID2) <= connectable(ID1,ID2).
Daniel@0 74
Daniel@0 75 rdf(eg:widget/enc(ID), eg:location, eg:storage/loc(X,Y)) <=
Daniel@0 76 widget_location(ID,X,Y).
Daniel@0 77
Daniel@0 78 Note that URI patterns MUST be written into the rdf/3 terms in the head
Daniel@0 79 of the rule (ie, the consequent part of the implication, rather than the
Daniel@0 80 antecedent, no matter which way round the rule is written, using <== or ==>).
Daniel@0 81 Otherwise, it is your responsibilty to construct or analyse any URIs. Of course,
Daniel@0 82 you can use the uripattern module to help you do this.