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