f59629e5df1fd2738011db435818d8eb196289c7
[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 ?titlerel ?ti . <!-- any kind of link -->
120                     ?ti a bf:Title <!-- to something that is a title -->
121                     {
122                         ?ti bf:titleValue %v FILTER(contains(%v, %s))
123                     } UNION {
124                         ?ti bf:partTitle %v FILTER(contains(%v, %s))
125                     } UNION {
126                         ?ti bf:subtitle %v FILTER(contains(%v, %s))
127                     }
128                 } UNION {
129                     ?inst bf:instanceOf ?thing .
130                     ?inst bf:instanceTitle ?it .
131                     ?it bf:titleValue %v FILTER(contains(%v, %s))
132                 } UNION {
133                     ?thing bf:title %v FILTER(contains(%v, %s))
134                 }
135             </index>
136
137             <!-- Author indexes. Much simpler than titles. -->
138             <index type="bf.creator">
139                 ?thing bf:creator ?c .
140                 ?c bf:label %v FILTER(contains(%v, %s))
141             </index>
142
143             <index type="bf.contributor">
144                 ?thing bf:contributor ?c .
145                 ?c bf:label %v FILTER(contains(%v, %s))
146             </index>
147
148             <index type="bf.anyauthor"> <!-- TODO - Is this a good name? -->
149                 {
150                     ?thing bf:creator ?c .
151                     ?c bf:label %v FILTER(contains(%v, %s))
152                 } UNION {
153                     ?thing bf:contributor ?c .
154                     ?c bf:label %v FILTER(contains(%v, %s))
155                 }
156             </index>
157
158             <!-- Subjects -->
159             <!-- Note that these refer to anything with a bf:subject relation -->
160             <!-- The actual item is likely to be something like topic person etc -->
161             <index type="bf.subject">
162                 ?thing bf:subject ?subject .
163                 ?subject bf:label %v FILTER(contains(%v, %s))
164             </index>
165
166
167             <!-- Present formats -->
168             <!-- BF-L comes from the "thing" template -->
169             <!-- BF-F expands all links, even to instances but not other works -->
170             <present type="BF-F">
171                 CONSTRUCT {
172                     %u ?rel ?wobj1 .
173                     ?wobj1 ?wrel1 ?wobj2 .
174                     ?wobj2 ?wrel2 ?wobj3 .
175                     ?inst ?irel1 ?iobj1 .
176                     ?iobj1 ?irel2 ?iobj2 .
177                     ?iobj2 ?irel3 ?iobj3
178                 }
179                 WHERE {
180                     %u a bf:Work .
181                     %u ?rel ?wobj1 .
182
183                     OPTIONAL {
184                         ?wobj ?wrel1 ?wobj1
185                         MINUS { ?wobj a bf:Work }
186                         MINUS { ?wobj a bf:Instance }
187                         OPTIONAL {
188                             ?wobj1 ?wrel2 ?wobj2
189                             MINUS { ?wobj1 a bf:Work }
190                             MINUS { ?wobj1 a bf:Instance }
191                             OPTIONAL {
192                                 ?wobj2 ?wrel3 ?wobj3
193                                 MINUS { ?wobj2 a bf:Work }
194                                 MINUS { ?wobj2 a bf:Instance }
195                             }
196                         }
197                     }
198                     <!-- Link to the instance(s) -->
199                     OPTIONAL {
200                         ?inst bf:instanceOf %u
201                         OPTIONAL { <!-- and expand the instance -->
202                             ?inst ?irel1 ?iobj1
203                             OPTIONAL {
204                                 ?iobj1 ?irel2 ?iobj2
205                                 OPTIONAL {
206                                     ?iobj2 ?irel3 ?iobj3
207                                 }
208                             }
209                         }
210                     }
211                 }
212             </present>
213         </db>
214
215         <!-- Instance database -->
216
217         <db path="instance" schema="sparql-results" include="thing smallindex">
218             <criteria>?thing a bf:Instance</criteria>
219
220             <!-- Title indexes -->
221             <!-- These are messy, there are so many ways to get to a title -->
222
223             <!-- Main title. Looks logical. Many instances seem to have a title -->
224             <index type="bf.title">
225                 ?thing bf:title %v FILTER(contains(%v, %s))
226             </index>
227
228             <!-- instancetitle is also pretty common -->
229             <index type="bf.instancetitle">
230                 ?thing bf:instanceTitle ?it .
231                 ?it bf:titleValue %v FILTER(contains(%v, %s))
232             </index>
233
234             <index type="bf.titlestatement">
235                 ?thing bf:titleStatement %v FILTER(contains(%v, %s))
236             </index>
237
238             <!-- Combining the two above, since users are not likely to know how
239             a given title has been indexed -->
240             <index type="bf.maintitle">
241                 {
242                     ?thing bf:instanceTitle ?it .
243                     ?it bf:titleValue %v FILTER(contains(%v, %s))
244                 } UNION {
245                     ?thing bf:title %v FILTER(contains(%v, %s))
246                 }
247             </index>
248
249
250             <!-- the instancetitle can also contain a subtitle and a parttitle -->
251             <index type="bf.subtitle">
252                 ?thing bf:instanceTitle ?it .
253                 ?it bf:subtitle %v FILTER(contains(%v, %s))
254             </index>
255
256             <index type="bf.parttitle">
257                 ?thing bf:instanceTitle ?it .
258                 ?it bf:partTitle %v FILTER(contains(%v, %s))
259             </index>
260             <!-- We could also go to the works, and get those titles... -->
261
262             <!-- Combining any kind of title into one index -->
263             <index type="bf.anytitle">
264                 {
265                     ?thing bf:title %v FILTER(contains(%v, %s))
266                 } UNION {
267                     ?thing bf:titleStatement %v FILTER(contains(%v, %s))
268                 } UNION {
269                     ?thing ?titlerel ?it . <!-- any kind of link -->
270                     ?it a bf:Title <!-- to something that is a title -->
271                     {
272                         ?it bf:titleValue %v FILTER(contains(%v, %s))
273                     } UNION {
274                         ?it bf:partTitle %v FILTER(contains(%v, %s))
275                     } UNION {
276                         ?it bf:subtitle %v FILTER(contains(%v, %s))
277                     }
278                 }
279             </index>
280
281             <!-- Author indexes. Many instances don't have any, works do -->
282             <index type="bf.creator">
283                 ?thing bf:creator ?c .
284                 ?c bf:label %v FILTER(contains(%v, %s))
285             </index>
286
287             <index type="bf.workcreator">
288                 ?thing bf:instanceOf ?work .
289                 ?work bf:creator ?c .
290                 ?c bf:label %v FILTER(contains(%v, %s))
291             </index>
292
293             <index type="bf.workcontributor">
294                 ?thing bf:instanceOf ?work .
295                 ?work bf:contributor ?c .
296                 ?c bf:label %v FILTER(contains(%v, %s))
297             </index>
298
299             <index type="bf.contributor">
300                 ?thing bf:contributor ?c .
301                 ?c bf:label %v FILTER(contains(%v, %s))
302             </index>
303
304             <index type="bf.anyauthor">
305                 {
306                     ?thing bf:creator ?c .
307                     ?c bf:label %v FILTER(contains(%v, %s))
308                 } UNION {
309                     ?thing bf:contributor ?c .
310                     ?c bf:label %v FILTER(contains(%v, %s))
311                 } UNION {
312                     ?thing bf:instanceOf ?work .
313                     ?work bf:creator ?c .
314                     ?c bf:label %v FILTER(contains(%v, %s))
315                 } UNION {
316                     ?thing bf:instanceOf ?work .
317                     ?work bf:contributor ?c .
318                     ?c bf:label %v FILTER(contains(%v, %s))
319                 }
320             </index>
321
322             <!-- Presetn formats. BF-L comes from "thing" -->
323             <!-- Full instance, with the related work too -->
324             <present type="BF-F">
325                 CONSTRUCT {
326                     %u ?irel1 ?iobj1 .
327                     ?iobj1 ?irel2 ?iobj2 .
328                     ?iobj2 ?irel3 ?iobj3 .
329                     ?work ?wrel1 ?wobj1 .
330                     ?wobj1 ?wrel2 ?wobj2 .
331                     ?wobj2 ?wrel3 ?wobj3
332                 }
333                 WHERE {
334                     %u a bf:Instance .
335                     %u ?irel1 ?iobj1
336                     OPTIONAL {
337                         ?iobj1 ?irel2 ?iobj2
338                         MINUS { ?iobj1 a bf:Work }
339                         MINUS { ?iobj1 a bf:Instance }
340                         OPTIONAL {
341                             ?iobj2 ?irel3 ?iobj3
342                             MINUS { ?iobj2 a bf:Work }
343                             MINUS { ?iobj2 a bf:Instance }
344                         }
345                     }
346
347                     OPTIONAL {
348                         %u bf:instanceOf ?work
349                         OPTIONAL {
350                             ?work ?wrel1 ?wobj1
351                             MINUS { ?wobj1 a bf:Work }
352                             MINUS { ?wobj1 a bf:Instance }
353                             OPTIONAL {
354                                 ?wobj1 ?wrel2 ?wobj2
355                                 MINUS { ?wobj2 a bf:Work }
356                                 MINUS { ?wobj2 a bf:Instance }
357                                 OPTIONAL {
358                                     ?wobj2 ?wrel3 ?wobj3
359                                     MINUS { ?wobj3 a bf:Work }
360                                     MINUS { ?wobj3 a bf:Instance }
361                                 }
362                             }
363                         }
364                     }
365                 }
366             </present>
367
368         </db>
369
370         <!-- Small databases -->
371
372         <!-- "small" contains all the things common to all small databases -->
373         <!-- It is only to be used as an include, it is not searchable, since -->
374         <!-- it has no schema atribute -->
375         <!-- It is divided into "smallbody", and a "small" that includes -->
376         <!-- the general indexes, so that title searches can include the body, -->
377         <!-- but have different "any" indexes -->
378
379         <db path="smallbody" include="thing">
380             <present type="BF-F">
381                 <!-- I don't think we need more than one level -->
382                 <!--for these simple databases -->
383                 CONSTRUCT {
384                     %u ?rel ?obj .
385                     ?obj ?rel1 ?obj1 .
386                 }
387                 WHERE {
388                     %u ?rel ?obj .
389                     OPTIONAL { ?obj ?rel1 ?obj1 }
390                 }
391             </present>
392         </db>
393
394         <!-- The combined "small" database defaults -->
395         <db path="small" include="smallbody">
396             <index type="any">
397                 ?thing bf:label %v FILTER(contains(%v, %s))
398             </index>
399             <index type="1016">
400                 ?thing bf:label %v FILTER(contains(%v, %s))
401             </index>
402         </db>
403
404         <!-- Various "small" databases, leaning heavily on the defaults above -->
405         <db path="place" schema="sparql-results" include="small" >
406             <criteria>?thing a bf:Place</criteria>
407             <index type="bf.place">
408                 ?thing bf:label %v FILTER(contains(%v, %s))
409             </index>
410         </db>
411
412         <db path="person" schema="sparql-results" include="small" >
413             <criteria>?thing a bf:Person</criteria>
414             <index type="bf.person">
415                 ?thing bf:label %v FILTER(contains(%v, %s))
416             </index>
417         </db>
418
419         <db path="meeting" schema="sparql-results" include="small" >
420             <criteria>?thing a bf:Meeting</criteria>
421             <index type="bf.meeting">
422                 ?thing bf:label %v FILTER(contains(%v, %s))
423             </index>
424         </db>
425
426         <db path="agent" schema="sparql-results" include="small" >
427             <criteria>?thing a bf:Agent</criteria>
428             <index type="bf.agent">
429                 ?thing bf:label %v FILTER(contains(%v, %s))
430             </index>
431         </db>
432
433         <db path="event" schema="sparql-results" include="small" >
434             <criteria>?thing a bf:Event</criteria>
435             <index type="bf.event">
436                 ?thing bf:label %v FILTER(contains(%v, %s))
437             </index>
438         </db>
439
440         <db path="organization" schema="sparql-results" include="small" >
441             <criteria>?thing a bf:Organization</criteria>
442             <index type="bf.organization">
443                 ?thing bf:label %v FILTER(contains(%v, %s))
444             </index>
445         </db>
446
447         <db path="topic" schema="sparql-results" include="small" >
448             <criteria>?thing a bf:Topic</criteria>
449             <index type="bf.topic">
450                 ?thing bf:label %v FILTER(contains(%v, %s))
451             </index>
452         </db>
453
454         <!-- Title search, for seatching Title objects. -->
455         <!-- Not sure if this is needed, but it is a nice example -->
456         <db path="title" schema="sparql-results" include="smallbody" >
457             <criteria>?thing a bf:Title</criteria>
458
459             <index type="any">
460                 {
461                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
462                 } UNION {
463                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
464                 } UNION {
465                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
466                 }
467             </index>
468
469             <index type="1016">
470                 {
471                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
472                 } UNION {
473                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
474                 } UNION {
475                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
476                 }
477             </index>
478
479             <index type="bf.title">
480                 ?thing bf:titleValue %v FILTER(contains(%v, %s))
481             </index>
482
483             <index type="bf.subtitle">
484                 ?thing bf:subtitle %v FILTER(contains(%v, %s))
485             </index>
486
487             <index type="bf.parttitle">
488                 ?thing bf:partTitle %v FILTER(contains(%v, %s))
489             </index>
490         </db>
491
492         <!-- A hack to be able to look at any triplet in the base -->
493         <!-- TODO - Switch to the new system, probably using "small" -->
494         <db path="node" schema="sparql-results">
495             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
496             <prefix>bf: http://bibframe.org/vocab/</prefix>
497             <form>SELECT ?node ?rel ?obj</form>
498             <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
499         </db>
500         <!-- A way to see which triplets refers to a given uri. -->
501         <!-- TODO - Switch to the new system, probably using "small" -->
502         <db path="ref" schema="sparql-results">
503             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
504             <prefix>bf: http://bibframe.org/vocab/</prefix>
505             <form>SELECT ?node ?rel ?obj</form>
506             <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
507         </db>
508     </filter>
509
510     <filter type="log">
511         <message>http</message>
512         <category apdu="true"/>
513     </filter>
514
515     <filter type="http_client">
516         <x-forwarded-for>true</x-forwarded-for>
517     </filter>
518 </filters>