Allow include of db definitions MPSPARQL-15
[mp-sparql-moved-to-github.git] / bibframe / triplestore.xml
index 42cfc26..27220ea 100644 (file)
@@ -1,8 +1,8 @@
 <filters  xmlns="http://indexdata.com/metaproxy">
   <filter type="sparql">
       <!-- Which sparql server to use, our demo, or your local installation -->
-    <!--defaults uri="http://bibframe.indexdata.com/sparql/"/-->
-    <defaults uri="http://localhost:8890/sparql/"/>
+    <defaults uri="http://bibframe.indexdata.com/sparql/"/>
+    <!--defaults uri="http://localhost:8890/sparql/"/-->
 
     <!-- New structure: Any search in work returns just a list of records.
          Present will make another request to the backend to get the fields
           ?subject bf:label %v FILTER(contains(%v, %s))
       </index>
       <uri type="BF-L">
-       CONSTRUCT { ?work ?rel ?subj }
-       WHERE {
-        ?work a bf:Work .
-        ?work ?rel ?subj .
-        ?work ?rel ?obj FILTER( str(?work) = %s )
+        CONSTRUCT { ?work ?rel ?subj }
+         WHERE {
+         ?work a bf:Work .
+         ?work ?rel ?subj .
+         ?work ?rel ?obj FILTER( str(?work) = %s )
         }
       </uri>
-      <!-- TODO: Define a query to return detailed information for each
-      schema. For example
-      <present shema="BF-L" results="sparql-results" >
-        <query>
-          SELECT ?sub ?rel ?obj
-          WHERE ?work ?rel ?obj FILTER( str(?work) = %s )
-        </query>
-           - or possibly "FILTER ( ?work = <%u> )" if we define %u to
-           expand to the unquoted URI of the work.
-           - Even better, with %u we can say something like
-              SELECT %u ?rel ?obj
-      </present>
-      -->
-    </db>
-
-    <!-- Experiments while waiting for the present queries to be implemented -->
-    <db path="onework-l" schema="sparql-results">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>SELECT ?work ?rel ?subj
-      </form>
-      <criteria>?work a bf:Work</criteria>
-      <criteria>?work ?rel ?obj</criteria>
-      <index type="any">?work ?rel ?obj FILTER( str(?work) = %s )</index>
-    </db>
-    <!-- Returns a decent-looking rdf (except that mp says 0 hits) 
-    with no links expanded -->
-    <db path="onework-l-rdf" schema="rdf">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>CONSTRUCT { ?work ?rel ?obj }
-      </form>
-      <criteria>?work a bf:Work</criteria>
-      <criteria>?work ?rel ?obj</criteria>
-      <index type="any">?work ?rel ?obj FILTER( str(?work) = %s )</index>
-    </db>
-    <!-- Expand some links -->
-    <db path="onework-e-rdf" schema="rdf">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>CONSTRUCT { ?work ?rel ?obj.
-                        ?creator ?crRel ?crObj .
-                        ?subj ?subRel ?subObj }
-      </form>
-      <criteria>?work a bf:Work</criteria>
-      <criteria>?work ?rel ?obj</criteria>
-      <criteria>OPTIONAL { ?work bf:creator ?creator . 
-                           ?creator ?crRel ?crObj }
-      </criteria>
-      <criteria>OPTIONAL { ?work bf:subject ?subj . 
-                           ?subj ?subRel ?subObj }
-      </criteria>
-      <index type="any">?work ?rel ?obj FILTER( str(?work) = %s )</index>
-    </db>
-    <!-- Expand all things a couple of levels. 
-      In all the data I have seen, two levels is enough. So we do three
-      Lnks to Works and Instances are explicitly excluded from this expansion,
-      and need to be handled separately. This is to avoid looping.
-    -->
-    
-    <db path="onework-f-rdf" schema="rdf">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>CONSTRUCT { ?work ?rel ?obj .
-                        ?obj ?rel1 ?obj1 .
-                        ?obj1 ?rel2 ?obj2 .
-                        ?obj2 ?rel3 ?obj3
-                        }
-      </form>
-      <criteria>?work a bf:Work</criteria>
-      
-      <criteria>?work ?rel ?obj </criteria>
-      <criteria>OPTIONAL { 
+      <uri type="BF-F">
+        CONSTRUCT { ?work ?rel ?obj .
+                    ?obj ?rel1 ?obj1 .
+                    ?obj1 ?rel2 ?obj2 .
+                    ?obj2 ?rel3 ?obj3 }
+         WHERE {
+         ?work a bf:Work .
+         ?work ?rel ?obj .
+      OPTIONAL { 
           ?obj ?rel1 ?obj1  
             MINUS { ?obj a bf:Work } 
-          } </criteria>
-      <criteria>OPTIONAL {
+          }
+      OPTIONAL {
           ?obj1 ?rel2 ?obj2 
             MINUS { ?obj1 a bf:Work } 
-          } </criteria>
-      <criteria>OPTIONAL { 
+          } 
+      OPTIONAL { 
           ?obj2 ?rel3 ?obj3 
             MINUS { ?obj2 a bf:Work } 
-          } </criteria>
-      <index type="any">?work ?rel ?obj FILTER( str(?work) = %s )</index>
-    </db>
-    <!-- Describe a work. Results may vary between back ends -->
-    <!-- On virtuoso, seems to return the same as onework-l-rdf above -->
-    <db path="onework-d-rdf" schema="rdf">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>DESCRIBE ?work 
-      </form>
-      <criteria>?work a bf:Work</criteria>
-      <criteria>?work ?rel ?obj</criteria>
-      <criteria>OPTIONAL { ?work bf:creator ?creator . 
-                           ?creator ?crRel ?crObj }
-      </criteria>
-      <criteria>OPTIONAL { ?work bf:subject ?subj . 
-                           ?subj ?subRel ?subObj }
-      </criteria>
-      <index type="any">?work ?rel ?obj FILTER( str(?work) = %s )</index>
-    </db>
-
-    <!-- This is the old "work" db that will not scale. May be removed -->
-    <db path="concatwork" schema="sparql-results">
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>SELECT
-              ?work
-              (sql:GROUP_DIGEST (?wtitle, ' ; ', 1000, 1)) AS ?title
-              (sql:GROUP_DIGEST (?creatorlabel, ' ; ', 1000, 1))AS ?creator
-              (sql:GROUP_DIGEST (?subjectlabel, ' ; ', 1000, 1))AS ?subject
-      </form>
-      <criteria>?work a bf:Work</criteria>
-
-      <criteria> OPTIONAL {
-          ?work bf:workTitle ?wt .
-          ?wt bf:titleValue ?wtitle }
-      </criteria>
-      <criteria> OPTIONAL {
-          ?work bf:creator ?creator .
-          ?creator bf:label ?creatorlabel }
-      </criteria>
-      <criteria>OPTIONAL {
-          ?work bf:subject ?subject .
-          ?subject bf:label ?subjectlabel }
-      </criteria>
-      <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
-      <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
-      <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
-      <index type="1016"> {
-            ?work ?op1 ?child .
-            ?child ?op2 %v FILTER(contains(STR(%v), %s))
           }
-      </index>
-      <modifier>GROUP BY $work</modifier>
-    </db>
-
-    <db path="works" schema="rdf">  <!-- May be removed, will not scale -->
-      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
-      <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>CONSTRUCT { 
-          ?work bf:title ?wtitle . 
-          ?work bf:instanceTitle ?title .
-          ?work bf:author ?creator . 
-          ?work bf:subject ?subjectlabel }
-      </form>
-      <criteria>?work a bf:Work</criteria>
-
-      <criteria>?work bf:workTitle ?wt</criteria>
-      <criteria>?wt bf:titleValue ?wtitle</criteria>
-      <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
-      <criteria>?work bf:creator ?creator</criteria>
-      <criteria>?creator bf:label ?creatorlabel</criteria>
-      <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
-      <criteria>?work bf:subject ?subject</criteria>
-      <criteria>?subject bf:label ?subjectlabel</criteria>
-      <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
+         ?work ?rel ?obj FILTER( str(?work) = %s )
+        }
+      </uri>
     </db>
-
     <!-- Instance searches, need to be refined later -->
     <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>
       <form>SELECT ?instance ?title ?format</form>
       <criteria>?instance a bf:Instance</criteria>
-
       <criteria>?instance bf:title ?title</criteria>
       <index type="4">?instance bf:title %v FILTER(contains(%v, %s))</index>
       <criteria>?instance bf:format ?format</criteria>
     <db path="place" schema="sparql-results">
       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
       <prefix>bf: http://bibframe.org/vocab/</prefix>
+      <form>SELECT DISTINCT ?place </form>
+      <criteria>?place a bf:Place</criteria>
+      <criteria>?place ?rel ?obj</criteria>
+      <index type="bf.place">?place bf:label %v FILTER(contains(%v, %s))</index>
+      <index type="any">?place bf:label %v FILTER(contains(%v, %s))</index>
+      <index type="1016">?place bf:label %v FILTER(contains(%v, %s))</index>
+      <uri type="BF-L">
+        CONSTRUCT { %u ?rel ?obj }
+         WHERE {
+           %u ?rel ?obj .
+         }
+      </uri>
+      <!-- Experimental, to get just the URIs out, in proper rdf. Probably not useful 
+      <uri type="BF-U">
+        CONSTRUCT { %u bf:uri %u }
+         WHERE {
+           %u bf:label ?lbl .
+         }
+      </uri>
+      -->
+      <uri type="BF-F">
+          <!-- I don't think we need more than one level for these simple 
+          databases -->
+        CONSTRUCT { %u ?rel ?obj . 
+                    ?obj ?rel1 ?obj1 .
+                    <!--  ?obj1 ?rel2 ?obj2 -->
+                  }
+         WHERE {
+           %u ?rel ?obj .
+           OPTIONAL { ?obj ?rel1 ?obj1 }
+           <!-- OPTIONAL { ?obj1 ?rel2 ?obj2 }   Seems not to be necessary -->
+         }
+      </uri>
+    </db>
+    <db path="place-old" schema="sparql-results">
+      <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
+      <prefix>bf: http://bibframe.org/vocab/</prefix>
       <form>SELECT DISTINCT  ?label ?id ?place ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?place a bf:Place</criteria>
       <criteria>?place bf:label ?label</criteria>