{"id":52,"date":"2015-06-22T15:57:40","date_gmt":"2015-06-22T15:57:40","guid":{"rendered":"http:\/\/cors1601.unl.edu\/cdrhdev\/?p=52"},"modified":"2025-10-06T14:28:27","modified_gmt":"2025-10-06T19:28:27","slug":"rdf-sparql-1","status":"publish","type":"post","link":"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-1\/","title":{"rendered":"Figuring Out RDF and SPARQL: Part I Triples"},"content":{"rendered":"<p>[Originally posted by Jessica Dussault, June 22, 2015 on Github Pages]<\/p>\n<p>Linked Data. The Semantic Web. A lot of those terms have been rattling around in my brain for years, picked up from various digital humanities events and lectures. We started on a new project that hopes to use linked data to analyze relationships between hundreds of individuals. Theoretically, I understood what this meant, but practically I had absolutely no idea how to start implementing it.<\/p>\n<p>I felt lost for a few days as I wallowed through lots of high level articles that all gave me the same introduction or as I got stuck in the details of software I never should have looked at to begin with. I even got briefly lost down a wikipedia rabbit hole of grammar when I looked up \u201cpredicate,\u201d since that word comes up a lot in linked data. I felt like I was missing a page in the owner\u2019s manual. Where was the \u201cQuick Setup\u201d chapter?<\/p>\n<div class=\"img_caption\">\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 445px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-144\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/grammar.jpg\" alt=\"Sentence diagram of &quot;Has the programmer been enjoying reading about predicates?&quot;\" width=\"445\" height=\"230\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/grammar.jpg 445w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/grammar-300x155.jpg 300w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">The programmer has NOT been enjoying reading about predicates, thanks<\/figcaption><\/figure>\n<\/div>\n<div class=\"img_caption\">What follows is certainly not the best introduction to linked data, but it is the kind of information that I was looking for as a step between beginning overviews and \u201cso now that you\u2019re all set up\u2026\u201d articles. The next few blog posts are, essentially \u201chow to actually set up some RDF.\u201d But first, the obligatory post on what it is.<\/div>\n<h2 id=\"okay-so-what-are-rdfs-and-owls\">Okay, so what are RDFs and OWLs?<\/h2>\n<p>Great question! Think of a relational database. It can do a lot of things, but if you put a bunch of people into it and then asked \u201cfind everybody related to person A (and HOW they are related), then find everybody that is related to all of THOSE people, too (as well as the nature of their relationship)\u201d it would get\u2026.complicated. This is where RDF shines.<\/p>\n<p>RDFs (Resource Description Frameworks) use a model based on \u201ctriples.\u201d Triples follow an object\u00a0\u00bb predicate\u00a0\u00bb subject format.<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>Sisko &gt;&gt; is on the show &gt;&gt; DS9\nSisko &gt;&gt; is rank &gt;&gt; captain\nPicard &gt;&gt; is rank &gt;&gt; captain\nPicard &gt;&gt; is on the show &gt;&gt; TNG\nDax &gt;&gt; is rank &gt;&gt; lt commander\nDax &gt;&gt; is on the show &gt;&gt; DS9\n<\/code><\/pre>\n<\/div>\n<div class=\"img_caption\">\n<figure id=\"attachment_147\" aria-describedby=\"caption-attachment-147\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-147\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/menagerie.jpg\" alt=\"Scene from The Menagerie\" width=\"600\" height=\"350\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/menagerie.jpg 600w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/menagerie-300x175.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-147\" class=\"wp-caption-text\">It&#8217;s okay to use Star Trek examples because RDF exists in Star Trek, too, as a Reality Distortion Field.<\/figcaption><\/figure>\n<p><!-- image source: http:\/\/www.razorfine.com\/wp-content\/uploads\/2014\/08\/star-trek-the-menagerie-02.jpg --><\/p>\n<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">From the above information one could write queries like \u201cfind all the captains,\u201d \u201clist the characters that appear on DS9,\u201d or \u201cfind all of the unique shows that a crew member appears on.\u201d But those questions aren\u2019t terribly difficult to do in a more familiar relational database model. Let\u2019s make it a little more interesting.<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>Dax &gt;&gt; served with &gt;&gt; Worf\nDax &gt;&gt; is married to &gt;&gt; Worf\nWorf &gt;&gt; served with &gt;&gt; Dax\nWorf &gt;&gt; is married to &gt;&gt; Dax\nPicard &gt;&gt; served with &gt;&gt; Worf\nWorf &gt;&gt; served with &gt;&gt; Picard\nPicard &gt;&gt; has met &gt;&gt; Sisko\nSisko &gt;&gt; has met &gt;&gt; Picard\nDax &gt;&gt; served with &gt;&gt; Sisko\nSisko &gt;&gt; served with &gt;&gt; Dax\n(etc)\n<\/code><\/pre>\n<\/div>\n<p>Now you could ask a question like \u201cFind all the people that Picard knows and then find all the people that THEY know (excluding the original person).\u201d You would get something like the following from that query:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>Picard | served with | Worf  | served with   | Dax\nPicard | served with | Worf  | is married to | Dax\nPicard | served with | Worf  | served with   | Sisko\nPicard | has met     | Sisko | served with   | Worf \nPicard | has met     | Sisko | served with   | Dax \n<\/code><\/pre>\n<\/div>\n<div class=\"img_caption\">\n<figure id=\"attachment_145\" aria-describedby=\"caption-attachment-145\" style=\"width: 554px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-145\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/picard_network.jpg\" alt=\"Picard's network, given this small dataset.\" width=\"554\" height=\"383\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/picard_network.jpg 554w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/picard_network-300x207.jpg 300w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><figcaption id=\"caption-attachment-145\" class=\"wp-caption-text\">A basic visualization of our findings.<\/figcaption><\/figure>\n<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">Though, to my knowledge, Picard has never met Dax, it would appear that they run in the same circles. This is a fairly small dataset, but if we had more crew members described in the triples, we could start constructing webs of relationships.<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">\n<figure id=\"attachment_146\" aria-describedby=\"caption-attachment-146\" style=\"width: 515px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-146\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/kirk.jpg\" alt=\"Kirk, Sisko, and Uhura in everybody's favorite DS9 episode, Trials and Tribble-ations\" width=\"515\" height=\"384\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/kirk.jpg 515w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/kirk-300x224.jpg 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><figcaption id=\"caption-attachment-146\" class=\"wp-caption-text\">A larger sampling of data would reveal that Sisko has met Kirk and Uhura. I bet you didn\u2019t remember that<\/figcaption><\/figure>\n<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">You can write very specific queries (\u201chow is Worf related to Dax?\u201d) or you can write very broad queries to scoop in a lot of results (\u201cgive me a list of every one-to-one relationship\u201d) or something in between (\u201ctell me what you know about Sisko\u201d).<\/div>\n<p>Of course, writing the triples doesn\u2019t look nearly so nice as my arrow delineated examples above. Here is an example of what one entry from the <a href=\"http:\/\/earlywashingtondc.org\/\">Oh Say Can You See<\/a> data looks like at this phase of the project.<\/p>\n<p>An excerpt from an RDF file<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;rdf:RDF xmlns:rdf=\"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#\" xmlns:oscys=\"http:\/\/server.unl.edu\/rdf\/oscys.owl#\"&gt;\n  &lt;rdf:Description rdf:about=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000056\"&gt;\n    &lt;rdf:type&gt;person&lt;\/rdf:type&gt;\n    &lt;oscys:fullName&gt;Queen, Louisa&lt;\/oscys:fullName&gt;\n    &lt;oscys:sex&gt;female&lt;\/oscys:sex&gt;\n    &lt;oscys:childOf rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000057\"\/&gt;\n    &lt;oscys:enslavedBy rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000058\"\/&gt;\n    &lt;oscys:petitionerAgainst rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000058\"\/&gt;\n    &lt;oscys:clientOf rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000001\"\/&gt;\n    &lt;oscys:judgedBy rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000004\"\/&gt;\n    &lt;oscys:judgedBy rdf:resource=\"http:\/\/server.unl.edu\/rdf\/oscys_test#per.000063\"\/&gt;\n  &lt;\/rdf:Description&gt;\n&lt;\/rdf:RDF&gt;<\/pre>\n<p>Well, okay, that looks way more complicated than the examples above. What it is really saying is the following:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>person 000056 &gt;&gt; is a &gt;&gt; person\nperson 000056 &gt;&gt; is named &gt;&gt; Queen, Louisa\nperson 000056 &gt;&gt; sex is &gt;&gt; female\nperson 000056 &gt;&gt; is a child of &gt;&gt; person 000057\n(etc)\n<\/code><\/pre>\n<\/div>\n<p>It looks a lot more complicated because it is using a mixture of literals and resources. Literals are just straight up text and numbers. An example above is the person\u2019s fullName: \u201cQueen, Louisa.\u201d Resources are the URIs that point at other entries in the RDF document (or even in other RDF documents). If you wanted to reference this particularly person, you would use the URI with #per.000056 on the end. You could have defined the references to other people are literals like \u201cper.000004\u201d but then the magic of linked data would be lost. Its power comes from knowing that the childOf relationship is one specific person and having access to the relationships and descriptions of that person as well. So perhaps the above translation would be more accurate if we said:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>http:\/\/path#person000056 &gt;&gt; is a child of &gt;&gt; http:\/\/path#person000057\n<\/code><\/pre>\n<\/div>\n<p>But wait, there\u2019s just one more detail in the RDF that we can\u2019t overlook. There is a namespace \u201coscys\u201d before most of the lines describing the person. This namespace is defining the predicates. That is to say, one can write down \u201cchildOf\u201d wherever they like but that doesn\u2019t mean anything to a computer. In fact, it might not mean a ton to hu-mans like us out of context, either. All of those predicates can be described in what I have been thinking of as a schema file, but which the internet likes to call a \u201contological\u201d file. This is where OWLs come in.<\/p>\n<div class=\"img_caption\">\n<figure id=\"attachment_148\" aria-describedby=\"caption-attachment-148\" style=\"width: 362px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-148\" src=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/owl.jpg\" alt=\"An owl and non ontological owl\" width=\"362\" height=\"288\" srcset=\"https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/owl.jpg 362w, https:\/\/cdrhdev.unl.edu\/log\/wp-content\/uploads\/2015\/06\/owl-300x239.jpg 300w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><figcaption id=\"caption-attachment-148\" class=\"wp-caption-text\">Fun fact, OWL stands for Web Ontology Language. That doesn\u2019t actually spell \u2018OWL\u2019 but I assume they wanted to use it because there aren\u2019t many cute images of WOLs.<\/figcaption><\/figure>\n<p><!-- source of above image: http:\/\/www.aktifmag.com\/wp-content\/uploads\/2013\/02\/cute-little-owl-Wallpaper__yvt2.jpg --><\/p>\n<\/div>\n<div class=\"img_caption\"><\/div>\n<div class=\"img_caption\">An excerpt from the Oh Say Can You See OWL file:<\/div>\n<div class=\"img_caption\">\n<pre class=\"lang:xhtml decode:true\">&lt;owl:ObjectProperty rdf:about=\"#parentOf\"&gt;\n  &lt;rdfs:domain rdf:resource=\"#Person\"\/&gt;\n  &lt;rdfs:range rdf:resource=\"#Person\"\/&gt;\n  &lt;owl:Inverseof rdf:resource=\"childOf\"\/&gt;\n  &lt;rdfs:subPropertyOf rdf:resource=\"#familyOf\"\/&gt;\n&lt;\/owl:ObjectProperty&gt;<\/pre>\n<p>To connect them up, just make sure that you\u2019re referencing the OWL file at the top of your RDF file. In the example RDF file, you\u2019ll see that it is assigned to the namespace \u201coscys.\u201d<\/p>\n<\/div>\n<p>Let\u2019s break down the OWL example:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>#parentOf &gt;&gt; domain &gt;&gt; #Person\n#parentOf &gt;&gt; range &gt;&gt; #Person\n#parentOf &gt;&gt; inverseOf &gt;&gt; childOf\n#parentOf &gt;&gt; subPropertyOf &gt;&gt; #familyOf\n<\/code><\/pre>\n<\/div>\n<p>That means that now we know that anybody joined up as the oscys:childOf predicate will return an object that should be the oscys:parentOf the original person. We could also do a search for all the predicates that are #familyOf and use those results to find all family relationships for a single person. Pretty cool stuff, right?<\/p>\n<p>Thus endeth the crash course in what kind of things RDF does. Next up, how to actually start running the queries!<\/p>\n<ul>\n<li>Figuring out RDF and SPARQL: Part I Triples<\/li>\n<li><a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-2\/\">Figuring out RDF and SPARQL: Part II Getting Set Up<\/a><\/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, June 22, 2015 on Github Pages] Linked Data. The Semantic Web. A lot of those terms have been rattling around in my brain for years, picked up from various digital humanities events and lectures. We started on a new project that hopes to use linked data to analyze relationships between&hellip;<\/p>\n <a href=\"https:\/\/cdrhdev.unl.edu\/log\/2015\/rdf-sparql-1\/\" title=\"Figuring Out RDF and SPARQL: Part I Triples\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Figuring Out RDF and SPARQL: Part I Triples<\/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":[14,12],"class_list":["entry","author-jdussault","post-52","post","type-post","status-publish","format-standard","category-introduction","category-linked-data","tag-owl","tag-rdf"],"_links":{"self":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/52","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=52"}],"version-history":[{"count":11,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/posts\/52\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdrhdev.unl.edu\/log\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}