+ yaz_tok_cfg_destroy(cfg);
+ return errors;
+}
+
+struct sparql_entry *lookup_schema(yaz_sparql_t s, const char *schema)
+{
+ struct sparql_entry *e;
+
+ for (e = s->conf; e; e = e->next)
+ {
+ if (!strncmp(e->pattern, "present.", 8))
+ {
+ if (!schema || !strcmp(e->pattern + 8, schema))
+ break;
+ }
+ if (!strncmp(e->pattern, "uri.", 4))
+ {
+ if (!schema || !strcmp(e->pattern + 4, schema))
+ break;
+ }
+ }
+ return e;
+}
+
+int yaz_sparql_lookup_schema(yaz_sparql_t s, const char *schema)
+{
+ return lookup_schema(s, schema) ? 1 : 0;
+}
+
+int yaz_sparql_from_uri_stream(yaz_sparql_t s,
+ WRBUF addinfo,
+ void (*pr)(const char *buf, void *client_data),
+ void *client_data,
+ const char *uri, const char *schema)
+{
+ int r = 0, errors = emit_prefixes(s, addinfo, pr, client_data);
+ struct sparql_entry *e = lookup_schema(s, schema);
+ if (!e)
+ errors++;
+ if (!errors)
+ {
+ WRBUF res = wrbuf_alloc();
+ WRBUF vars = wrbuf_alloc();
+ int var_no = 0;
+ Z_Term term;
+
+ term.which = Z_Term_characterString;
+ term.u.characterString = (char *) uri;
+ r = z_term(s, addinfo, res, vars, e, 0, &term, 0, &var_no);
+ if (!r)
+ {
+ pr(wrbuf_cstr(res), client_data);
+ pr("\n", client_data);
+ }
+ wrbuf_destroy(res);
+ wrbuf_destroy(vars);
+ }
+ return errors ? -1 : r;
+}
+
+int yaz_sparql_from_rpn_stream(yaz_sparql_t s,
+ WRBUF addinfo,
+ void (*pr)(const char *buf,
+ void *client_data),
+ void *client_data,
+ Z_RPNQuery *q)
+{
+ int r = 0, errors = emit_prefixes(s, addinfo, pr, client_data);
+ struct sparql_entry *e;
+