allow triplestore endpoint to be given once MPSPARQL-10
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 18 Feb 2015 12:19:35 +0000 (13:19 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 18 Feb 2015 12:19:35 +0000 (13:19 +0100)
bibframe/triplestore.xml
doc/filter_sparql.rnc
src/filter_sparql.cpp

index dcfbc93..f5fd644 100644 (file)
@@ -1,10 +1,11 @@
 <filters  xmlns="http://indexdata.com/metaproxy">
   <filter type="sparql">
 <filters  xmlns="http://indexdata.com/metaproxy">
   <filter type="sparql">
-    <db path="work" uri="http://bibframe.indexdata.com/sparql/" schema="sparql-results">
+    <defaults uri="http://bibframe.indexdata.com:21/sparql/"/>
+    <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>
       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
       <prefix>bf: http://bibframe.org/vocab/</prefix>
-      <form>SELECT 
-              ?work 
+      <form>SELECT
+              ?work
               MAX(?wtitle) AS ?title
               MAX(?creatorlabel) AS ?creator
               MAX(?subjectlabel) AS ?subject
               MAX(?wtitle) AS ?title
               MAX(?creatorlabel) AS ?creator
               MAX(?subjectlabel) AS ?subject
       <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="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"> { 
+      <index type="1016"> {
             ?work ?op1 ?child .
             ?child ?op2 ?val FILTER(contains(STR(?val), %s))
           }
       </index>
       <modifier>GROUP BY $work</modifier>
     </db>
             ?work ?op1 ?child .
             ?child ?op2 ?val FILTER(contains(STR(?val), %s))
           }
       </index>
       <modifier>GROUP BY $work</modifier>
     </db>
-    <db path="works" uri="http://bibframe.indexdata.com/sparql/" schema="rdf">
+    <db path="works" 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 bf:title ?title . ?work bf:author ?creator . ?work bf:instanceTitle ?it }</form>
       <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 ?title . ?work bf:author ?creator . ?work bf:instanceTitle ?it }</form>
@@ -49,7 +50,7 @@
       <criteria>?subject bf:label ?subjectlabel</criteria>
       <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
     </db>
       <criteria>?subject bf:label ?subjectlabel</criteria>
       <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
     </db>
-    <db path="instance" uri="http://bibframe.indexdata.com/sparql/" schema="sparql-results">
+    <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 DISTINCT ?instance ?title ?format</form>
       <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
       <prefix>bf: http://bibframe.org/vocab/</prefix>
       <form>SELECT DISTINCT ?instance ?title ?format</form>
index 3a97465..3b6e817 100644 (file)
@@ -6,6 +6,9 @@ filter_sparql =
   attribute type { "xquery" },
   attribute id { xsd:NCName }?,
   attribute name { xsd:NCName }?,
   attribute type { "xquery" },
   attribute id { xsd:NCName }?,
   attribute name { xsd:NCName }?,
+  element mp:defaults {
+    attribute uri { xsd:string }
+  }?,
   element mp:db {
     attribute path { xsd:string },
     attribute uri { xsd:string },
   element mp:db {
     attribute path { xsd:string },
     attribute uri { xsd:string },
@@ -19,4 +22,3 @@ filter_sparql =
     }*,
     element mp:modifier { xsd:string }*
   }+
     }*,
     element mp:modifier { xsd:string }*
   }+
-
index bfb18c7..3a824f0 100644 (file)
@@ -129,16 +129,31 @@ void yf::SPARQL::configure(const xmlNode *xmlnode, bool test_only,
                            const char *path)
 {
     const xmlNode *ptr = xmlnode->children;
                            const char *path)
 {
     const xmlNode *ptr = xmlnode->children;
+    std::string uri;
 
     for (; ptr; ptr = ptr->next)
     {
         if (ptr->type != XML_ELEMENT_NODE)
             continue;
 
     for (; ptr; ptr = ptr->next)
     {
         if (ptr->type != XML_ELEMENT_NODE)
             continue;
-        if (!strcmp((const char *) ptr->name, "db"))
+        if (!strcmp((const char *) ptr->name, "defaults"))
+        {
+            const struct _xmlAttr *attr;
+            for (attr = ptr->properties; attr; attr = attr->next)
+            {
+                if (!strcmp((const char *) attr->name, "uri"))
+                    uri = mp::xml::get_text(attr->children);
+                else
+                    throw mp::filter::FilterException(
+                        "Bad attribute " + std::string((const char *)
+                                                       attr->name));
+            }
+        }
+        else if (!strcmp((const char *) ptr->name, "db"))
         {
             yaz_sparql_t s = yaz_sparql_create();
             ConfPtr conf(new Conf);
             conf->s = s;
         {
             yaz_sparql_t s = yaz_sparql_create();
             ConfPtr conf(new Conf);
             conf->s = s;
+            conf->uri = uri;
 
             const struct _xmlAttr *attr;
             for (attr = ptr->properties; attr; attr = attr->next)
 
             const struct _xmlAttr *attr;
             for (attr = ptr->properties; attr; attr = attr->next)