Towards LOC-7: Experiments in expanding works
[mp-sparql-moved-to-github.git] / bibframe / triplestore.xml
index 7277edb..3ea4914 100644 (file)
 <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/"/>
+
+    <!-- New structure: Any search in work returns just a list of records.
+         Present will make another request to the backend to get the fields
+         we want, depending on the schema. That part is not yet implemented -->
     <db path="work" 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 ?work
+      </form>
+      <criteria>?work a bf:Work</criteria>
+      <!-- TODO: Many more indexes like the ones below-->
+      <index type="bf.title">?work bf:workTitle ?wt .
+          ?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
+      <index type="bf.creator">?work bf:creator ?c .
+          ?c bf:label %v FILTER(contains(%v, %s))</index>
+      <index type="bf.subject">?work bf:subject ?subject .
+          ?subject bf:label %v FILTER(contains(%v, %s))</index>
+      <!-- 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 { 
+          ?obj ?rel1 ?obj1  
+            MINUS { ?obj a bf:Work } 
+          } </criteria>
+      <criteria>OPTIONAL {
+          ?obj1 ?rel2 ?obj2 
+            MINUS { ?obj1 a bf:Work } 
+          } </criteria>
+      <criteria>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
       </index>
       <modifier>GROUP BY $work</modifier>
     </db>
-    <db path="works" schema="rdf">
+
+    <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 { 
       <criteria>?subject bf:label ?subjectlabel</criteria>
       <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
     </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>
       <criteria>?instance bf:format ?format</criteria>
       <index type="1013">?instance bf:format %s</index>
     </db>
+
+    <!-- Simple databases -->
     <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 ?label ?id ?place ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?place ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?place a bf:Place</criteria>
       <criteria>?place bf:label ?label</criteria>
       <criteria>OPTIONAL { ?place bf:identifier ?id}</criteria>
     <db path="person" 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 ?person ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?person ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?person a bf:Person</criteria>
       <criteria>?person bf:label ?label</criteria>
       <criteria>OPTIONAL { ?person bf:identifier ?id}</criteria>
     <db path="meeting" 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 ?meeting ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?meeting ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?meeting a bf:Meeting</criteria>
       <criteria>?meeting bf:label ?label</criteria>
       <criteria>OPTIONAL { ?meeting bf:identifier ?id}</criteria>
     <db path="agent" 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 ?agent ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?agent ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?agent a bf:Agent</criteria>
       <criteria>?agent bf:label ?label</criteria>
       <criteria>OPTIONAL { ?agent bf:identifier ?id}</criteria>
     <db path="event" 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 ?event ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?event ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?event a bf:Event</criteria>
       <criteria>?event bf:label ?label</criteria>
       <criteria>OPTIONAL { ?event bf:identifier ?id}</criteria>
     <db path="organization" 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 ?organization ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?organization ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?organization a bf:Organization</criteria>
       <criteria>?organization bf:label ?label</criteria>
       <criteria>OPTIONAL { ?organization bf:identifier ?id}</criteria>
     <db path="topic" 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 ?topic ?relatedTo ?authorizedAccessPoint </form>
+      <form>SELECT DISTINCT  ?label ?id ?topic ?relatedTo ?authorizedAccessPoint </form>
       <criteria>?topic a bf:Topic</criteria>
       <criteria>?topic bf:label ?label</criteria>
       <criteria>OPTIONAL { ?topic bf:identifier ?id}</criteria>
       <index type="bf.topic">?topic bf:label %v FILTER(contains(%v, %s))</index>
       <index type="any">?topic bf:label %v FILTER(contains(%v, %s))</index>
     </db>
-    <db path="node" schema="rdf">
+
+    <!-- Title search, probably not needed. Will need to be rewritten to the same
+    system as the work search above, with separate present query -->
+    <db path="title" 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 ?title ?titleValue 
+            ?formDesignation ?partNumber ?partTitle ?subtitle 
+            ?titleAttribute ?titleQualifier ?titleSource 
+            ?titleType ?titleVariationDate</form>
+        <criteria>?title a bf:Title</criteria>
+        <criteria>OPTIONAL { ?title bf:titleValue ?titleValue}</criteria>
+        <criteria>OPTIONAL { ?title bf:formDesignation ?formDesignation}</criteria>
+        <criteria>OPTIONAL { ?title bf:partNumber ?partNumber}</criteria>
+        <criteria>OPTIONAL { ?title bf:partTitle ?partTitle}</criteria>
+        <criteria>OPTIONAL { ?title bf:subtitle ?subtitle}</criteria>
+        <criteria>OPTIONAL { ?title bf:titleAttribute ?titleAttribute}</criteria>
+        <criteria>OPTIONAL { ?title bf:titleQualifier ?titleQualifier}</criteria>
+        <criteria>OPTIONAL { ?title bf:titleSource ?titleSource}</criteria>
+        <criteria>OPTIONAL { ?title bf:titleType ?titleType}</criteria>
+        <criteria>OPTIONAL { ?title bf:titleVariationDate ?titleVariationDate}</criteria>
+        <index type="bf.title">?title bf:titleValue %v FILTER(contains(%v, %s))</index>
+        <index type="bf.subtitle">?title bf:subtitle %v FILTER(contains(%v, %s))</index>
+        <index type="bf.parttitle">?title bf:partTitle %v FILTER(contains(%v, %s))</index>
+        <index type="any">?title ?rel  %v FILTER(contains(str(%v), %s))</index>
+    </db>
+    <!-- A hack to be able to look at any triplet in the base -->
+    <db path="node" schema="sparql-results">
       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
       <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>DESCRIBE ?node </form>
+      <form>SELECT ?node ?rel ?obj</form>
       <index type="any">?node ?rel ?obj FILTER( str(?node) = %s )</index>
     </db>
+    <!-- A way to see which triplets refers to a given uri. -->
+    <db path="ref" 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 ?node ?rel ?obj</form>
+      <index type="any">?node ?rel ?obj FILTER( str(?obj) = %s )</index>
+    </db>
   </filter>
   <filter type="log">
     <message>http</message>