<filters xmlns="http://indexdata.com/metaproxy">
<filter type="sparql">
- <db path="work" uri="http://bibframe.indexdata.com/sparql/">
+ <db path="work" uri="http://bibframe.indexdata.com/sparql/" 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 ?wtitle ?creatorlabel ?subjectlabel</form>
<criteria>?subject bf:label ?subjectlabel</criteria>
<index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
</db>
- <db path="works" uri="http://bibframe.indexdata.com/sparql/">
+ <db path="works" uri="http://bibframe.indexdata.com/sparql/" 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>
<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/">
+ <db path="instance" uri="http://bibframe.indexdata.com/sparql/" 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>
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 (<literal>path</literal>) and
- HTTP access point of triplestore (<literal>uri</literal>). Each
+ HTTP access point of triplestore (<literal>uri</literal>).
+ Optionally, the schema for the database may be given with attribute
+ <literal>schema</literal>.
+ Each
db element takes these elements:
Configurable values:
<variablelist>
the field (use attribute) "bf.wtitle" is supported.
<screen><![CDATA[
<filter type="sparql">
- <db path="Default" uri="http://bibframe.indexdata.com/sparql/">
+ <db path="Default"
+ uri="http://bibframe.indexdata.com/sparql/"
+ schema="sparql-results"
+ >
<prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
<prefix>bf: http://bibframe.org/vocab/</prefix>
- <field>?work ?wtitle</field>
+ <field>SELECT ?work ?wtitle</field>
<criteria>?work a bf:Work</criteria>
<criteria>?work bf:workTitle ?wt</criteria>
<criteria>?wt bf:titleValue ?wtitle</criteria>
public:
std::string db;
std::string uri;
+ std::string schema;
yaz_sparql_t s;
~Conf();
};
friend class Session;
Odr_int hits;
std::string db;
+ ConfPtr conf;
xmlDoc *doc;
};
class SPARQL::Session {
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,
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 *)
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));
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;
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,
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);