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

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