Towards LOC-6: Title indexes for works
[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     <!-- Any search in work returns just a list of records.
44          Present will make another request for each record to get the level
45          of details we want, depending on the schema.  -->
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       <form>SELECT DISTINCT ?work </form>
50       <criteria>?work a bf:Work</criteria>
51
52       <!-- bf.uri is a simple way to get to a work -->
53       <index type="bf.uri"> ?work a bf:Work FILTER( ?work  = %u ) </index>
54
55       <!-- Title indexes, directly via work.workTitle -->
56       <index type="bf.title">
57           ?work bf:workTitle ?wt .
58           ?wt bf:titleValue %v FILTER(contains(%v, %s))
59       </index>
60
61       <index type="bf.subtitle">?work bf:workTitle ?wt .
62           ?wt bf:subtitle %v FILTER(contains(%v, %s))
63       </index>
64
65       <index type="bf.parttitle">
66           ?work bf:workTitle ?wt .
67           ?wt bf:partTitle %v FILTER(contains(%v, %s))
68       </index>
69
70       <!-- work.titlevariation - this could also have sub- and partTitles -->
71       <index type="bf.titlevariation">
72           ?work bf:titleVariation ?tv .
73           ?tv bf:titleValue %v FILTER(contains(%v, %s))
74       </index>
75
76       <!-- Instance titles -->
77       <index type="bf.instancetitle">
78           ?inst bf:instanceOf ?work .
79           ?inst bf:instanceTitle ?it .
80           ?it bf:titleValue %v FILTER(contains(%v, %s))
81       </index>
82
83       <!-- Combined title index. There are so many ways titles can be expresses
84       in Bibframe, this seems to cover most of what we have seen -->
85       <index type="bf.anytitle">
86           { ?work bf:workTitle ?wt .
87               { ?wt bf:titleValue %v FILTER(contains(%v, %s)) } UNION
88               { ?wt bf:subtitle %v FILTER(contains(%v, %s)) } UNION
89               { ?wt bf:partTitle %v FILTER(contains(%v, %s)) }
90           } UNION {
91               ?work bf:titleVariation ?tv .
92               ?tv bf:titleValue %v FILTER(contains(%v, %s)) 
93           } UNION {
94               ?inst bf:instanceOf ?work .
95               ?inst bf:instanceTitle ?it .
96               ?it bf:titleValue %v FILTER(contains(%v, %s))
97           }
98       </index>
99
100       <index type="bf.creator">?work bf:creator ?c .
101           ?c bf:label %v FILTER(contains(%v, %s))</index>
102       <index type="bf.subject">?work bf:subject ?subject .
103           ?subject bf:label %v FILTER(contains(%v, %s))
104       </index>
105       
106       <present type="BF-L">
107         CONSTRUCT { ?work ?rel ?subj }
108          WHERE {
109          ?work a bf:Work .
110          ?work ?rel ?subj .
111          ?work ?rel ?obj FILTER( str(?work) = %s )
112         }
113       </present>
114       <present type="BF-F">
115         CONSTRUCT { ?work ?rel ?obj .
116                     ?obj ?rel1 ?obj1 .
117                     ?obj1 ?rel2 ?obj2 .
118                     ?obj2 ?rel3 ?obj3 }
119          WHERE {
120          ?work a bf:Work .
121          ?work ?rel ?obj .
122         OPTIONAL { 
123           ?obj ?rel1 ?obj1  
124             MINUS { ?obj a bf:Work } 
125           }
126         OPTIONAL {
127           ?obj1 ?rel2 ?obj2 
128             MINUS { ?obj1 a bf:Work } 
129           } 
130         OPTIONAL { 
131           ?obj2 ?rel3 ?obj3 
132             MINUS { ?obj2 a bf:Work } 
133           }
134          ?work ?rel ?obj FILTER( str(?work) = %s )
135         }
136       </present>
137       <present type="BF-FI">  <!-- full, with instances. Experimental! -->
138         CONSTRUCT { %u ?rel ?wobj1 .
139                     ?wobj1 ?wrel1 ?wobj2 .
140                     ?wobj2 ?wrel2 ?wobj3 .
141                     ?inst ?irel1 ?iobj1 .
142                     ?iobj1 ?irel2 ?iobj2 .
143                     ?iobj2 ?irel3 ?iobj3 }
144          WHERE {
145           %u a bf:Work .
146           %u ?rel ?wobj1 .
147           OPTIONAL { <!-- note, this is not in the final construct
148           the linking triplet will get included like any others -->
149             ?inst bf:instanceOf %u
150           } 
151           &workfull; <!-- This does not seem to get expanded!! -->
152           OPTIONAL {
153               ?wobj ?wrel1 ?wobj1
154               MINUS { ?wobj a bf:Work }
155               MINUS { ?wobj a bf:Instance }
156           }
157           OPTIONAL {
158               ?wobj1 ?wrel2 ?wobj2
159               MINUS { ?wobj1 a bf:Work }
160               MINUS { ?wobj1 a bf:Instance }
161           }
162           OPTIONAL {
163               ?wobj2 ?wrel3 ?wobj3
164               MINUS { ?wobj2 a bf:Work }
165               MINUS { ?wobj2 a bf:Instance }
166           }
167           <!--&instfull; -->
168           OPTIONAL {
169             ?inst ?irel1 ?iobj1
170           }
171           OPTIONAL {
172             ?iobj1 ?irel2 ?iobj2
173           }
174           OPTIONAL {
175             ?iobj2 ?irel3 ?iobj3
176           }
177
178         }
179       </present>
180     </db>
181     <!-- Instance searches, need to be refined later. TODO -->
182     <db path="instance" schema="sparql-results">
183       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
184       <prefix>bf: http://bibframe.org/vocab/</prefix>
185       <form>SELECT ?instance ?title ?format</form>
186       <criteria>?instance a bf:Instance</criteria>
187       <criteria>?instance bf:title ?title</criteria>
188       <index type="4">?instance bf:title %v FILTER(contains(%v, %s))</index>
189       <criteria>?instance bf:format ?format</criteria>
190       <index type="1013">?instance bf:format %s</index>
191     </db>
192
193     <!-- Small databases -->
194    
195     <!-- "small" contains all the things common to all small databases -->
196     <!-- It is only to be used as an include, it is not searchable, since -->
197     <!-- it has no schema atribute -->
198     <!-- It is divided into "smallindex", "smallbody", and a "small" that includes
199     both, so that title searches can include the body, but have different indexes -->
200     
201     <db path="smallindex">
202       <index type="any">?thing bf:label %v FILTER(contains(%v, %s))</index>
203       <index type="1016">?thing bf:label %v FILTER(contains(%v, %s))</index>
204     </db>
205
206     <db path="smallbody">
207       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
208       <prefix>bf: http://bibframe.org/vocab/</prefix>
209       <form>SELECT DISTINCT ?thing </form>
210       <criteria>?thing ?rel ?obj</criteria>
211       <present type="BF-L">
212         CONSTRUCT { %u ?rel ?obj }
213          WHERE {
214            %u ?rel ?obj .
215          }
216       </present>
217       <!-- Experimental, to get just the URIs out, in proper rdf. Probably not useful 
218       <uri type="BF-U">
219         CONSTRUCT { %u bf:uri %u }
220          WHERE {
221            %u bf:label ?lbl .
222          }
223       </uri>
224       -->
225       <present type="BF-F">
226           <!-- I don't think we need more than one level for these simple 
227           databases -->
228         CONSTRUCT { %u ?rel ?obj . 
229                     ?obj ?rel1 ?obj1 .
230                   }
231          WHERE {
232            %u ?rel ?obj .
233            OPTIONAL { ?obj ?rel1 ?obj1 }
234          }
235       </present>
236     </db>
237     <db path="small" include="smallindex smallbody"/>
238     
239     <db path="place" schema="sparql-results" include="small" >
240       <criteria>?thing a bf:Place</criteria>
241       <index type="bf.place">?thing bf:label %v FILTER(contains(%v, %s))</index>
242     </db>
243     <db path="person" schema="sparql-results" include="small" >
244       <criteria>?thing a bf:Person</criteria>
245       <index type="bf.person">?thing bf:label %v FILTER(contains(%v, %s))</index>
246     </db>
247     <db path="meeting" schema="sparql-results" include="small" >
248       <criteria>?thing a bf:Meeting</criteria>
249       <index type="bf.meeting">?thing bf:label %v FILTER(contains(%v, %s))</index>
250     </db>
251     <db path="agent" schema="sparql-results" include="small" >
252       <criteria>?thing a bf:Agent</criteria>
253       <index type="bf.agent">?thing bf:label %v FILTER(contains(%v, %s))</index>
254     </db>
255     <db path="event" schema="sparql-results" include="small" >
256       <criteria>?thing a bf:Event</criteria>
257       <index type="bf.event">?thing bf:label %v FILTER(contains(%v, %s))</index>
258     </db>
259     <db path="organization" schema="sparql-results" include="small" >
260       <criteria>?thing a bf:Organization</criteria>
261       <index type="bf.organization">?thing bf:label %v FILTER(contains(%v, %s))</index>
262     </db>
263     <db path="topic" schema="sparql-results" include="small" >
264       <criteria>?thing a bf:Topic</criteria>
265       <index type="bf.topic">?thing bf:label %v FILTER(contains(%v, %s))</index>
266     </db>
267
268     <!-- Title search, probably not needed. -->
269     <db path="title" schema="sparql-results" include="smallbody" >
270       <criteria>?thing a bf:Title</criteria>
271       <index type="any">
272            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
273            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
274            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
275       </index>
276       <index type="1016">
277            { ?thing bf:titleValue %v FILTER(contains(%v, %s)) } UNION
278            { ?thing bf:subtitle %v FILTER(contains(%v, %s)) } UNION
279            { ?thing bf:partTitle %v FILTER(contains(%v, %s)) } 
280       </index>
281       <index type="bf.title">?thing bf:titleValue %v FILTER(contains(%v, %s))</index>
282       <index type="bf.subtitle">?thing bf:subtitle %v FILTER(contains(%v, %s))</index>
283       <index type="bf.parttitle">?thing bf:partTitle %v FILTER(contains(%v, %s))</index>
284     </db>
285
286     <!-- A hack to be able to look at any triplet in the base -->
287     <!-- TODO - Switch to the new system, probably using "small" -->
288     <db path="node" schema="sparql-results">
289       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
290       <prefix>bf: http://bibframe.org/vocab/</prefix>
291       <form>SELECT ?node ?rel ?obj</form>
292       <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
293     </db>
294     <!-- A way to see which triplets refers to a given uri. -->
295     <!-- TODO - Switch to the new system, probably using "small" -->
296     <db path="ref" schema="sparql-results">
297       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
298       <prefix>bf: http://bibframe.org/vocab/</prefix>
299       <form>SELECT ?node ?rel ?obj</form>
300       <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
301     </db>
302   </filter>
303   <filter type="log">
304     <message>http</message>
305     <category apdu="true"/>
306   </filter>
307   <filter type="http_client">
308     <x-forwarded-for>true</x-forwarded-for>
309   </filter>
310 </filters>