1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
10 #include <yaz/sparql.h>
13 #include <yaz/pquery.h>
15 static int test_query(yaz_sparql_t s, const char *pqf, const char *expect)
17 YAZ_PQF_Parser parser = yaz_pqf_create();
18 ODR odr = odr_createmem(ODR_ENCODE);
19 Z_RPNQuery *rpn = yaz_pqf_parse(parser, odr, pqf);
21 WRBUF addinfo = wrbuf_alloc();
22 WRBUF w = wrbuf_alloc();
26 int r = yaz_sparql_from_rpn_wrbuf(s, addinfo, w, rpn);
31 if (!strcmp(expect, wrbuf_cstr(w)))
35 yaz_log(YLOG_WARN, "test_sparql: pqf=%s", pqf);
36 yaz_log(YLOG_WARN, " expect: %s", expect);
37 yaz_log(YLOG_WARN, " got: %s", wrbuf_cstr(w));
42 yaz_log(YLOG_WARN, "test_sparql: pqf=%s", pqf);
43 yaz_log(YLOG_WARN, " expect: %s", expect);
44 yaz_log(YLOG_WARN, " got error: %d:%s", r, wrbuf_cstr(addinfo));
53 yaz_log(YLOG_WARN, "test_sparql: pqf=%s", pqf);
54 yaz_log(YLOG_WARN, " expect error");
55 yaz_log(YLOG_WARN, " got: %s", wrbuf_cstr(w));
60 wrbuf_destroy(addinfo);
62 yaz_pqf_destroy(parser);
66 static void tst1(void)
68 yaz_sparql_t s = yaz_sparql_create();
70 yaz_sparql_add_pattern(s, "prefix",
71 "rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns");
72 yaz_sparql_add_pattern(s, "prefix",
73 "bf: <http://bibframe.org/vocab/>");
74 yaz_sparql_add_pattern(s, "field.title", "?title");
75 yaz_sparql_add_pattern(s, "field.author", "?author");
76 yaz_sparql_add_pattern(s, "field.description", "?description");
77 yaz_sparql_add_pattern(s, "field.instanceTitle", "?ititle");
78 yaz_sparql_add_pattern(s, "criteria", "?work a bf:Work");
79 yaz_sparql_add_pattern(s, "criteria", "?work bf:workTitle/bf:titleValue ?title");
80 yaz_sparql_add_pattern(s, "criteria", "?work bf:creator/bf:label ?author");
81 yaz_sparql_add_pattern(s, "criteria", "?work bf:note ?description");
82 yaz_sparql_add_pattern(s, "criteria", "?inst bf:instanceOf ?work");
83 yaz_sparql_add_pattern(s, "criteria", "?inst bf:instanceTitle/bf:titleValue ?ititle");
86 "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns>\n"
87 "PREFIX bf: <http://bibframe.org/vocab/>\n"
89 "SELECT ?title ?author ?description ?ititle\n"
91 " ?work a bf:Work .\n"
92 " ?work bf:workTitle/bf:titleValue ?title .\n"
93 " ?work bf:creator/bf:label ?author .\n"
94 " ?work bf:note ?description .\n"
95 " ?inst bf:instanceOf ?work .\n"
96 " ?inst bf:instanceTitle/bf:titleValue ?ititle .\n"
100 yaz_sparql_destroy(s);
103 int main(int argc, char **argv)
105 YAZ_CHECK_INIT(argc, argv);
113 * c-file-style: "Stroustrup"
114 * indent-tabs-mode: nil
116 * vim: shiftwidth=4 tabstop=8 expandtab