Heavy refactoring
[mp-sparql-moved-to-github.git] / bibframe / triplestore.xml
1 <?xml version="1.0"?>
2
3 <filters  xmlns="http://indexdata.com/metaproxy">
4     <filter type="sparql">
5
6         <!-- Which sparql server to use, our demo, or your local installation -->
7         <!--defaults uri="http://bibframe.indexdata.com/sparql/"/-->
8         <defaults uri="http://localhost:8890/sparql/"/>
9
10         <!-- "thing" database that will be included all real databases -->
11         <db path="thing">  <!-- no schema, so it is not directly searchable -->
12             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
13             <prefix>bf: http://bibframe.org/vocab/</prefix>
14             <form>SELECT DISTINCT ?thing </form>
15
16             <!-- Common indexes -->
17
18             <!-- bf.uri is a simple way to get to a thing -->
19             <index type="bf.uri">
20                 ?thing  rdf:type ?any FILTER( ?thing  = %u ) </index>
21
22
23             <!-- The BF-L present format is the same for everything -->
24             <!-- Each db is supposed to provide a dedicated BF-F present format -->
25             <present type="BF-L">
26                 CONSTRUCT {
27                     ?thing ?rel ?subj
28                 }
29                 WHERE {
30                     ?thing ?rel ?subj .
31                     ?thing ?rel ?subj FILTER( str(?thing) = %s )
32                 }
33             </present>
34
35         </db>
36
37         <!-- "smallindex" db that will be included in work and instance -->
38         <!-- It provides the small indexes like bf.person, bf.place, etc -->
39         <db path="smallindex">
40             <!-- Indexes for persons, organizations, etc -->
41             <!-- The person (etc) may be in any relation to the thing, -->
42             <!-- subject, creator, etc, as long as there is a direct link -->
43             <index type="bf.person">
44                 ?thing ?rel ?person .
45                 ?person a bf:Person .
46                 ?person bf:label %v FILTER(contains(%v, %s))
47             </index>
48             <!-- TODO - make many more like the person above -->
49         </db>
50
51         <!-- work database -->
52
53         <db path="work" schema="sparql-results" include="thing smallindex">
54
55             <!-- The search clause just finds ?things, present is done below -->
56             <criteria>?thing a bf:Work</criteria>
57
58             <!-- Title indexes -->
59             <!-- These are messy, there are so many ways to get to a title -->
60
61             <!-- Main title. Looks logical, but in practice we have not seen -->
62             <!-- many of these -->
63             <index type="bf.title">
64                     ?thing bf:title %v FILTER(contains(%v, %s))
65             </index>
66
67             <!-- worktitle.titleValue seems to be the most common way to -->
68             <!-- store the title of a work -->
69             <index type="bf.worktitle">
70                 ?thing bf:workTitle ?wt .
71                 ?wt bf:titleValue %v FILTER(contains(%v, %s))
72             </index>
73
74             <!-- Combining the two above, since users are not likely -->
75             <!-- to know how a given title has been indexed -->
76             <!-- TODO is "maintitle" a good name for this? I made it up myself -->
77             <index type="bf.maintitle">
78                 {
79                     ?thing bf:workTitle ?wt .
80                     ?wt bf:titleValue %v FILTER(contains(%v, %s))
81                 } UNION {
82                     ?thing bf:title %v FILTER(contains(%v, %s))
83                 }
84             </index>
85
86             <!-- the worktitle can also contain a subtitle and a parttitle -->
87             <index type="bf.subtitle">?thing bf:workTitle ?wt .
88                 ?wt bf:subtitle %v FILTER(contains(%v, %s))
89             </index>
90
91             <index type="bf.parttitle">
92                 ?thing bf:workTitle ?wt .
93                 ?wt bf:partTitle %v FILTER(contains(%v, %s))
94             </index>
95
96             <!-- work.titlevariation - this could also have sub- and partTitles -->
97             <index type="bf.titlevariation">
98                 ?thing bf:titleVariation ?tv .
99                 ?tv bf:titleValue %v FILTER(contains(%v, %s))
100             </index>
101
102             <!-- Instance titles -->
103             <index type="bf.instancetitle">
104                 ?inst bf:instanceOf ?thing .
105                 ?inst bf:instanceTitle ?it .
106                 ?it bf:titleValue %v FILTER(contains(%v, %s))
107             </index>
108
109             <!-- Combined title index. There are so many ways titles can be expresses
110             in Bibframe, this seems to cover most of what we have seen -->
111             <!-- TODO - See the anytitle in instance for a more flexible way -->
112             <index type="bf.anytitle">
113                 {
114                     ?thing bf:workTitle ?wt .
115                     { ?wt bf:titleValue %v FILTER(contains(%v, %s)) } UNION
116                     { ?wt bf:subtitle %v FILTER(contains(%v, %s)) } UNION
117                     { ?wt bf:partTitle %v FILTER(contains(%v, %s)) }
118                 } UNION {
119                     ?thing bf:titleVariation ?tv .
120                     ?tv bf:titleValue %v FILTER(contains(%v, %s))
121                 } UNION {
122                     ?inst bf:instanceOf ?thing .
123                     ?inst bf:instanceTitle ?it .
124                     ?it bf:titleValue %v FILTER(contains(%v, %s))
125                 } UNION {
126                     ?thing bf:title %v FILTER(contains(%v, %s))
127                 }
128             </index>
129
130             <!-- Author indexes. Much simpler than titles. -->
131             <index type="bf.creator">
132                 ?thing bf:creator ?c .
133                 ?c bf:label %v FILTER(contains(%v, %s))
134             </index>
135
136             <index type="bf.contributor">
137                 ?thing bf:contributor ?c .
138                 ?c bf:label %v FILTER(contains(%v, %s))
139             </index>
140
141             <index type="bf.anyauthor"> <!-- TODO - Is this a good name? -->
142                 {
143                     ?thing bf:creator ?c .
144                     ?c bf:label %v FILTER(contains(%v, %s))
145                 } UNION {
146                     ?thing bf:contributor ?c .
147                     ?c bf:label %v FILTER(contains(%v, %s))
148                 }
149             </index>
150
151             <!-- Subjects -->
152             <!-- Note that these refer to anything with a bf:subject relation -->
153             <!-- The actual item is likely to be something like topic person etc -->
154             <index type="bf.subject">
155                 ?thing bf:subject ?subject .
156                 ?subject bf:label %v FILTER(contains(%v, %s))
157             </index>
158
159
160             <!-- Present formats -->
161             <!-- BF-L comes from the "thing" template -->
162             <!-- BF-F expands all links, except to instances and other works -->
163             <present type="BF-F">
164                 CONSTRUCT {
165                     ?thing ?rel ?obj .
166                     ?obj ?rel1 ?obj1 .
167                     ?obj1 ?rel2 ?obj2 .
168                     ?obj2 ?rel3 ?obj3
169                 }
170                 WHERE {
171
172                     ?thing a bf:Work .
173                     ?thing ?rel ?obj .
174                     OPTIONAL {
175                         ?obj ?rel1 ?obj1
176                         MINUS { ?obj a bf:Work }
177                         MINUS { ?obj a bf:Instance }
178                     }
179                     OPTIONAL {
180                         ?obj1 ?rel2 ?obj2
181                         MINUS { ?obj1 a bf:Work }
182                         MINUS { ?obj1 a bf:Instance }
183                     }
184                     OPTIONAL {
185                         ?obj2 ?rel3 ?obj3
186                         MINUS { ?obj2 a bf:Work }
187                         MINUS { ?obj2 a bf:Instance }
188                     }
189                     ?thing ?rel ?obj FILTER( str(?thing) = %s )
190                     <!-- TODO Use the %u -->
191                     <!-- TODO Use the BF-FI as the BF-F -->
192                 }
193             </present>
194
195             <!-- full, with instances. Experimental! -->
196             <present type="BF-FI">
197                 CONSTRUCT {
198                     %u ?rel ?wobj1 .
199                     ?wobj1 ?wrel1 ?wobj2 .
200                     ?wobj2 ?wrel2 ?wobj3 .
201                     ?inst ?irel1 ?iobj1 .
202                     ?iobj1 ?irel2 ?iobj2 .
203                     ?iobj2 ?irel3 ?iobj3
204                 }
205                 WHERE {
206                     %u a bf:Work .
207                     %u ?rel ?wobj1 .
208
209                     OPTIONAL {
210                         ?wobj ?wrel1 ?wobj1
211                         MINUS { ?wobj a bf:Work }
212                         MINUS { ?wobj a bf:Instance }
213                     }
214                     OPTIONAL {
215                         ?wobj1 ?wrel2 ?wobj2
216                         MINUS { ?wobj1 a bf:Work }
217                         MINUS { ?wobj1 a bf:Instance }
218                     }
219                     OPTIONAL {
220                         ?wobj2 ?wrel3 ?wobj3
221                         MINUS { ?wobj2 a bf:Work }
222                         MINUS { ?wobj2 a bf:Instance }
223                     }
224
225                     <!-- Link to the instance(s) -->
226                     OPTIONAL {
227                         ?inst bf:instanceOf %u
228                     }
229                     <!-- and expand the instance -->
230                     OPTIONAL {
231                         ?inst ?irel1 ?iobj1
232                     }
233                     OPTIONAL {
234                         ?iobj1 ?irel2 ?iobj2
235                     }
236                     OPTIONAL {
237                         ?iobj2 ?irel3 ?iobj3
238                     }
239                 }
240             </present>
241         </db>
242
243         <!-- Instance database -->
244
245         <db path="instance" schema="sparql-results" include="thing">
246             <criteria>?thing a bf:Instance</criteria>
247
248             <!-- Title indexes -->
249             <!-- These are messy, there are so many ways to get to a title -->
250
251             <!-- Main title. Looks logical. Many instances seem to have a title -->
252             <index type="bf.title">
253                 ?thing bf:title %v FILTER(contains(%v, %s))
254             </index>
255
256             <!-- instancetitle is also pretty common -->
257             <index type="bf.instancetitle">
258                 ?thing bf:instanceTitle ?it .
259                 ?it bf:titleValue %v FILTER(contains(%v, %s))
260             </index>
261
262             <index type="bf.titlestatement">
263                 ?thing bf:titleStatement %v FILTER(contains(%v, %s))
264             </index>
265
266             <!-- Combining the two above, since users are not likely to know how
267             a given title has been indexed -->
268             <index type="bf.maintitle">
269                 {
270                     ?thing bf:instanceTitle ?it .
271                     ?it bf:titleValue %v FILTER(contains(%v, %s))
272                 } UNION {
273                     ?thing bf:title %v FILTER(contains(%v, %s))
274                 }
275             </index>
276
277
278             <!-- the instancetitle can also contain a subtitle and a parttitle -->
279             <index type="bf.subtitle">
280                 ?thing bf:instanceTitle ?it .
281                 ?it bf:subtitle %v FILTER(contains(%v, %s))
282             </index>
283
284             <index type="bf.parttitle">
285                 ?thing bf:instanceTitle ?it .
286                 ?it bf:partTitle %v FILTER(contains(%v, %s))
287             </index>
288             <!-- We could also go to the works, and get those titles... -->
289
290             <!-- Combining any kind of title into one index -->
291             <index type="bf.anytitle">
292                 {
293                     ?thing bf:title %v FILTER(contains(%v, %s))
294                 } UNION {
295                     ?thing bf:titleStatement %v FILTER(contains(%v, %s))
296                 } UNION {
297                     ?thing ?titlerel ?it . <!-- any kind of link -->
298                     ?it a bf:Title <!-- to something that is a title -->
299                     {
300                         ?it bf:titleValue %v FILTER(contains(%v, %s))
301                     } UNION {
302                         ?it bf:partTitle %v FILTER(contains(%v, %s))
303                     } UNION {
304                         ?it bf:subtitle %v FILTER(contains(%v, %s))
305                     }
306                 }
307             </index>
308
309             <!-- Author indexes. Many instances don't have any, works do -->
310             <index type="bf.creator">
311                 ?thing bf:creator ?c .
312                 ?c bf:label %v FILTER(contains(%v, %s))
313             </index>
314
315             <index type="bf.workcreator">
316                 ?thing bf:instanceOf ?work .
317                 ?work bf:creator ?c .
318                 ?c bf:label %v FILTER(contains(%v, %s))
319             </index>
320
321             <index type="bf.workcontributor">
322                 ?thing bf:instanceOf ?work .
323                 ?work bf:contributor ?c .
324                 ?c bf:label %v FILTER(contains(%v, %s))
325             </index>
326
327             <index type="bf.contributor">
328                 ?thing bf:contributor ?c .
329                 ?c bf:label %v FILTER(contains(%v, %s))
330             </index>
331
332             <index type="bf.anyauthor">
333                 {
334                     ?thing bf:creator ?c .
335                     ?c bf:label %v FILTER(contains(%v, %s))
336                 } UNION {
337                     ?thing bf:contributor ?c .
338                     ?c bf:label %v FILTER(contains(%v, %s))
339                 } UNION {
340                     ?thing bf:instanceOf ?work .
341                     ?work bf:creator ?c .
342                     ?c bf:label %v FILTER(contains(%v, %s))
343                 } UNION {
344                     ?thing bf:instanceOf ?work .
345                     ?work bf:contributor ?c .
346                     ?c bf:label %v FILTER(contains(%v, %s))
347                 }
348             </index>
349
350             <!-- Presetn formats. BF-L comes from "thing" -->
351             <!-- Full instance, with the related work too -->
352             <present type="BF-F">
353                 CONSTRUCT {
354                     %u ?irel1 ?iobj1 .
355                     ?iobj1 ?irel2 ?iobj2 .
356                     ?iobj2 ?irel3 ?iobj3 .
357                     ?work ?wrel1 ?wobj1 .
358                     ?wobj1 ?wrel2 ?wobj2 .
359                     ?wobj2 ?wrel3 ?wobj3
360                 }
361                 WHERE {
362                     %u a bf:Instance .
363                     %u ?irel1 ?iobj1
364                     OPTIONAL {
365                         ?iobj1 ?irel2 ?iobj2
366                         MINUS { ?iobj1 a bf:Work }
367                         MINUS { ?iobj1 a bf:Instance }
368                         OPTIONAL {
369                             ?iobj2 ?irel3 ?iobj3
370                             MINUS { ?iobj2 a bf:Work }
371                             MINUS { ?iobj2 a bf:Instance }
372                         }
373                     }
374
375                     OPTIONAL {
376                         %u bf:instanceOf ?work
377                         OPTIONAL {
378                             ?work ?wrel1 ?wobj1
379                             MINUS { ?wobj1 a bf:Work }
380                             MINUS { ?wobj1 a bf:Instance }
381                             OPTIONAL {
382                                 ?wobj1 ?wrel2 ?wobj2
383                                 MINUS { ?wobj2 a bf:Work }
384                                 MINUS { ?wobj2 a bf:Instance }
385                                 OPTIONAL {
386                                     ?wobj2 ?wrel3 ?wobj3
387                                     MINUS { ?wobj3 a bf:Work }
388                                     MINUS { ?wobj3 a bf:Instance }
389                                 }
390                             }
391                         }
392                     }
393                 }
394             </present>
395
396         </db>
397
398         <!-- Small databases -->
399
400         <!-- "small" contains all the things common to all small databases -->
401         <!-- It is only to be used as an include, it is not searchable, since -->
402         <!-- it has no schema atribute -->
403         <!-- It is divided into "smallbody", and a "small" that includes -->
404         <!-- the general indexes, so that title searches can include the body, -->
405         <!-- but have different "any" indexes -->
406
407         <db path="smallbody" include="thing">
408             <present type="BF-F">
409                 <!-- I don't think we need more than one level -->
410                 <!--for these simple databases -->
411                 CONSTRUCT {
412                     %u ?rel ?obj .
413                     ?obj ?rel1 ?obj1 .
414                 }
415                 WHERE {
416                     %u ?rel ?obj .
417                     OPTIONAL { ?obj ?rel1 ?obj1 }
418                 }
419             </present>
420         </db>
421
422         <!-- The combined "small" database defaults -->
423         <db path="small" include="smallbody">
424             <index type="any">
425                 ?thing bf:label %v FILTER(contains(%v, %s))
426             </index>
427             <index type="1016">
428                 ?thing bf:label %v FILTER(contains(%v, %s))
429             </index>
430         </db>
431
432         <!-- Various "small" databases, leaning heavily on the defaults above -->
433         <db path="place" schema="sparql-results" include="small" >
434             <criteria>?thing a bf:Place</criteria>
435             <index type="bf.place">
436                 ?thing bf:label %v FILTER(contains(%v, %s))
437             </index>
438         </db>
439
440         <db path="person" schema="sparql-results" include="small" >
441             <criteria>?thing a bf:Person</criteria>
442             <index type="bf.person">
443                 ?thing bf:label %v FILTER(contains(%v, %s))
444             </index>
445         </db>
446
447         <db path="meeting" schema="sparql-results" include="small" >
448             <criteria>?thing a bf:Meeting</criteria>
449             <index type="bf.meeting">
450                 ?thing bf:label %v FILTER(contains(%v, %s))
451             </index>
452         </db>
453
454         <db path="agent" schema="sparql-results" include="small" >
455             <criteria>?thing a bf:Agent</criteria>
456             <index type="bf.agent">
457                 ?thing bf:label %v FILTER(contains(%v, %s))
458             </index>
459         </db>
460
461         <db path="event" schema="sparql-results" include="small" >
462             <criteria>?thing a bf:Event</criteria>
463             <index type="bf.event">
464                 ?thing bf:label %v FILTER(contains(%v, %s))
465             </index>
466         </db>
467
468         <db path="organization" schema="sparql-results" include="small" >
469             <criteria>?thing a bf:Organization</criteria>
470             <index type="bf.organization">
471                 ?thing bf:label %v FILTER(contains(%v, %s))
472             </index>
473         </db>
474
475         <db path="topic" schema="sparql-results" include="small" >
476             <criteria>?thing a bf:Topic</criteria>
477             <index type="bf.topic">
478                 ?thing bf:label %v FILTER(contains(%v, %s))
479             </index>
480         </db>
481
482         <!-- Title search, for seatching Title objects. -->
483         <!-- Not sure if this is needed, but it is a nice example -->
484         <db path="title" schema="sparql-results" include="smallbody" >
485             <criteria>?thing a bf:Title</criteria>
486
487             <index type="any">
488                 {
489                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
490                 } UNION {
491                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
492                 } UNION {
493                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
494                 }
495             </index>
496
497             <index type="1016">
498                 {
499                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
500                 } UNION {
501                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
502                 } UNION {
503                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
504                 }
505             </index>
506
507             <index type="bf.title">
508                 ?thing bf:titleValue %v FILTER(contains(%v, %s))
509             </index>
510
511             <index type="bf.subtitle">
512                 ?thing bf:subtitle %v FILTER(contains(%v, %s))
513             </index>
514
515             <index type="bf.parttitle">
516                 ?thing bf:partTitle %v FILTER(contains(%v, %s))
517             </index>
518         </db>
519
520         <!-- A hack to be able to look at any triplet in the base -->
521         <!-- TODO - Switch to the new system, probably using "small" -->
522         <db path="node" schema="sparql-results">
523             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
524             <prefix>bf: http://bibframe.org/vocab/</prefix>
525             <form>SELECT ?node ?rel ?obj</form>
526             <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
527         </db>
528         <!-- A way to see which triplets refers to a given uri. -->
529         <!-- TODO - Switch to the new system, probably using "small" -->
530         <db path="ref" schema="sparql-results">
531             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
532             <prefix>bf: http://bibframe.org/vocab/</prefix>
533             <form>SELECT ?node ?rel ?obj</form>
534             <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
535         </db>
536     </filter>
537
538     <filter type="log">
539         <message>http</message>
540         <category apdu="true"/>
541     </filter>
542
543     <filter type="http_client">
544         <x-forwarded-for>true</x-forwarded-for>
545     </filter>
546 </filters>