Fix minor typo
[mp-sparql-moved-to-github.git] / doc / sparql.xml
1 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN"
2     "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
3 ]>
4 <refentry id="sparql">
5  <refentryinfo>
6   <productname>Metaproxy SPARQL module</productname>
7   <info><orgname>Index Data</orgname></info>
8  </refentryinfo>
9
10  <refmeta>
11   <refentrytitle>sparql</refentrytitle>
12   <manvolnum>3mp</manvolnum>
13   <refmiscinfo class="manual">Metaproxy Module</refmiscinfo>
14  </refmeta>
15
16  <refnamediv>
17   <refname>sparql</refname>
18   <refpurpose>
19    Metaproxy Module for accessing a triplestore
20   </refpurpose>
21  </refnamediv>
22
23  <refsect1><title>DESCRIPTION</title>
24   <para>
25    This module translates Z39.50 operations init, search, present to
26    HTTP requests that accesses a remote triplestore via HTTP
27   </para>
28   <para>
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>.
35    Each
36    db element takes these elements:
37    Configurable values:
38    <variablelist>
39     <varlistentry><term>&lt;prefix/&gt;</term>
40      <listitem>
41       <para>
42        Section that maps prefixes and namespaces for RDF vocabularies.
43        The format is prefix followed by colon, followed by value.
44       </para>
45      </listitem>
46     </varlistentry>
47     <varlistentry><term>&lt;form/&gt;</term>
48      <listitem>
49       <para>
50        SPARQL Query formulation selection. Should start with one of the
51        query forms: SELECT or CONSTRUCT.
52       </para>
53      </listitem>
54     </varlistentry>
55     <varlistentry><term>&lt;criteria/&gt;</term>
56      <listitem>
57       <para>
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.
64       </para>
65      </listitem>
66     </varlistentry>
67     <varlistentry><term>&lt;index type="attribute"/&gt;</term>
68      <listitem>
69       <para>
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 (<literal>%s</literal>, <literal>%d</literal>,
74        <literal>%t</literal>) are substituted with query terms.
75        To map a given CQL index (e.g the default keyword index) into
76        multiple entity properties, SPARQL constructs like
77        `OPTIONAL` or `UNION` could be used.
78       </para>
79      </listitem>
80     </varlistentry>
81     <varlistentry><term>&lt;present type="attribute"/&gt;</term>
82      <listitem>
83       <para>
84        Section used to declare retrieval for a given element-set 
85        (SRU schema). The CDATA is SPARQL where <literal>%u</literal> holds
86        the URI of the record. This can be used to construct the resulting
87        record.
88       </para>
89      </listitem>
90     </varlistentry>
91     <varlistentry><term>&lt;modifier/&gt;</term>
92      <listitem>
93       <para>
94        Optional section that allows you to add solution sequences or
95        modifiers.
96       </para>
97      </listitem>
98     </varlistentry>
99
100    </variablelist>
101   </para>
102  </refsect1>
103
104  <refsect1><title>SCHEMA</title>
105    <literallayout><xi:include
106                      xi:href="filter_sparql.rnc"
107                      xi:parse="text"
108                      xmlns:xi="http://www.w3.org/2001/XInclude" />
109    </literallayout>
110  </refsect1>
111
112  <refsect1><title>EXAMPLE</title>
113   <para>
114    Configuration for database "Default" that allows searching works. Only
115    the field (use attribute) "bf.wtitle" is supported.
116    <screen><![CDATA[
117   <filter type="sparql">
118     <db path="Default"
119         uri="http://bibframe.indexdata.com/sparql/"
120         schema="sparql-results">
121       <prefix>bf: http://bibframe.org/vocab/</prefix>
122       <form>SELECT ?work ?wtitle</form>
123       <criteria>?work a bf:Work</criteria>
124       <criteria>?work bf:workTitle ?wt</criteria>
125       <criteria>?wt bf:titleValue ?wtitle</criteria>
126       <index type="bf.wtitle">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
127     </db>
128   </filter>
129 ]]>
130    </screen>
131    The matching is done by a simple case-sensitive substring match. There is
132    no deduplication, so if a work has two titles, we get two rows.
133   </para>
134  </refsect1>
135
136  <refsect1><title>EXAMPLE</title>
137   <para>
138    A more complex configuration for database "work". This could be included in
139    the same filter section as the "Default" db above.
140    <screen><![CDATA[
141     <db path="work" schema="sparql-results">
142       <prefix>bf: http://bibframe.org/vocab/</prefix>
143       <form>SELECT
144               ?work
145               (sql:GROUP_DIGEST (?wtitle, ' ; ', 1000, 1)) AS ?title
146               (sql:GROUP_DIGEST (?creatorlabel, ' ; ', 1000, 1))AS ?creator
147               (sql:GROUP_DIGEST (?subjectlabel, ' ; ', 1000, 1))AS ?subject
148       </form>
149       <criteria>?work a bf:Work</criteria>
150
151       <criteria> OPTIONAL {
152           ?work bf:workTitle ?wt .
153           ?wt bf:titleValue ?wtitle }
154       </criteria>
155       <criteria> OPTIONAL {
156           ?work bf:creator ?creator .
157           ?creator bf:label ?creatorlabel }
158       </criteria>
159       <criteria>OPTIONAL {
160           ?work bf:subject ?subject .
161           ?subject bf:label ?subjectlabel }
162       </criteria>
163       <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
164       <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
165       <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
166       <index type="1016"> {
167             ?work ?op1 ?child .
168             ?child ?op2 %v FILTER(contains(STR(%v), %s))
169           }
170       </index>
171       <modifier>GROUP BY $work</modifier>
172     </db>
173 ]]>
174    </screen>
175    </para>
176    <para>
177     This returns one row for each work. Titles, authors, and subjects
178     are all optional. If they repeat, the repeated values are concatenated into
179     a single field, separated by semicolons. This is done by the GROUP_DIGEST
180     function that is specific to the Virtuoso back end.
181    </para>
182    <para>
183     This example supports use attributes 4 (title), 1003 (author), 21 (subject),
184     and 1016 (keyword) which matches any literal in a triplet that refers to the
185     work, so it works for the titleValue in the workTitle, as well as the label
186     in the subject, and what ever else there may be. Like the preceding example,
187     the matching is by a simple substring, case sensitive. A more realistic term
188     matching could be done with regular expressions, at the cost of some readability
189     portability, and performance.
190    </para>
191  </refsect1>
192
193  <refsect1><title>EXAMPLE</title>
194    <para>
195     Configuration for database "works". This uses CONSTRUCT to produce rdf.
196    <screen><![CDATA[
197     <db path="works" schema="rdf">
198       <prefix>bf: http://bibframe.org/vocab/</prefix>
199       <form>CONSTRUCT {
200           ?work bf:title ?wtitle .
201           ?work bf:instanceTitle ?title .
202           ?work bf:author ?creator .
203           ?work bf:subject ?subjectlabel }
204       </form>
205       <criteria>?work a bf:Work</criteria>
206
207       <criteria>?work bf:workTitle ?wt</criteria>
208       <criteria>?wt bf:titleValue ?wtitle</criteria>
209       <index type="4">?wt bf:titleValue %v FILTER(contains(%v, %s))</index>
210       <criteria>?work bf:creator ?creator</criteria>
211       <criteria>?creator bf:label ?creatorlabel</criteria>
212       <index type="1003">?creator bf:label %v FILTER(contains(%v, %s))</index>
213       <criteria>?work bf:subject ?subject</criteria>
214       <criteria>?subject bf:label ?subjectlabel</criteria>
215       <index type="21">?subject bf:label %v FILTER(contains(%v, %s))</index>
216     </db>
217  ]]>
218    </screen>
219   </para>
220  </refsect1>
221
222  <refsect1><title>EXAMPLE</title>
223    <para>
224     Configuration for database "instance". Like "work" above this uses SELECT
225     to return row-based data, this time from the instances. This is not deduplicated,
226     so if an instance has two titles, we get two rows, and if it also has
227     two formats, we get four rows. The DISTINCT in the SELECT
228    <screen><![CDATA[
229     <db path="instance" schema="sparql-results">
230       <prefix>bf: http://bibframe.org/vocab/</prefix>
231       <form>SELECT DISTINCT ?instance ?title ?format</form>
232       <criteria>?instance a bf:Instance</criteria>
233       <criteria>?instance bf:title ?title</criteria>
234       <index type="4">?instance bf:title %v FILTER(contains(%v, %s))</index>
235       <criteria>?instance bf:format ?format</criteria>
236       <index type="1013">?instance bf:format %s</index>
237     </db>
238  ]]>
239    </screen>
240   </para>
241
242
243  </refsect1>
244
245  <refsect1><title>SEE ALSO</title>
246   <para>
247    <citerefentry>
248     <refentrytitle>metaproxy</refentrytitle>
249     <manvolnum>1</manvolnum>
250    </citerefentry>
251   </para>
252  </refsect1>
253
254 </refentry>
255
256 <!-- Keep this comment at the end of the file
257 Local variables:
258 mode: nxml
259 nxml-child-indent: 1
260 End:
261 -->