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