Towards LOC-7: beginnings of a proper instance base
[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     <!-- work database -->
44     <db path="work" schema="sparql-results">
45       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
46       <prefix>bf: http://bibframe.org/vocab/</prefix>
47       <!-- The search clause just finds ?works, present is done below -->
48       <form>SELECT DISTINCT ?work </form>
49       <criteria>?work a bf:Work</criteria>
50
51       <!-- bf.uri is a simple way to get to a work -->
52       <index type="bf.uri"> ?work a bf:Work FILTER( ?work  = %u ) </index>
53
54       <!-- Title indexes -->
55       <!-- These are messy, there are so many ways to get to a title -->
56
57       <!-- Main title. Looks logical, but in practice we have seen only a very
58       small number of these -->
59       <index type="bf.title">
60             ?work bf:title %v FILTER(contains(%v, %s))
61       </index>
62
63       <!-- worktitle seems to be the most common way to store the title of a work -->
64       <index type="bf.worktitle">
65           ?work bf:workTitle ?wt .
66           ?wt bf:titleValue %v FILTER(contains(%v, %s))
67       </index>
68
69       <!-- Combining the two above, since users are not likely to know how
70       a given title has been indexed -->
71       <index type="bf.maintitle">
72           { 
73             ?work bf:workTitle ?wt .
74             ?wt bf:titleValue %v FILTER(contains(%v, %s))
75           } UNION {
76             ?work bf:title %v FILTER(contains(%v, %s))
77           }
78       </index>
79
80
81       <!-- the worktitle can also contain a subtitle and a parttitle -->
82       <index type="bf.subtitle">?work bf:workTitle ?wt .
83           ?wt bf:subtitle %v FILTER(contains(%v, %s))
84       </index>
85
86       <index type="bf.parttitle">
87           ?work bf:workTitle ?wt .
88           ?wt bf:partTitle %v FILTER(contains(%v, %s))
89       </index>
90
91       <!-- work.titlevariation - this could also have sub- and partTitles -->
92       <index type="bf.titlevariation">
93           ?work bf:titleVariation ?tv .
94           ?tv bf:titleValue %v FILTER(contains(%v, %s))
95       </index>
96
97       <!-- Instance titles -->
98       <index type="bf.instancetitle">
99           ?inst bf:instanceOf ?work .
100           ?inst bf:instanceTitle ?it .
101           ?it bf:titleValue %v FILTER(contains(%v, %s))
102       </index>
103
104       <!-- Combined title index. There are so many ways titles can be expresses
105       in Bibframe, this seems to cover most of what we have seen -->
106       <index type="bf.anytitle">
107           { ?work bf:workTitle ?wt .
108               { ?wt bf:titleValue %v FILTER(contains(%v, %s)) } UNION
109               { ?wt bf:subtitle %v FILTER(contains(%v, %s)) } UNION
110               { ?wt bf:partTitle %v FILTER(contains(%v, %s)) }
111           } UNION {
112               ?work bf:titleVariation ?tv .
113               ?tv bf:titleValue %v FILTER(contains(%v, %s)) 
114           } UNION {
115               ?inst bf:instanceOf ?work .
116               ?inst bf:instanceTitle ?it .
117               ?it bf:titleValue %v FILTER(contains(%v, %s))
118           } UNION {
119               ?work bf:title %v FILTER(contains(%v, %s))
120           }
121       </index>
122
123       <!-- Author indexes. Much simpler than titles. -->
124       <index type="bf.creator">
125           ?work bf:creator ?c .
126           ?c bf:label %v FILTER(contains(%v, %s))
127       </index>
128
129       <index type="bf.contributor">
130           ?work bf:contributor ?c .
131           ?c bf:label %v FILTER(contains(%v, %s))
132           </index>
133
134       <!-- Subjects -->
135       <index type="bf.subject">
136           ?work bf:subject ?subject .
137           ?subject bf:label %v FILTER(contains(%v, %s))
138       </index>
139
140       <!-- Indexes for persons, organizations, etc -->
141       <!-- The person (etc) may be in any relation to the work, subject,
142       creator, etc, as long as there is a direct link -->
143       <index type="bf.person">
144           ?work ?rel ?person .
145           ?person a bf:Person .
146           ?person bf:label %v FILTER(contains(%v, %s))
147       </index>
148       <!-- TODO - make many more like the person above -->
149
150       <!-- Present formats -->
151       <!-- BF-L is just the links -->
152       <present type="BF-L">
153         CONSTRUCT { ?work ?rel ?subj }
154          WHERE {
155          ?work a bf:Work .
156          ?work ?rel ?subj .
157          ?work ?rel ?subj FILTER( str(?work) = %s )
158         }
159       </present>
160
161       <!-- BF-F expands all links, except to instances and other works -->
162       <present type="BF-F"> 
163         CONSTRUCT { ?work ?rel ?obj .
164                     ?obj ?rel1 ?obj1 .
165                     ?obj1 ?rel2 ?obj2 .
166                     ?obj2 ?rel3 ?obj3 }
167          WHERE {
168          ?work a bf:Work .
169          ?work ?rel ?obj .
170         OPTIONAL { 
171           ?obj ?rel1 ?obj1  
172             MINUS { ?obj a bf:Work } 
173             MINUS { ?obj a bf:Instance }
174             }
175         OPTIONAL {
176           ?obj1 ?rel2 ?obj2 
177             MINUS { ?obj1 a bf:Work } 
178             MINUS { ?obj1 a bf:Instance }
179             } 
180         OPTIONAL { 
181           ?obj2 ?rel3 ?obj3 
182             MINUS { ?obj2 a bf:Work } 
183             MINUS { ?obj2 a bf:Instance }
184             }
185          ?work ?rel ?obj FILTER( str(?work) = %s )
186         }
187       </present>
188
189       <!-- full, with instances. Experimental! -->
190       <present type="BF-FI">  
191         CONSTRUCT { %u ?rel ?wobj1 .
192                     ?wobj1 ?wrel1 ?wobj2 .
193                     ?wobj2 ?wrel2 ?wobj3 .
194                     ?inst ?irel1 ?iobj1 .
195                     ?iobj1 ?irel2 ?iobj2 .
196                     ?iobj2 ?irel3 ?iobj3 }
197          WHERE {
198           %u a bf:Work .
199           %u ?rel ?wobj1 .
200           OPTIONAL { <!-- note, this is not in the final construct
201           the linking triplet will get included like any others -->
202             ?inst bf:instanceOf %u
203           } 
204           &workfull; <!-- This does not seem to get expanded!! TODO -->
205           OPTIONAL {
206               ?wobj ?wrel1 ?wobj1
207               MINUS { ?wobj a bf:Work }
208               MINUS { ?wobj a bf:Instance }
209           }
210           OPTIONAL {
211               ?wobj1 ?wrel2 ?wobj2
212               MINUS { ?wobj1 a bf:Work }
213               MINUS { ?wobj1 a bf:Instance }
214           }
215           OPTIONAL {
216               ?wobj2 ?wrel3 ?wobj3
217               MINUS { ?wobj2 a bf:Work }
218               MINUS { ?wobj2 a bf:Instance }
219           }
220           <!--&instfull; -->
221           OPTIONAL {
222             ?inst ?irel1 ?iobj1
223           }
224           OPTIONAL {
225             ?iobj1 ?irel2 ?iobj2
226           }
227           OPTIONAL {
228             ?iobj2 ?irel3 ?iobj3
229           }
230
231         }
232       </present>
233     </db>
234     
235     <!-- Instance database -->
236
237     <db path="instance" schema="sparql-results">
238         <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
239         <prefix>bf: http://bibframe.org/vocab/</prefix>
240         <!-- The search clause just finds ?insts, present is done below -->
241         <form>SELECT DISTINCT ?inst </form>
242         <criteria>?inst a bf:Instance</criteria>
243
244         <!-- bf.uri is a simple way to get to a work -->
245         <index type="bf.uri"> ?inst a bf:Instance FILTER( ?inst  = %u ) </index>
246
247         <!-- Title indexes -->
248         <!-- These are messy, there are so many ways to get to a title -->
249
250         <!-- Main title. Looks logical, but in practice we have seen only a very
251         small number of these -->
252         <index type="bf.title">
253             ?inst bf:title %v FILTER(contains(%v, %s))
254         </index>
255
256         <!-- worktitle seems to be the most common way to store the title of a work -->
257         <index type="bf.instancetitle">
258             ?inst bf:instanceTitle ?it .
259             ?it bf:titleValue %v FILTER(contains(%v, %s))
260         </index>
261
262         <!-- BF-L is just the links -->
263         <present type="BF-L">
264             CONSTRUCT { ?inst ?rel ?subj }
265             WHERE {
266             ?inst a bf:Instance .
267             ?inst ?rel ?subj .
268             ?inst ?rel ?subj FILTER( str(?inst) = %s )
269             }
270         </present>
271
272         <!-- Full instance, with the related work too -->
273         <present type="BF-F">  
274             CONSTRUCT { 
275                 %u ?irel1 ?iobj1 .
276                 ?iobj1 ?irel2 ?iobj2 .
277                 ?iobj2 ?irel3 ?iobj3 .
278                 ?work ?wrel1 ?wobj1 .
279                 ?wobj1 ?wrel2 ?wobj2 .
280                 ?wobj2 ?wrel3 ?wobj3
281             }
282             WHERE {
283                 %u a bf:Instance .
284                 %u ?irel1 ?iobj1
285                 OPTIONAL {
286                     ?iobj1 ?irel2 ?iobj2
287                     MINUS { ?iobj1 a bf:Work }
288                     MINUS { ?iobj1 a bf:Instance }
289                     OPTIONAL {
290                         ?iobj2 ?irel3 ?iobj3
291                         MINUS { ?iobj2 a bf:Work }
292                         MINUS { ?iobj2 a bf:Instance }
293                     }
294                 }
295
296                 OPTIONAL {
297                     %u bf:instanceOf ?work
298                     OPTIONAL {
299                         ?work ?wrel1 ?wobj1
300                         MINUS { ?wobj1 a bf:Work }
301                         MINUS { ?wobj1 a bf:Instance }
302                         OPTIONAL {
303                             ?wobj1 ?wrel2 ?wobj2
304                             MINUS { ?wobj2 a bf:Work }
305                             MINUS { ?wobj2 a bf:Instance }
306                             OPTIONAL {
307                                 ?wobj2 ?wrel3 ?wobj3
308                                 MINUS { ?wobj3 a bf:Work }
309                                 MINUS { ?wobj3 a bf:Instance }
310                             }
311                         }
312                     }
313                 }
314             }
315         </present>
316
317     </db>
318
319     <!-- Small databases -->
320
321     <!-- "small" contains all the things common to all small databases -->
322     <!-- It is only to be used as an include, it is not searchable, since -->
323     <!-- it has no schema atribute -->
324     <!-- It is divided into "smallindex", "smallbody", and a "small" that includes
325     both, so that title searches can include the body, but have different indexes -->
326     
327     <db path="smallindex">
328       <index type="any">?thing bf:label %v FILTER(contains(%v, %s))</index>
329       <index type="1016">?thing bf:label %v FILTER(contains(%v, %s))</index>
330     </db>
331
332     <db path="smallbody">
333       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
334       <prefix>bf: http://bibframe.org/vocab/</prefix>
335       <form>SELECT DISTINCT ?thing </form>
336       <criteria>?thing ?rel ?obj</criteria>
337       <present type="BF-L">
338         CONSTRUCT { %u ?rel ?obj }
339          WHERE {
340            %u ?rel ?obj .
341          }
342       </present>
343       <!-- Experimental, to get just the URIs out, in proper rdf. Probably not useful 
344       <uri type="BF-U">
345         CONSTRUCT { %u bf:uri %u }
346          WHERE {
347            %u bf:label ?lbl .
348          }
349       </uri>
350       -->
351       <present type="BF-F">
352           <!-- I don't think we need more than one level for these simple 
353           databases -->
354         CONSTRUCT { %u ?rel ?obj . 
355                     ?obj ?rel1 ?obj1 .
356                   }
357          WHERE {
358            %u ?rel ?obj .
359            OPTIONAL { ?obj ?rel1 ?obj1 }
360          }
361       </present>
362     </db>
363     <db path="small" include="smallindex smallbody"/>
364     
365     <db path="place" schema="sparql-results" include="small" >
366       <criteria>?thing a bf:Place</criteria>
367       <index type="bf.place">?thing bf:label %v FILTER(contains(%v, %s))</index>
368     </db>
369     <db path="person" schema="sparql-results" include="small" >
370       <criteria>?thing a bf:Person</criteria>
371       <index type="bf.person">?thing bf:label %v FILTER(contains(%v, %s))</index>
372     </db>
373     <db path="meeting" schema="sparql-results" include="small" >
374       <criteria>?thing a bf:Meeting</criteria>
375       <index type="bf.meeting">?thing bf:label %v FILTER(contains(%v, %s))</index>
376     </db>
377     <db path="agent" schema="sparql-results" include="small" >
378       <criteria>?thing a bf:Agent</criteria>
379       <index type="bf.agent">?thing bf:label %v FILTER(contains(%v, %s))</index>
380     </db>
381     <db path="event" schema="sparql-results" include="small" >
382       <criteria>?thing a bf:Event</criteria>
383       <index type="bf.event">?thing bf:label %v FILTER(contains(%v, %s))</index>
384     </db>
385     <db path="organization" schema="sparql-results" include="small" >
386       <criteria>?thing a bf:Organization</criteria>
387       <index type="bf.organization">?thing bf:label %v FILTER(contains(%v, %s))</index>
388     </db>
389     <db path="topic" schema="sparql-results" include="small" >
390       <criteria>?thing a bf:Topic</criteria>
391       <index type="bf.topic">?thing bf:label %v FILTER(contains(%v, %s))</index>
392     </db>
393
394     <!-- Title search, probably not needed. -->
395     <db path="title" schema="sparql-results" include="smallbody" >
396       <criteria>?thing a bf:Title</criteria>
397       <index type="any">
398            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
399            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
400            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
401       </index>
402       <index type="1016">
403            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
404            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
405            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
406       </index>
407       <index type="bf.title">?thing bf:titleValue %v FILTER(contains(%v, %s))</index>
408       <index type="bf.subtitle">?thing bf:subtitle %v FILTER(contains(%v, %s))</index>
409       <index type="bf.parttitle">?thing bf:partTitle %v FILTER(contains(%v, %s))</index>
410     </db>
411
412     <!-- A hack to be able to look at any triplet in the base -->
413     <!-- TODO - Switch to the new system, probably using "small" -->
414     <db path="node" schema="sparql-results">
415       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
416       <prefix>bf: http://bibframe.org/vocab/</prefix>
417       <form>SELECT ?node ?rel ?obj</form>
418       <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
419     </db>
420     <!-- A way to see which triplets refers to a given uri. -->
421     <!-- TODO - Switch to the new system, probably using "small" -->
422     <db path="ref" schema="sparql-results">
423       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
424       <prefix>bf: http://bibframe.org/vocab/</prefix>
425       <form>SELECT ?node ?rel ?obj</form>
426       <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
427     </db>
428   </filter>
429   <filter type="log">
430     <message>http</message>
431     <category apdu="true"/>
432   </filter>
433   <filter type="http_client">
434     <x-forwarded-for>true</x-forwarded-for>
435   </filter>
436 </filters>