Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying Project Gutenberg catalog.rdf via SPARQL
    primarykey
    data
    text
    <p>I'm having difficulty structuring a SPARQL query for the Project Gutenberg catalog (available at <a href="http://www.gutenberg.org/wiki/Gutenberg:Feeds" rel="nofollow noreferrer">Gutenberg Feeds</a> toward the bottom of the page). I know it is a fundamental lack of understanding on my part of how SparQL/RDF/etc. actually work, conflating it with SQL, etc. But I've tried several tutorials, and I just can't quite get my mind around piecing the WHERE clause together with what seems to be the multidimensional dataset.</p> <p>I have imported catalog.rdf into a TDB database (from the Jena project), and am using the tdbquery tool to set up my query initially, before I wrap it into a command-line tool that allows searching by author or title.</p> <p>Here is what I have so far:</p> <pre><code>$ cat gutenquery.tq PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt; PREFIX dcterms: &lt;http://purl.org/dc/terms/&gt; PREFIX dcmitype: &lt;http://purl.org/dc/dcmitype/&gt; PREFIX cc: &lt;http://web.resource.org/cc/&gt; PREFIX pgterms: &lt;http://www.gutenberg.org/rdfterms/&gt; PREFIX dcmitype: &lt;http://purl.org/dc/dcmitype/&gt; SELECT ?title ?author WHERE { ?book dc:title ?title ; dc:creator ?author } LIMIT 10 $ ./tdbquery --loc=/var/db/gutenberg/ --file=gutenquery.tq ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | title | author | ====================================================================================================================================================================== | "The Belgian Curtain\nEurope after Communism"^^rdf:XMLLiteral | "Vaknin, Samuel, 1961-"^^rdf:XMLLiteral | | "Fairy Tales; Their Origin and Meaning\nWith Some Account of Dwellers in Fairyland"^^rdf:XMLLiteral | "Bunce, John Thackray, 1828-1899"^^rdf:XMLLiteral | | "The World English Bible (WEB): Zephaniah"^^rdf:XMLLiteral | "Anonymous"^^rdf:XMLLiteral | | "Lectures of Col. R. G. Ingersoll - Latest"^^rdf:XMLLiteral | "Ingersoll, Robert Green, 1833-1899"^^rdf:XMLLiteral | | "Selections from Erasmus\nPrincipally from his Epistles"^^rdf:XMLLiteral | "Erasmus, Desiderius, 1469-1536"^^rdf:XMLLiteral | | "East and West\nPoems"^^rdf:XMLLiteral | "Harte, Bret, 1836-1902"^^rdf:XMLLiteral | | "The Enormous Room"^^rdf:XMLLiteral | "Cummings, E. E. (Edward Estlin), 1894-1962"^^rdf:XMLLiteral | | "The Enormous Room"^^rdf:XMLLiteral | _:b0 | | "Actes et Paroles, Volume 4\nDepuis l'Exil 1876-1885"^^rdf:XMLLiteral | "Hugo, Victor, 1802-1885"^^rdf:XMLLiteral | | "L'ÃŽle Des Pingouins"^^rdf:XMLLiteral | "France, Anatole, 1844-1924"^^rdf:XMLLiteral | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- </code></pre> <p>A typical entry from PG looks like this, although not all fields are present in all records:</p> <pre><code>&lt;pgterms:etext rdf:ID="etext7250"&gt; &lt;dc:publisher&gt;&amp;pg;&lt;/dc:publisher&gt; &lt;dc:title rdf:parseType="Literal"&gt;A Connecticut Yankee in King Arthur's Court, Part 9.&lt;/dc:title&gt; &lt;dc:creator rdf:parseType="Literal"&gt;Twain, Mark, 1835-1910&lt;/dc:creator&gt; &lt;pgterms:friendlytitle rdf:parseType="Literal"&gt;A Connecticut Yankee in King Arthur's Court, Part &lt;/pgterms:friendlytitle&gt; &lt;dc:language&gt;&lt;dcterms:ISO639-2&gt;&lt;rdf:value&gt;en&lt;/rdf:value&gt;&lt;/dcterms:ISO639-2&gt;&lt;/dc:language&gt; &lt;dc:subject&gt; &lt;rdf:Bag&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Americans -- Great Britain -- Fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Arthurian romances -- Adaptations&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Britons -- Fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Fantasy fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Kings and rulers -- Fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Knights and knighthood -- Fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Satire&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;rdf:li&gt;&lt;dcterms:LCSH&gt;&lt;rdf:value&gt;Time travel -- Fiction&lt;/rdf:value&gt;&lt;/dcterms:LCSH&gt;&lt;/rdf:li&gt; &lt;/rdf:Bag&gt; &lt;/dc:subject&gt; &lt;dc:subject&gt;&lt;dcterms:LCC&gt;&lt;rdf:value&gt;PS&lt;/rdf:value&gt;&lt;/dcterms:LCC&gt;&lt;/dc:subject&gt; &lt;dc:created&gt;&lt;dcterms:W3CDTF&gt;&lt;rdf:value&gt;2004-07-07&lt;/rdf:value&gt;&lt;/dcterms:W3CDTF&gt;&lt;/dc:created&gt; &lt;dc:rights rdf:resource="&amp;lic;" /&gt; </code></pre> <p></p> <p>In addition to, e.g. dc:author and dc:title, I'd like to get the value from the attribute of pgterms:etext rdf:ID="STUFF IN HERE":</p> <pre><code>&lt;pgterms:etext rdf:ID="etext7250"&gt; </code></pre> <p>As well as combining the entries in the list under dc:subject, etc. Basically, provide all the info on this book as a single coherent entry via the command-line query.</p> <p>So, my questions:</p> <ol> <li>How can I combine the attribute value from pg:eterms rdf:ID with the rest of the query?</li> <li>How can I combine the entries under dc:subject's list into one string?</li> <li>Since not all fields show up for every record, should I use the OPTIONAL() clause to surround fields that don't always appear?</li> <li>How can I limit my query based on a user-specified string? Am I supposed to use FILTER() for that?</li> </ol> <p>Thank you so much. I have been able to construct queries to get single-layer information, but anything beyond that, attributes etc. are nigh inscrutable to me. This is much different to standard SQL, and a much more involved project than I thought at first.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload