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