Towards LOC-7: Using the include system for all small bases
[mp-sparql-moved-to-github.git] / bibframe / triplestore.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE html [
3 <!-- Entity definitions for commonly used idioms -->
4 <!-- TODO - Now it accepts these, but will not expand them in place! -->
5 <!-- Seems we can not use many special characters in these: <> % etc -->
6   <!ENTITY workfull "FOOBAR">
7   <!ENTITY workfullX "
8           OPTIONAL {
9               ?wobj ?wrel1 ?wobj1
10               MINUS { ?wobj a bf:Work }
11               MINUS { ?wobj a bf:Instance }
12           }
13           OPTIONAL {
14               ?wobj1 ?wrel2 ?wobj2
15               MINUS { ?wobj1 a bf:Work }
16               MINUS { ?wobj1 a bf:Instance }
17           }
18           OPTIONAL {
19               ?wobj2 ?wrel3 ?wobj3
20               MINUS { ?wobj2 a bf:Work }
21               MINUS { ?wobj2 a bf:Instance }
22           }
23   ">
24   <!ENTITY instfull "
25           OPTIONAL {
26             ?inst ?irel1 ?iobj1
27           }
28           OPTIONAL {
29             ?iobj1 ?irel2 ?iobj2
30           }
31           OPTIONAL {
32             ?iobj2 ?irel3 ?iobj3
33           }
34   ">
35 ]>
36
37 <filters  xmlns="http://indexdata.com/metaproxy">
38   <filter type="sparql">
39       <!-- Which sparql server to use, our demo, or your local installation -->
40     <defaults uri="http://bibframe.indexdata.com/sparql/"/>
41     <!--defaults uri="http://localhost:8890/sparql/"/-->
42
43     <!-- Any search in work returns just a list of records.
44          Present will make another request for each record to get the level
45          of details we want, depending on the schema.  -->
46     <db path="work" schema="sparql-results">
47       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
48       <prefix>bf: http://bibframe.org/vocab/</prefix>
49       <form>SELECT DISTINCT ?work
50       </form>
51       <criteria>?work a bf:Work</criteria>
52       <!-- TODO: Many more indexes like the ones below-->
53       <index type="bf.title">?work bf:workTitle ?wt .
54           ?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
55       <index type="bf.creator">?work bf:creator ?c .
56           ?c bf:label %v FILTER(contains(%v, %s))</index>
57       <index type="bf.subject">?work bf:subject ?subject .
58           ?subject bf:label %v FILTER(contains(%v, %s))
59       </index>
60       <present type="BF-L">
61         CONSTRUCT { ?work ?rel ?subj }
62          WHERE {
63          ?work a bf:Work .
64          ?work ?rel ?subj .
65          ?work ?rel ?obj FILTER( str(?work) = %s )
66         }
67       </present>
68       <present type="BF-F">
69         CONSTRUCT { ?work ?rel ?obj .
70                     ?obj ?rel1 ?obj1 .
71                     ?obj1 ?rel2 ?obj2 .
72                     ?obj2 ?rel3 ?obj3 }
73          WHERE {
74          ?work a bf:Work .
75          ?work ?rel ?obj .
76         OPTIONAL { 
77           ?obj ?rel1 ?obj1  
78             MINUS { ?obj a bf:Work } 
79           }
80         OPTIONAL {
81           ?obj1 ?rel2 ?obj2 
82             MINUS { ?obj1 a bf:Work } 
83           } 
84         OPTIONAL { 
85           ?obj2 ?rel3 ?obj3 
86             MINUS { ?obj2 a bf:Work } 
87           }
88          ?work ?rel ?obj FILTER( str(?work) = %s )
89         }
90       </present>
91       <present type="BF-FI">  <!-- full, with instances. Experimental! -->
92         CONSTRUCT { %u ?rel ?wobj1 .
93                     ?wobj1 ?wrel1 ?wobj2 .
94                     ?wobj2 ?wrel2 ?wobj3 .
95                     ?inst ?irel1 ?iobj1 .
96                     ?iobj1 ?irel2 ?iobj2 .
97                     ?iobj2 ?irel3 ?iobj3 }
98          WHERE {
99           %u a bf:Work .
100           %u ?rel ?wobj1 .
101           OPTIONAL { <!-- note, this is not in the final construct
102           the linking triplet will get included like any others -->
103             ?inst bf:instanceOf %u
104           } 
105           &workfull; <!-- This does not seem to get expanded!! -->
106           OPTIONAL {
107               ?wobj ?wrel1 ?wobj1
108               MINUS { ?wobj a bf:Work }
109               MINUS { ?wobj a bf:Instance }
110           }
111           OPTIONAL {
112               ?wobj1 ?wrel2 ?wobj2
113               MINUS { ?wobj1 a bf:Work }
114               MINUS { ?wobj1 a bf:Instance }
115           }
116           OPTIONAL {
117               ?wobj2 ?wrel3 ?wobj3
118               MINUS { ?wobj2 a bf:Work }
119               MINUS { ?wobj2 a bf:Instance }
120           }
121           <!--&instfull; -->
122           OPTIONAL {
123             ?inst ?irel1 ?iobj1
124           }
125           OPTIONAL {
126             ?iobj1 ?irel2 ?iobj2
127           }
128           OPTIONAL {
129             ?iobj2 ?irel3 ?iobj3
130           }
131
132         }
133       </present>
134     </db>
135     <!-- Instance searches, need to be refined later. TODO -->
136     <db path="instance" schema="sparql-results">
137       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
138       <prefix>bf: http://bibframe.org/vocab/</prefix>
139       <form>SELECT ?instance ?title ?format</form>
140       <criteria>?instance a bf:Instance</criteria>
141       <criteria>?instance bf:title ?title</criteria>
142       <index type="4">?instance bf:title %v FILTER(contains(%v, %s))</index>
143       <criteria>?instance bf:format ?format</criteria>
144       <index type="1013">?instance bf:format %s</index>
145     </db>
146
147     <!-- Small databases -->
148    
149     <!-- "small" contains all the things common to all small databases -->
150     <!-- It is only to be used as an include, it is not searchable, since -->
151     <!-- it has no schema atribute -->
152     <!-- It is divided into "smallindex", "smallbody", and a "small" that includes
153     both, so that title searches can include the body, but have different indexes -->
154     
155     <db path="smallindex">
156       <index type="any">?thing bf:label %v FILTER(contains(%v, %s))</index>
157       <index type="1016">?thing bf:label %v FILTER(contains(%v, %s))</index>
158     </db>
159
160     <db path="smallbody">
161       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
162       <prefix>bf: http://bibframe.org/vocab/</prefix>
163       <form>SELECT DISTINCT ?thing </form>
164       <criteria>?thing ?rel ?obj</criteria>
165       <present type="BF-L">
166         CONSTRUCT { %u ?rel ?obj }
167          WHERE {
168            %u ?rel ?obj .
169          }
170       </present>
171       <!-- Experimental, to get just the URIs out, in proper rdf. Probably not useful 
172       <uri type="BF-U">
173         CONSTRUCT { %u bf:uri %u }
174          WHERE {
175            %u bf:label ?lbl .
176          }
177       </uri>
178       -->
179       <present type="BF-F">
180           <!-- I don't think we need more than one level for these simple 
181           databases -->
182         CONSTRUCT { %u ?rel ?obj . 
183                     ?obj ?rel1 ?obj1 .
184                   }
185          WHERE {
186            %u ?rel ?obj .
187            OPTIONAL { ?obj ?rel1 ?obj1 }
188          }
189       </present>
190     </db>
191     <db path="small" include="smallindex smallbody"/>
192     
193     <db path="place" schema="sparql-results" include="small" >
194       <criteria>?thing a bf:Place</criteria>
195       <index type="bf.place">?thing bf:label %v FILTER(contains(%v, %s))</index>
196     </db>
197     <db path="person" schema="sparql-results" include="small" >
198       <criteria>?thing a bf:Person</criteria>
199       <index type="bf.person">?thing bf:label %v FILTER(contains(%v, %s))</index>
200     </db>
201     <db path="meeting" schema="sparql-results" include="small" >
202       <criteria>?thing a bf:Meeting</criteria>
203       <index type="bf.meeting">?thing bf:label %v FILTER(contains(%v, %s))</index>
204     </db>
205     <db path="agent" schema="sparql-results" include="small" >
206       <criteria>?thing a bf:Agent</criteria>
207       <index type="bf.agent">?thing bf:label %v FILTER(contains(%v, %s))</index>
208     </db>
209     <db path="event" schema="sparql-results" include="small" >
210       <criteria>?thing a bf:Event</criteria>
211       <index type="bf.event">?thing bf:label %v FILTER(contains(%v, %s))</index>
212     </db>
213     <db path="organization" schema="sparql-results" include="small" >
214       <criteria>?thing a bf:Organization</criteria>
215       <index type="bf.organization">?thing bf:label %v FILTER(contains(%v, %s))</index>
216     </db>
217     <db path="topic" schema="sparql-results" include="small" >
218       <criteria>?thing a bf:Topic</criteria>
219       <index type="bf.topic">?thing bf:label %v FILTER(contains(%v, %s))</index>
220     </db>
221
222     <!-- Title search, probably not needed. -->
223     <db path="title" schema="sparql-results" include="smallbody" >
224       <criteria>?thing a bf:Title</criteria>
225       <index type="any">
226            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
227            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
228            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
229       </index>
230       <index type="1016">
231            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
232            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
233            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
234       </index>
235       <index type="bf.title">?thing bf:titleValue %v FILTER(contains(%v, %s))</index>
236       <index type="bf.subtitle">?thing bf:subtitle %v FILTER(contains(%v, %s))</index>
237       <index type="bf.parttitle">?thing bf:partTitle %v FILTER(contains(%v, %s))</index>
238     </db>
239
240     <!-- A hack to be able to look at any triplet in the base -->
241     <!-- TODO - Switch to the new system, probably using "small" -->
242     <db path="node" schema="sparql-results">
243       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
244       <prefix>bf: http://bibframe.org/vocab/</prefix>
245       <form>SELECT ?node ?rel ?obj</form>
246       <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
247     </db>
248     <!-- A way to see which triplets refers to a given uri. -->
249     <!-- TODO - Switch to the new system, probably using "small" -->
250     <db path="ref" schema="sparql-results">
251       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
252       <prefix>bf: http://bibframe.org/vocab/</prefix>
253       <form>SELECT ?node ?rel ?obj</form>
254       <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
255     </db>
256   </filter>
257   <filter type="log">
258     <message>http</message>
259     <category apdu="true"/>
260   </filter>
261   <filter type="http_client">
262     <x-forwarded-for>true</x-forwarded-for>
263   </filter>
264 </filters>