From: Heikki Levanto Date: Wed, 18 Feb 2015 15:21:48 +0000 (+0100) Subject: More examples and explanations on the man page X-Git-Tag: v0.4~4 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=0e7a5eeb3ab16f7a94d2ae3a331c6dd8421f8424;p=mp-sparql-moved-to-github.git More examples and explanations on the man page --- diff --git a/bibframe/triplestore.xml b/bibframe/triplestore.xml index aae5725..f227102 100644 --- a/bibframe/triplestore.xml +++ b/bibframe/triplestore.xml @@ -32,11 +32,17 @@ ?child ?op2 %v FILTER(contains(STR(%v), %s)) } + GROUP BY $work rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/ -
CONSTRUCT { ?work bf:title ?title . ?work bf:author ?creator . ?work bf:instanceTitle ?it }
+
CONSTRUCT { + ?work bf:title ?wtitle . + ?work bf:instanceTitle ?title . + ?work bf:author ?creator . + ?work bf:subject ?subjectlabel } +
?work a bf:Work ?work bf:workTitle ?wt @@ -52,7 +58,7 @@ rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/ -
SELECT DISTINCT ?instance ?title ?format
+
SELECT ?instance ?title ?format
?instance a bf:Instance ?instance bf:title ?title diff --git a/doc/sparql.xml b/doc/sparql.xml index e23b149..2859458 100644 --- a/doc/sparql.xml +++ b/doc/sparql.xml @@ -98,19 +98,18 @@ - EXAMPLES + EXAMPLE Configuration for database "Default" that allows searching works. Only - the field (use attribute) "bf.wtitle" is supported. + the field (use attribute) "bf.wtitle" is supported. + schema="sparql-results"> rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns bf: http://bibframe.org/vocab/ - SELECT ?work ?wtitle +
SELECT ?work ?wtitle
?work a bf:Work ?work bf:workTitle ?wt ?wt bf:titleValue ?wtitle @@ -119,9 +118,123 @@ ]]>
+ The matching is done by a simple case-sensitive substring match. There is + no deduplication, so if a work has two titles, we get two rows.
+ EXAMPLE + + A more complex configuration for database "work". This could be included in + the same filter section as the "Default" db above. + + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns + bf: http://bibframe.org/vocab/ +
SELECT + ?work + (sql:GROUP_DIGEST (?wtitle, ' ; ', 1000, 1)) AS ?title + (sql:GROUP_DIGEST (?creatorlabel, ' ; ', 1000, 1))AS ?creator + (sql:GROUP_DIGEST (?subjectlabel, ' ; ', 1000, 1))AS ?subject +
+ ?work a bf:Work + + OPTIONAL { + ?work bf:workTitle ?wt . + ?wt bf:titleValue ?wtitle } + + OPTIONAL { + ?work bf:creator ?creator . + ?creator bf:label ?creatorlabel } + + OPTIONAL { + ?work bf:subject ?subject . + ?subject bf:label ?subjectlabel } + + ?wt bf:titleValue %v FILTER(contains(%v, %s)) + ?creator bf:label %v FILTER(contains(%v, %s)) + ?subject bf:label %v FILTER(contains(%v, %s)) + { + ?work ?op1 ?child . + ?child ?op2 %v FILTER(contains(STR(%v), %s)) + } + + GROUP BY $work +
+]]> + + + + This returns one row for each work. Titles, authors, and subjects + are all optional. If they repeat, the repeated values are concatenated into + a single field, separated by semicolons. This is done by the GROUP_DIGEST + function that is specific to the Virtuoso back end. + + + This example supports use attributes 4 (title), 1003 (author), 21 (subject), + and 1016 (keyword) which matches any literal in a triplet that refers to the + work, so it works for the titleValue in the workTitle, as well as the label + in the subject, and what ever else there may be. Like the preceding example, + the matching is by a simple substring, case sensitive. A more realistic term + matching could be done with regular expressions, at the cost of some readability + portability, and performance. + + + + EXAMPLE + + Configuration for database "works". This uses CONSTRUCT to produce rdf. + + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns + bf: http://bibframe.org/vocab/ +
CONSTRUCT { + ?work bf:title ?wtitle . + ?work bf:instanceTitle ?title . + ?work bf:author ?creator . + ?work bf:subject ?subjectlabel } +
+ ?work a bf:Work + + ?work bf:workTitle ?wt + ?wt bf:titleValue ?wtitle + ?wt bf:titleValue %v FILTER(contains(%v, %s)) + ?work bf:creator ?creator + ?creator bf:label ?creatorlabel + ?creator bf:label %v FILTER(contains(%v, %s)) + ?work bf:subject ?subject + ?subject bf:label ?subjectlabel + ?subject bf:label %v FILTER(contains(%v, %s)) +
+ ]]> + + + + + EXAMPLE + + Configuration for database "instance". Like "work" above this uses SELECT + to return row-based data, this time from the instances. This is not deduplicated, + so if an instance has two titles, we get two rows, and if it also has + two formats, we get four rows. The DISTINCT in the SELECT + + rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns + bf: http://bibframe.org/vocab/ +
SELECT DISTINCT ?instance ?title ?format
+ ?instance a bf:Instance + ?instance bf:title ?title + ?instance bf:title %v FILTER(contains(%v, %s)) + ?instance bf:format ?format + ?instance bf:format %s + + ]]> +
+
+ + +
+ SEE ALSO