From: Adam Dickmeiss Date: Wed, 4 Feb 2015 12:49:10 +0000 (+0100) Subject: schema check and accept header update MPSPARQL-5 X-Git-Tag: v0.3~2 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=e5b5ae2b4836f76d84aae25c0edf4312b761dae4;p=mp-sparql-moved-to-github.git schema check and accept header update MPSPARQL-5 --- diff --git a/bibframe/triplestore.xml b/bibframe/triplestore.xml index 56b80fa..2e53a31 100644 --- a/bibframe/triplestore.xml +++ b/bibframe/triplestore.xml @@ -1,6 +1,6 @@ - + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/
SELECT DISTINCT ?work ?wtitle ?creatorlabel ?subjectlabel
@@ -16,7 +16,7 @@ ?subject bf:label ?subjectlabel ?subject bf:label %v FILTER(contains(%v, %s))
- + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/
CONSTRUCT { ?work bf:title ?title . ?work bf:author ?creator . ?work bf:instanceTitle ?it }
@@ -32,7 +32,7 @@ ?subject bf:label ?subjectlabel ?subject bf:label %v FILTER(contains(%v, %s))
- + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/
SELECT DISTINCT ?instance ?title ?format
diff --git a/doc/filter_sparql.rnc b/doc/filter_sparql.rnc index 263214d..4e71e8c 100644 --- a/doc/filter_sparql.rnc +++ b/doc/filter_sparql.rnc @@ -9,6 +9,7 @@ filter_sparql = element mp:db { attribute path { xsd:string }, attribute uri { xsd:string }, + attribute schema { xsd:string }, element mp:prefix { xsd:string }+, element mp:field { xsd:string }*, element mp:criteria { xsd:string }*, diff --git a/doc/sparql.xml b/doc/sparql.xml index d374ef6..ba4eca7 100644 --- a/doc/sparql.xml +++ b/doc/sparql.xml @@ -29,7 +29,10 @@ Configuration consists of one or more db elements. Each db element describes how to access a specific database. The db element takes attributes name of Z39.50 database (path) and - HTTP access point of triplestore (uri). Each + HTTP access point of triplestore (uri). + Optionally, the schema for the database may be given with attribute + schema. + Each db element takes these elements: Configurable values: @@ -92,10 +95,13 @@ the field (use attribute) "bf.wtitle" is supported. - + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/ - ?work ?wtitle + SELECT ?work ?wtitle ?work a bf:Work ?work bf:workTitle ?wt ?wt bf:titleValue ?wtitle diff --git a/src/filter_sparql.cpp b/src/filter_sparql.cpp index 8aa9bab..235989b 100644 --- a/src/filter_sparql.cpp +++ b/src/filter_sparql.cpp @@ -60,6 +60,7 @@ namespace metaproxy_1 { public: std::string db; std::string uri; + std::string schema; yaz_sparql_t s; ~Conf(); }; @@ -77,6 +78,7 @@ namespace metaproxy_1 { friend class Session; Odr_int hits; std::string db; + ConfPtr conf; xmlDoc *doc; }; class SPARQL::Session { @@ -88,7 +90,7 @@ namespace metaproxy_1 { Z_APDU *apdu_req, mp::odr &odr, const char *sparql_query, - const char *uri); + ConfPtr conf); Z_Records *fetch( FrontendSetPtr fset, ODR odr, Odr_oid *preferredRecordSyntax, @@ -145,6 +147,8 @@ void yf::SPARQL::configure(const xmlNode *xmlnode, bool test_only, conf->db = mp::xml::get_text(attr->children); else if (!strcmp((const char *) attr->name, "uri")) conf->uri = mp::xml::get_text(attr->children); + else if (!strcmp((const char *) attr->name, "schema")) + conf->schema = mp::xml::get_text(attr->children); else throw mp::filter::FilterException( "Bad attribute " + std::string((const char *) @@ -344,6 +348,20 @@ Z_Records *yf::SPARQL::Session::fetch( int *number_returned, int *next_position) { Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records)); + if (esn && esn->which == Z_ElementSetNames_generic && + fset->conf->schema.length()) + { + if (strcmp(esn->u.generic, fset->conf->schema.c_str())) + { + rec->which = Z_Records_NSD; + rec->u.nonSurrogateDiagnostic = + zget_DefaultDiagFormat( + odr, + YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_, + esn->u.generic); + return rec; + } + } rec->which = Z_Records_DBOSD; rec->u.databaseOrSurDiagnostics = (Z_NamePlusRecordList *) odr_malloc(odr, sizeof(Z_NamePlusRecordList)); @@ -383,18 +401,19 @@ Z_APDU *yf::SPARQL::Session::run_sparql(mp::Package &package, Z_APDU *apdu_req, mp::odr &odr, const char *sparql_query, - const char *uri) + ConfPtr conf) { Z_SearchRequest *req = apdu_req->u.searchRequest; Package http_package(package.session(), package.origin()); http_package.copy_filter(package); - Z_GDU *gdu = z_get_HTTP_Request_uri(odr, uri, 0, 1); + Z_GDU *gdu = z_get_HTTP_Request_uri(odr, conf->uri.c_str(), 0, 1); z_HTTP_header_add(odr, &gdu->u.HTTP_Request->headers, "Content-Type", "application/x-www-form-urlencoded"); z_HTTP_header_add(odr, &gdu->u.HTTP_Request->headers, - "Accept", "application/rdf+xml"); + "Accept", "application/sparql-results+xml," + "application/rdf+xml"); const char *names[2]; names[0] = "query"; names[1] = 0; @@ -437,6 +456,7 @@ Z_APDU *yf::SPARQL::Session::run_sparql(mp::Package &package, fset->doc = xmlParseMemory(resp->content_buf, resp->content_len); fset->db = req->databaseNames[0]; + fset->conf = conf; if (!fset->doc) apdu_res = odr.create_searchResponse(apdu_req, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, @@ -597,8 +617,7 @@ void yf::SPARQL::Session::handle_z(mp::Package &package, Z_APDU *apdu_req) else { apdu_res = run_sparql(package, apdu_req, odr, - wrbuf_cstr(sparql_wr), - (*it)->uri.c_str()); + wrbuf_cstr(sparql_wr), *it); } wrbuf_destroy(addinfo_wr); wrbuf_destroy(sparql_wr);