1 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN"
2 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
6 <productname>Metaproxy SPARQL module</productname>
7 <info><orgname>Index Data</orgname></info>
11 <refentrytitle>sparql</refentrytitle>
12 <manvolnum>3mp</manvolnum>
13 <refmiscinfo class="manual">Metaproxy Module</refmiscinfo>
17 <refname>sparql</refname>
19 Metaproxy Module for accessing a triplestore
23 <refsect1><title>DESCRIPTION</title>
25 This module translates Z39.50 operations init, search, present to
26 HTTP requests that accesses a remote triplestore via HTTP
29 Configuration consists of one or more db elements. Each db element
30 describes how to access a specific database. The db element takes
31 attributes name of Z39.50 database (<literal>path</literal>) and
32 HTTP access point of triplestore (<literal>uri</literal>).
33 Optionally, the schema for the database may be given with attribute
34 <literal>schema</literal>.
36 db element takes these elements:
39 <varlistentry><term><prefix/></term>
42 Section that maps prefixes and namespaces for RDF vocabularies.
43 The format is prefix followed by colon, followed by value.
47 <varlistentry><term><form/></term>
50 SPARQL Query formulation selection. SHould start with one of the
51 query forms: SELECT or CONSTRUCT.
55 <varlistentry><term><criteria/></term>
58 section that allows to map static graph patterns for binding
59 variables, narrowing types, etc, or any other WHERE clause criteria
60 static to the Z39.50/SRU database. The final query conversion logic
61 should be able to deduce which optional criteria should be included
62 in the generated SPARQL by analyzing variables required in the query
63 matching and display fields.
67 <varlistentry><term><index type="attribute"/></term>
70 Section used to declare RPN use attribute strings (indexes) and map
71 them to BIBFRAME graph patterns.
72 Items in this section are expanded during RPN query processing and
73 placeholders (%s, %d) are substituted with query terms.
74 To map a given CQL index (e.g the default keyword index) into
75 multiple entity properties, SPARQL constructs like
76 `OPTIONAL` or `UNION` could be used.
80 <varlistentry><term><modifier/></term>
83 Optional section that allows you to add solution sequences or
93 <refsect1><title>SCHEMA</title>
94 <literallayout><xi:include
95 xi:href="filter_sparql.rnc"
97 xmlns:xi="http://www.w3.org/2001/XInclude" />
101 <refsect1><title>EXAMPLE</title>
103 Configuration for database "Default" that allows searching works. Only
104 the field (use attribute) "bf.wtitle" is supported.
106 <filter type="sparql">
108 uri="http://bibframe.indexdata.com/sparql/"
109 schema="sparql-results">
110 <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
111 <prefix>bf: http://bibframe.org/vocab/</prefix>
112 <form>SELECT ?work ?wtitle</form>
113 <criteria>?work a bf:Work</criteria>
114 <criteria>?work bf:workTitle ?wt</criteria>
115 <criteria>?wt bf:titleValue ?wtitle</criteria>
116 <index type="bf.wtitle">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
121 The matching is done by a simple case-sensitive substring match. There is
122 no deduplication, so if a work has two titles, we get two rows.
126 <refsect1><title>EXAMPLE</title>
128 A more complex configuration for database "work". This could be included in
129 the same filter section as the "Default" db above.
131 <db path="work" schema="sparql-results">
132 <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
133 <prefix>bf: http://bibframe.org/vocab/</prefix>
136 (sql:GROUP_DIGEST (?wtitle, ' ; ', 1000, 1)) AS ?title
137 (sql:GROUP_DIGEST (?creatorlabel, ' ; ', 1000, 1))AS ?creator
138 (sql:GROUP_DIGEST (?subjectlabel, ' ; ', 1000, 1))AS ?subject
140 <criteria>?work a bf:Work</criteria>
142 <criteria> OPTIONAL {
143 ?work bf:workTitle ?wt .
144 ?wt bf:titleValue ?wtitle }
146 <criteria> OPTIONAL {
147 ?work bf:creator ?creator .
148 ?creator bf:label ?creatorlabel }
151 ?work bf:subject ?subject .
152 ?subject bf:label ?subjectlabel }
154 <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
155 <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
156 <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
157 <index type="1016"> {
159 ?child ?op2 %v FILTER(contains(STR(%v), %s))
162 <modifier>GROUP BY $work</modifier>
168 This returns one row for each work. Titles, authors, and subjects
169 are all optional. If they repeat, the repeated values are concatenated into
170 a single field, separated by semicolons. This is done by the GROUP_DIGEST
171 function that is specific to the Virtuoso back end.
174 This example supports use attributes 4 (title), 1003 (author), 21 (subject),
175 and 1016 (keyword) which matches any literal in a triplet that refers to the
176 work, so it works for the titleValue in the workTitle, as well as the label
177 in the subject, and what ever else there may be. Like the preceding example,
178 the matching is by a simple substring, case sensitive. A more realistic term
179 matching could be done with regular expressions, at the cost of some readability
180 portability, and performance.
184 <refsect1><title>EXAMPLE</title>
186 Configuration for database "works". This uses CONSTRUCT to produce rdf.
188 <db path="works" schema="rdf">
189 <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
190 <prefix>bf: http://bibframe.org/vocab/</prefix>
192 ?work bf:title ?wtitle .
193 ?work bf:instanceTitle ?title .
194 ?work bf:author ?creator .
195 ?work bf:subject ?subjectlabel }
197 <criteria>?work a bf:Work</criteria>
199 <criteria>?work bf:workTitle ?wt</criteria>
200 <criteria>?wt bf:titleValue ?wtitle</criteria>
201 <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
202 <criteria>?work bf:creator ?creator</criteria>
203 <criteria>?creator bf:label ?creatorlabel</criteria>
204 <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
205 <criteria>?work bf:subject ?subject</criteria>
206 <criteria>?subject bf:label ?subjectlabel</criteria>
207 <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
214 <refsect1><title>EXAMPLE</title>
216 Configuration for database "instance". Like "work" above this uses SELECT
217 to return row-based data, this time from the instances. This is not deduplicated,
218 so if an instance has two titles, we get two rows, and if it also has
219 two formats, we get four rows. The DISTINCT in the SELECT
221 <db path="instance" schema="sparql-results">
222 <prefix>rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns</prefix>
223 <prefix>bf: http://bibframe.org/vocab/</prefix>
224 <form>SELECT DISTINCT ?instance ?title ?format</form>
225 <criteria>?instance a bf:Instance</criteria>
226 <criteria>?instance bf:title ?title</criteria>
227 <index type="4">?instance bf:title %v FILTER(contains(%v, %s))</index>
228 <criteria>?instance bf:format ?format</criteria>
229 <index type="1013">?instance bf:format %s</index>
238 <refsect1><title>SEE ALSO</title>
241 <refentrytitle>metaproxy</refentrytitle>
242 <manvolnum>1</manvolnum>
249 <!-- Keep this comment at the end of the file