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