+ ?iobj2 ?irel3 ?iobj3
+ }
+ WHERE {
+ %u a bf:Work .
+ %u ?rel ?wobj1 .
+
+ OPTIONAL {
+ ?wobj ?wrel1 ?wobj1
+ MINUS { ?wobj a bf:Work }
+ MINUS { ?wobj a bf:Instance }
+ }
+ OPTIONAL {
+ ?wobj1 ?wrel2 ?wobj2
+ MINUS { ?wobj1 a bf:Work }
+ MINUS { ?wobj1 a bf:Instance }
+ }
+ OPTIONAL {
+ ?wobj2 ?wrel3 ?wobj3
+ MINUS { ?wobj2 a bf:Work }
+ MINUS { ?wobj2 a bf:Instance }
+ }
+
+ <!-- Link to the instance(s) -->
+ OPTIONAL {
+ ?inst bf:instanceOf %u
+ }
+ <!-- and expand the instance -->
+ OPTIONAL {
+ ?inst ?irel1 ?iobj1
+ }
+ OPTIONAL {
+ ?iobj1 ?irel2 ?iobj2
+ }
+ OPTIONAL {
+ ?iobj2 ?irel3 ?iobj3
+ }
+ }
+ </present>
+ </db>
+
+ <!-- Instance database -->
+
+ <db path="instance" schema="sparql-results">
+ <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
+ <prefix>bf: http://bibframe.org/vocab/</prefix>
+ <!-- The search clause just finds ?insts, present is done below -->
+ <form>SELECT DISTINCT ?inst </form>
+ <criteria>?inst a bf:Instance</criteria>
+
+ <!-- bf.uri is a simple way to get to a work -->
+ <index type="bf.uri">
+ ?inst a bf:Instance FILTER( ?inst = %u )
+ </index>
+
+ <!-- Title indexes -->
+ <!-- These are messy, there are so many ways to get to a title -->
+
+ <!-- Main title. Looks logical. Many instances seem to have a title -->
+ <index type="bf.title">
+ ?inst bf:title %v FILTER(contains(%v, %s))
+ </index>
+
+ <!-- instancetitle is also pretty common -->
+ <index type="bf.instancetitle">
+ ?inst bf:instanceTitle ?it .
+ ?it bf:titleValue %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.titlestatement">
+ ?inst bf:titleStatement %v FILTER(contains(%v, %s))
+ </index>
+
+ <!-- Combining the two above, since users are not likely to know how
+ a given title has been indexed -->
+ <index type="bf.maintitle">
+ {
+ ?inst bf:instanceTitle ?it .
+ ?it bf:titleValue %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst bf:title %v FILTER(contains(%v, %s))
+ }
+ </index>
+
+
+ <!-- the instancetitle can also contain a subtitle and a parttitle -->
+ <index type="bf.subtitle">
+ ?inst bf:instanceTitle ?it .
+ ?it bf:subtitle %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.parttitle">
+ ?inst bf:instanceTitle ?it .
+ ?it bf:partTitle %v FILTER(contains(%v, %s))
+ </index>
+ <!-- We could also go to the works, and get those titles... -->
+
+ <!-- Combining any kind of title into one index -->
+ <index type="bf.anytitle">
+ {
+ ?inst bf:title %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst bf:titleStatement %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst ?titlerel ?it . <!-- any kind of link -->
+ ?it a bf:Title <!-- to something that is a title -->
+ {
+ ?it bf:titleValue %v FILTER(contains(%v, %s))
+ } UNION {
+ ?it bf:partTitle %v FILTER(contains(%v, %s))
+ } UNION {
+ ?it bf:subtitle %v FILTER(contains(%v, %s))
+ }
+ }
+ </index>
+
+ <!-- Author indexes. Many instances don't have any, works do -->
+ <index type="bf.creator">
+ ?inst bf:creator ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.workcreator">
+ ?inst bf:instanceOf ?work .
+ ?work bf:creator ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.workcontributor">
+ ?inst bf:instanceOf ?work .
+ ?work bf:contributor ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.contributor">
+ ?inst bf:contributor ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ </index>
+
+ <index type="bf.anyauthor">
+ {
+ ?inst bf:creator ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst bf:contributor ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst bf:instanceOf ?work .
+ ?work bf:creator ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ } UNION {
+ ?inst bf:instanceOf ?work .
+ ?work bf:contributor ?c .
+ ?c bf:label %v FILTER(contains(%v, %s))
+ }
+ </index>
+
+ <!-- BF-L is just the links -->
+ <present type="BF-L">
+ CONSTRUCT {
+ ?inst ?rel ?subj
+ }
+ WHERE {
+ ?inst a bf:Instance .
+ ?inst ?rel ?subj .
+ ?inst ?rel ?subj FILTER( str(?inst) = %s )
+ }
+ </present>
+
+ <!-- Full instance, with the related work too -->
+ <present type="BF-F">
+ CONSTRUCT {
+ %u ?irel1 ?iobj1 .
+ ?iobj1 ?irel2 ?iobj2 .
+ ?iobj2 ?irel3 ?iobj3 .
+ ?work ?wrel1 ?wobj1 .
+ ?wobj1 ?wrel2 ?wobj2 .
+ ?wobj2 ?wrel3 ?wobj3
+ }
+ WHERE {
+ %u a bf:Instance .
+ %u ?irel1 ?iobj1
+ OPTIONAL {
+ ?iobj1 ?irel2 ?iobj2
+ MINUS { ?iobj1 a bf:Work }
+ MINUS { ?iobj1 a bf:Instance }
+ OPTIONAL {
+ ?iobj2 ?irel3 ?iobj3
+ MINUS { ?iobj2 a bf:Work }
+ MINUS { ?iobj2 a bf:Instance }
+ }
+ }
+
+ OPTIONAL {
+ %u bf:instanceOf ?work
+ OPTIONAL {
+ ?work ?wrel1 ?wobj1
+ MINUS { ?wobj1 a bf:Work }
+ MINUS { ?wobj1 a bf:Instance }
+ OPTIONAL {
+ ?wobj1 ?wrel2 ?wobj2
+ MINUS { ?wobj2 a bf:Work }
+ MINUS { ?wobj2 a bf:Instance }
+ OPTIONAL {
+ ?wobj2 ?wrel3 ?wobj3
+ MINUS { ?wobj3 a bf:Work }
+ MINUS { ?wobj3 a bf:Instance }
+ }
+ }
+ }
+ }
+ }
+ </present>
+
+ </db>
+
+ <!-- Small databases -->
+
+ <!-- "small" contains all the things common to all small databases -->
+ <!-- It is only to be used as an include, it is not searchable, since -->
+ <!-- it has no schema atribute -->
+ <!-- It is divided into "smallindex", "smallbody", and a "small" that includes
+ both, so that title searches can include the body, but have different indexes -->
+
+ <db path="smallindex">
+ <index type="any">
+ ?thing bf:label %v FILTER(contains(%v, %s))
+ </index>
+ <index type="1016">
+ ?thing bf:label %v FILTER(contains(%v, %s))
+ </index>
+ </db>