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