LOC-6: isbn index: Check we have a literal before substring
[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             <!-- isbn index. The Instance may contain a isbn10 or isbn13. -->
325             <!-- These can be literal values like -->
326             <!--   http://isbn.example.org/1906833214 which we need to search -->
327             <!-- by our usual substring match. Or they can be links to Identivfiers -->
328             <!-- which will have a proper identifierValue on which we can do -->
329             <!-- an exact match.  -->
330             <index type="bf.isbn">
331                 {
332                     ?thing bf:isbn10  %v
333                         FILTER(isLiteral(%v) &amp;&amp; contains(%v, %s))
334                 } UNION {
335                     ?thing bf:isbn13  %v
336                         FILTER(isLiteral(%v) &amp;&amp; contains(%v, %s))
337                 } UNION {
338                     {
339                         ?thing bf:isbn10 ?isbn
340                     } UNION {
341                         ?thing bf:isbn13 ?isbn
342                     }
343                     ?isbn a bf:Identifier  .
344                     ?isbn bf:identifierValue  %v FILTER( %v = %s )
345                 }
346             </index>
347
348
349             <!-- Present formats. BF-L comes from "thing" -->
350             <!-- Full instance, with the related work too -->
351             <present type="BF-V">
352                 CONSTRUCT {
353                     %u ?irel1 ?iobj1 .
354                     ?iobj1 ?irel2 ?iobj2 .
355                     ?iobj2 ?irel3 ?iobj3 .
356                     ?work ?wrel1 ?wobj1 .
357                     ?wobj1 ?wrel2 ?wobj2 .
358                     ?wobj2 ?wrel3 ?wobj3
359                 }
360                 WHERE {
361                     %u a bf:Instance .
362                     %u ?irel1 ?iobj1 .
363                     OPTIONAL {
364                         ?iobj1 ?irel2 ?iobj2
365                             MINUS { ?iobj2 a bf:Work }
366                             MINUS { ?iobj2 a bf:Instance } .
367                         OPTIONAL {
368                             ?iobj2 ?irel3 ?iobj3
369                                 MINUS { ?iobj3 a bf:Work }
370                                 MINUS { ?iobj3 a bf:Instance }
371                         }
372                     }
373                     OPTIONAL { <!-- Work -->
374                         %u bf:instanceOf ?work .
375                         ?work ?wrel1 ?wobj1 .
376                         OPTIONAL {
377                             ?wobj1 ?wrel2 ?wobj2
378                                 MINUS { ?wobj1 a bf:Work }
379                                 MINUS { ?wobj1 a bf:Instance } .
380                             OPTIONAL {
381                                 ?wobj2 ?wrel3 ?wobj3
382                                     MINUS { ?wobj2 a bf:Work }
383                                     MINUS { ?wobj2 a bf:Instance }
384                             }
385                         }
386                     }
387                 }
388             </present>
389
390         </db>
391
392         <!-- Small databases -->
393
394         <!-- "small" contains all the things common to all small databases -->
395         <!-- It is only to be used as an include, it is not searchable, since -->
396         <!-- it has no schema atribute -->
397         <!-- It is divided into "smallbody", and a "small" that includes -->
398         <!-- the general indexes, so that title searches can include the body, -->
399         <!-- but have different "any" indexes -->
400
401         <db path="smallbody" include="thing">
402             <present type="BF-V">
403                 <!-- I don't think we need more than one level -->
404                 <!--for these simple databases -->
405                 CONSTRUCT {
406                     %u ?rel ?obj .
407                     ?obj ?rel1 ?obj1 .
408                 }
409                 WHERE {
410                     %u ?rel ?obj .
411                     OPTIONAL { ?obj ?rel1 ?obj1 }
412                 }
413             </present>
414         </db>
415
416         <!-- The combined "small" database defaults -->
417         <db path="small" include="smallbody">
418             <index type="any">
419                 ?thing bf:label %v FILTER(contains(%v, %s))
420             </index>
421             <index type="1016">
422                 ?thing bf:label %v FILTER(contains(%v, %s))
423             </index>
424         </db>
425
426         <!-- Various "small" databases, leaning heavily on the defaults above -->
427         <db path="place" schema="sparql-results" include="small" >
428             <criteria>?thing a bf:Place</criteria>
429             <index type="bf.place">
430                 ?thing bf:label %v FILTER(contains(%v, %s))
431             </index>
432         </db>
433
434         <db path="person" schema="sparql-results" include="small" >
435             <criteria>?thing a bf:Person</criteria>
436             <index type="bf.person">
437                 ?thing bf:label %v FILTER(contains(%v, %s))
438             </index>
439         </db>
440
441         <db path="meeting" schema="sparql-results" include="small" >
442             <criteria>?thing a bf:Meeting</criteria>
443             <index type="bf.meeting">
444                 ?thing bf:label %v FILTER(contains(%v, %s))
445             </index>
446         </db>
447
448         <db path="agent" schema="sparql-results" include="small" >
449             <criteria>?thing a bf:Agent</criteria>
450             <index type="bf.agent">
451                 ?thing bf:label %v FILTER(contains(%v, %s))
452             </index>
453         </db>
454
455         <db path="event" schema="sparql-results" include="small" >
456             <criteria>?thing a bf:Event</criteria>
457             <index type="bf.event">
458                 ?thing bf:label %v FILTER(contains(%v, %s))
459             </index>
460         </db>
461
462         <db path="organization" schema="sparql-results" include="small" >
463             <criteria>?thing a bf:Organization</criteria>
464             <index type="bf.organization">
465                 ?thing bf:label %v FILTER(contains(%v, %s))
466             </index>
467         </db>
468
469         <db path="topic" schema="sparql-results" include="small" >
470             <criteria>?thing a bf:Topic</criteria>
471             <index type="bf.topic">
472                 ?thing bf:label %v FILTER(contains(%v, %s))
473             </index>
474         </db>
475
476         <!-- Title search, for seatching Title objects. -->
477         <!-- Not sure if this is needed, but it is a nice example -->
478         <db path="title" schema="sparql-results" include="smallbody" >
479             <criteria>?thing a bf:Title</criteria>
480
481             <index type="any">
482                 {
483                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
484                 } UNION {
485                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
486                 } UNION {
487                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
488                 }
489             </index>
490
491             <index type="1016">
492                 {
493                     ?thing bf:titleValue %v FILTER(contains(%v, %s))
494                 } UNION {
495                     ?thing bf:subtitle %v FILTER(contains(%v, %s))
496                 } UNION {
497                     ?thing bf:partTitle %v FILTER(contains(%v, %s))
498                 }
499             </index>
500
501             <index type="bf.title">
502                 ?thing bf:titleValue %v FILTER(contains(%v, %s))
503             </index>
504
505             <index type="bf.subtitle">
506                 ?thing bf:subtitle %v FILTER(contains(%v, %s))
507             </index>
508
509             <index type="bf.parttitle">
510                 ?thing bf:partTitle %v FILTER(contains(%v, %s))
511             </index>
512         </db>
513
514         <!-- A hack to be able to look at any triplet in the base -->
515         <!-- TODO - Switch to the new system, probably using "small" -->
516         <db path="node" schema="sparql-results">
517             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
518             <prefix>bf: http://bibframe.org/vocab/</prefix>
519             <form>SELECT ?node ?rel ?obj</form>
520             <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
521         </db>
522         <!-- A way to see which triplets refers to a given uri. -->
523         <!-- TODO - Switch to the new system, probably using "small" -->
524         <db path="ref" schema="sparql-results">
525             <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
526             <prefix>bf: http://bibframe.org/vocab/</prefix>
527             <form>SELECT ?node ?rel ?obj</form>
528             <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
529         </db>
530     </filter>
531
532     <filter type="log">
533         <message>http</message>
534         <category apdu="true"/>
535     </filter>
536
537     <filter type="http_client">
538         <x-forwarded-for>true</x-forwarded-for>
539     </filter>
540 </filters>