{"id":54,"date":"2015-07-06T18:08:31","date_gmt":"2015-07-06T18:08:31","guid":{"rendered":"http:\/\/cors1601.unl.edu\/cdrhdev\/?p=54"},"modified":"2025-10-06T14:38:37","modified_gmt":"2025-10-06T19:38:37","slug":"rdf-sparql-2","status":"publish","type":"post","link":"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-2\/","title":{"rendered":"Figuring out RDF and SPARQL: Part II Getting Set Up"},"content":{"rendered":"<p>[Originally posted by Jessica Dussault, July 6, 2015 on Github Pages]<\/p>\n<p>In <a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-1\/\">Part I<\/a> of the RDF crash course, I provided some examples of the types of information that you can get out of an RDF file. I stopped just at the point where the floor was falling out from under me in other tutorials. Right after explaining the basics of describing the data, suddenly tutorials would start throwing down mad SPARQL queries, SPARQL being to RDF what SQL is to relational databases. But\u2026.how? You don\u2019t just magically start querying a document. That\u2019s like showing people some sample data and then saying \u201cnow try this SQL!\u201d That won\u2019t get you anywhere if you don\u2019t have a database set up and even if you have a database, you have to know how to send SQL its way.<\/p>\n<p>At this point, linked data life became confusing. Did I need an RDF server? What about the \u201ctriple store\u201d I kept seeing in articles? I wasn\u2019t even confident that the RDF or the OWL files were correctly created, yet. I was pretty sure that I was going to spend a few hours learning how to load them into some software only to get errors and have no idea which moving piece (or pieces) was causing the trouble.<\/p>\n<figure id=\"attachment_153\" aria-describedby=\"caption-attachment-153\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-153\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/mamp.png\" alt=\"MAMP Icon\" width=\"256\" height=\"256\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/mamp.png 256w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/mamp-150x150.png 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><figcaption id=\"caption-attachment-153\" class=\"wp-caption-text\">What I felt like I was looking for, as an RDF newcomer, was something to hold my hand like MAMP.<br \/>This is the last time that you&#8217;ll see a non-reptile in this blog post, so prepare yourself.<\/figcaption><\/figure>\n<h2 id=\"the-moment-of-englightenment\">The Moment of Enlightenment<\/h2>\n<p>It turns out that you don\u2019t need any fancy servers or technologies to test some rdf out. There are nice people on the internet who have already set up those types of utilities for you, like the <a href=\"http:\/\/sparql.org\/sparql.html\">SPARQLer<\/a> from sparql.org. All you need is a RDF document (rdf, ttl, n3, etc) accessible via the web. I readied my rdf file on a server and took aim with the faithful <a href=\"http:\/\/sparql.org\/sparql.html\">SPARQLer<\/a>. \u201cGive me all the subjects, predicates, and objects? Question mark?\u201d I asked it nervously in my best beginner SPARQL. It responded with errors about our RDF file. It could see the file and read it as rdf enough to give me errors! The breakthrough had been made.<\/p>\n<h2 id=\"some-reptile-themed-examples\">Some Reptile Themed Examples<\/h2>\n<p>Before we start trying to use our own files, let\u2019s find a ready to go RDF file to see how this works. The <a href=\"http:\/\/www.bbc.com\/earth\/uk\">BBC\u2019s Nature<\/a> web pages have a nice system where you can <a href=\"http:\/\/www.bbc.co.uk\/nature\/feedsanddata\">simply add different extensions<\/a> to the URIs to get different formats back, which is perfect. Today, to celebrate the awesomeness of marine reptiles, we will be learning about ichthyosaurs!<\/p>\n<figure id=\"attachment_152\" aria-describedby=\"caption-attachment-152\" style=\"width: 512px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-152\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ichthyosaurs.jpg\" alt=\"Illustration of ichthyosaurs\" width=\"512\" height=\"288\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ichthyosaurs.jpg 512w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ichthyosaurs-300x169.jpg 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><figcaption id=\"caption-attachment-152\" class=\"wp-caption-text\">Today&#8217;s proud RDF mascot brought to you by the Mesozoic Era.<\/figcaption><\/figure>\n<p><!-- source: http:\/\/www.dinosaurfact.net\/backgrounds\/aa1-1366-768.jpg -->Check out the page that the BBC has for ichthyosaurs at <a href=\"http:\/\/www.bbc.co.uk\/nature\/life\/Ichthyosaur\">http:\/\/www.bbc.co.uk\/nature\/life\/Ichthyosaur<\/a>. Looks pretty nice, sure, but no obvious linked data here. Now, if you add .rdf to the end of the URI, the BBC gives you RDF rather than an HTML file. If you would like to look at it, you should be able to open the downloaded file in a text editor: <a href=\"http:\/\/www.bbc.co.uk\/nature\/life\/Ichthyosaur.rdf\">Ichthyosaur RDF<\/a>. Because the RDF is available online, we can access it via the <a href=\"http:\/\/sparql.org\/sparql.html\">SPARQLer<\/a>.<\/p>\n<div class=\"img_caption\">\n<figure id=\"attachment_151\" aria-describedby=\"caption-attachment-151\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-151\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/sparql_ich_query.jpg\" alt=\"Screenshot showing a Sparql Query for BBC ichthyosaurs at sparql.org\" width=\"540\" height=\"550\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/sparql_ich_query.jpg 540w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/sparql_ich_query-295x300.jpg 295w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-151\" class=\"wp-caption-text\">Plugging in a basic query<\/figcaption><\/figure>\n<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">Very quickly I\u2019ll run through what the above query is asking, for those of you unfamiliar with SPARQL.<\/div>\n<div class=\"img_caption\"><\/div>\n<p><strong>SELECT<\/strong>: Select any variable that you can find<\/p>\n<p><strong>FROM<\/strong>: This is the rdf file that we are querying<\/p>\n<p><strong>WHERE<\/strong>: Things with question marks in front are variables. We\u2019ll get into it more in a later post, but for now know that this is asking \u201cgive me the subject, predicate, and object of everything.\u201d Or, if you prefer, \u201cgive me everything and how that is connected to anything else.\u201d The names that you use do not matter, so feel free to write something like:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>?ichthyosaurs ?are ?cool\n<\/code><\/pre>\n<\/div>\n<p>The only problem with that being that then your results won\u2019t make a ton of sense to read, hence why I stuck with the subject, predicate, object naming conventions.<\/p>\n<p>Note that I also have \u201ctext\u201d selected for my output. Some sparql utilities have \u201chtml\u201d instead of text, but essentially I\u2019m picking that because it\u2019s pretty easy to read at a glance. Feel free to request JSON, XML, etc. The results will be the same but they will be organized differently. Okay, let\u2019s click \u201cGet Results\u201d and see what happens! Here is a sample of what is returned:<\/p>\n<div class=\"table_scroll\">\n<table>\n<thead>\n<tr>\n<th>s (subject)<\/th>\n<th>p (predicate)<\/th>\n<th>o (object)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt;http:\/\/www.bbc.co.uk\/programmes\/p00486xd#programme&gt;<\/td>\n<td>&lt;http:\/\/pURI.org\/ontology\/po\/subject&gt;<\/td>\n<td>&lt;http:\/\/www.bbc.co.uk\/nature\/order\/Ichthyosaur#order&gt;<\/td>\n<\/tr>\n<tr>\n<td>&lt;http:\/\/www.bbc.co.uk\/programmes\/p00486xd#programme&gt;<\/td>\n<td>&lt;http:\/\/pURI.org\/dc\/terms\/title&gt;<\/td>\n<td>\u201cA reptilian dolphin?\u201d<\/td>\n<\/tr>\n<tr>\n<td>&lt;http:\/\/www.bbc.co.uk\/nature\/26153424&gt;<\/td>\n<td>&lt;http:\/\/pURI.org\/dc\/terms\/description&gt;<\/td>\n<td>\u201cA rare fossil reveals how marine reptiles evolved to give birth to live young, say scientists.\u201d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>There are dozens more results, but let\u2019s just grab a few of them and figure out what they mean, starting with the first row. The subject is a URI. The predicate says that the URI is a subject of the site we were just querying. The next row says that the same programme has a title of \u201cA reptilian dolphin?\u201d If we type the URI into a browser we find that the link sends us to a page with a video titled, feel free to take a guess, \u201cA reptilian dolphin?\u201d If you would like to hear the soothing voice of Sir David Attenborough, <a href=\"http:\/\/www.bbc.co.uk\/programmes\/p00486xd#programme\">give it a watch<\/a>.<\/p>\n<p>The third result above is also a URI. It has a description which says \u201cA rare fossil reveals how marine reptiles evolved to give birth to live young, say scientists.\u201d Let\u2019s learn a little bit more about that. Go back to the query screen and put in that whole subject in the place of <code class=\"highlighter-rouge\">?s<\/code>.<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"language-sparql\" data-lang=\"sparql\">SELECT *\nFROM &lt;http:\/\/www.bbc.co.uk\/nature\/life\/Ichthyosaur.rdf&gt;\nWHERE {\n  &lt;http:\/\/www.bbc.co.uk\/nature\/26153424&gt; ?p ?o\n}<\/code><\/pre>\n<\/figure>\n<p>Now we get only four results and fewer columns. Why fewer columns? Because we specified the subject, so now there is no variable <code class=\"highlighter-rouge\">?s<\/code> to return with the results. We essentially said \u201cgive me all of the things related to the specific BBC nature item 26153424.\u201d Keep in mind that we are still only asking the original ichthyosaur rdf file that question.<\/p>\n<div class=\"table_scroll\">\n<table>\n<thead>\n<tr>\n<th>p (predicate)<\/th>\n<th>o (object)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt;http:\/\/xmlns.com\/foaf\/0.1\/primaryTopic&gt;<\/td>\n<td>&lt;http:\/\/www.bbc.co.uk\/nature\/order\/Ichthyosaur#order&gt;<\/td>\n<\/tr>\n<tr>\n<td>&lt;http:\/\/pURI.org\/dc\/terms\/description&gt;<\/td>\n<td>\u201cA rare fossil reveals how marine reptiles evolved to give birth to live young, say scientists.\u201d<\/td>\n<\/tr>\n<tr>\n<td>&lt;http:\/\/pURI.org\/dc\/terms\/title&gt;<\/td>\n<td>\u201cAncient reptile\u2019s birth fossilised\u201d<\/td>\n<\/tr>\n<tr>\n<td>&lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type&gt;<\/td>\n<td>&lt;http:\/\/xmlns.com\/foaf\/0.1\/Document&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Putting the subject we just specified into a browser sends us to an article titled <a href=\"http:\/\/www.bbc.co.uk\/nature\/26153424\">\u201cAncient reptile\u2019s birth fossilised\u201d<\/a>. As we might have predicted from our RDF query, the article talks about Ichthyosaurs, it\u2019s has a \u201ctype\u201d of document, and it discusses the birth of live young.<\/p>\n<p>This rabbit hole can go a long way. Some of the results lead to other rdf documents which can also be queried, like the page on <a href=\"http:\/\/www.bbc.co.uk\/nature\/life\/Ophthalmosaurus\">Ophthalmosaurus<\/a>, a type of ichthyosaur.<\/p>\n<figure id=\"attachment_150\" aria-describedby=\"caption-attachment-150\" style=\"width: 467px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-150\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ophthalmosaurus.jpg\" alt=\"Ophthalmosaurus eyeball\" width=\"467\" height=\"288\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ophthalmosaurus.jpg 467w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/ophthalmosaurus-300x185.jpg 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><figcaption id=\"caption-attachment-150\" class=\"wp-caption-text\">Why don&#8217;t you take a deep look into Ophthalmosaurus&#8217;s sparqling eyes?<\/figcaption><\/figure>\n<p><!-- source: http:\/\/ichef.bbci.co.uk\/naturelibrary\/images\/ic\/credit\/640x395\/o\/op\/ophthalmosaurus\/ophthalmosaurus_1.jpg --><\/p>\n<h2 id=\"how-to-query-your-rdf-with-online-sparql-resources\">How To Query Your RDF with Online SPARQL Resources<\/h2>\n<p>Here\u2019s a step by step guide to getting some queries going on your own linked data. If you\u2019re like me, you just want to test some things out before you worry too much about how you are going to query loads of things, but keep in mind that using someone else\u2019s SPARQL power won\u2019t help you if you are looking to do a lot of processing.<\/p>\n<p><strong>Step One<\/strong>: Get an RDF document. You could create your own, download some off the BBC\u2019s pages, find one elsewhere on the internet, etc. If you\u2019re using your own you may want to run it through a <a href=\"http:\/\/www.w3.org\/RDF\/Validator\/\">validator<\/a> before you start trying to query it. Also, keep in mind that it doesn\u2019t have to be a file with a .rdf extension, it could be a .ttl file or any other SPARQL ready linked data document.<\/p>\n<div class=\"img_caption\">\n<figure id=\"attachment_154\" aria-describedby=\"caption-attachment-154\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-154\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/turtle.jpg\" alt=\"Turtle with fish cleaning its neck\" width=\"500\" height=\"333\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/turtle.jpg 500w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/07\/turtle-300x200.jpg 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption id=\"caption-attachment-154\" class=\"wp-caption-text\">Validation will help you clean up your turtle (.ttl) files before you query them.<\/figcaption><\/figure>\n<p><!-- source: http:\/\/farm4.static.flickr.com\/3189\/2311658016_2907c40d0f.jpg --><\/div>\n<p><strong>Step Two<\/strong>: If your RDF file has any prefixes (basically namespaces) at the top that are from ontologies that you personally created, you will need to have those OWL files and whathaveyou at the ready as well. Otherwise, they should already be available on the web.<\/p>\n<p><strong>Step Three<\/strong>: Put your RDF and OWL files in a place that is accessible from the web. If you already have a website, upload them just like you would any of your other files and note the path. The tricky part here is that in numerous places throughout the RDF and OWL files, there are references to URIs, as you may have noticed from the ichthyosaur examples. If you cannot put the files at that exact path, you will have to find and replace all references with the URI where you just put the documents.<\/p>\n<p><strong>Step Four<\/strong>: Head to the <a href=\"http:\/\/sparql.org\/sparql.html\">SPARQLer<\/a>! Put in a basic query to see if everything is working correctly. You can either put your RDF file\u2019s location in the \u201cTarget Graph URI\u201d or you can use a \u201cFROM\u201d statement.<\/p>\n<figure class=\"highlight\">\n<pre><code class=\"language-sparql\" data-lang=\"sparql\">SELECT ?subject ?predicate ?object\nFROM &lt;http:\/\/server.unl.edu\/jessica\/oscys_test.rdf&gt;\nWHERE {\n  ?subject ?predicate ?object\n}<\/code><\/pre>\n<\/figure>\n<p><strong>Step Five<\/strong>: Pick the response format! I like text\/html when I\u2019m just messing around, but if you are going to be using the results for a script then you might want XML, CSV, or JSON results.<\/p>\n<p><strong>Step Six<\/strong>: View your sweet, sweet results. If you have an error, does it look like it is understandable?<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>Error 400: Failed to load URL http:\/\/www.bbc.co.uk\/naturefdfdafdafdafda.ttl\nFuseki - version 1.1.2\n<\/code><\/pre>\n<\/div>\n<p>If you got the above, you might want to make sure that the \u201cFROM\u201d line of your query is pointed at the right place. You may want to actually put the URI into your browser to make sure that you don\u2019t get a 400 error when you navigate there manually. If you\u2019re hosting the file yourself, make sure that the correct permissions exist for the file to be served up.<\/p>\n<p><strong>Step Seven<\/strong>: Do something cool with your data. Link your subjects out to other resources, learn about the relationships between items, create visualizations, generate pages, or whatever else you can dream up. In the next couple of posts, I\u2019ll talk about how we\u2019ve been using the RDF data for some network visualizations, queries, and scripts that we\u2019ve been using to move between spreadsheet entries to results.<\/p>\n<ul>\n<li><a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-1\/\">Figuring out RDF and SPARQL: Part I Triples<\/a><\/li>\n<li>Figuring out RDF and SPARQL: Part II Getting Set Up<\/li>\n<li><a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-3\/\">Figuring out RDF and SPARQL: Part III Some Queries<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>[Originally posted by Jessica Dussault, July 6, 2015 on Github Pages] In Part I of the RDF crash course, I provided some examples of the types of information that you can get out of an RDF file. I stopped just at the point where the floor was falling out from under me in other tutorials.&hellip;<\/p>\n <a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-2\/\" title=\"Figuring out RDF and SPARQL: Part II Getting Set Up\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Figuring out RDF and SPARQL: Part II Getting Set Up<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"Layout":"1c","footnotes":""},"categories":[10,9],"tags":[11,14,12,13],"class_list":["entry","author-jdussault","post-54","post","type-post","status-publish","format-standard","category-introduction","category-linked-data","tag-oscys","tag-owl","tag-rdf","tag-sparql"],"_links":{"self":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":12,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/54\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}