<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; semweb</title>
	<atom:link href="http://www.craiget.com/tags/semweb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.craiget.com</link>
	<description>In which I write mostly about programming and that sort of thing</description>
	<lastBuildDate>Fri, 20 Aug 2010 17:32:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SPARQLing The Highest Point in Every US State</title>
		<link>http://www.craiget.com/2009/02/sparqling-the-highest-point-in-every-us-state/</link>
		<comments>http://www.craiget.com/2009/02/sparqling-the-highest-point-in-every-us-state/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 04:38:31 +0000</pubDate>
		<dc:creator>craiget</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[arc2]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[semweb]]></category>
		<category><![CDATA[sparql]]></category>

		<guid isPermaLink="false">http://www.craigethomas.com/blog/?p=37</guid>
		<description><![CDATA[In a previous post, I mentioned that it should be pretty easy to use SPARQL to make a map of the highest point in each of the 50 US States. Having written that, I thought I should maybe actually, you know, try it. The following chunk of code uses ARC2, an rdf/semantic web library for [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, I mentioned that it should be pretty easy to use SPARQL to make a map of the highest point in each of the 50 US States. Having written that, I thought I should maybe actually, you know, <em>try it</em>.</p>
<p>The following chunk of code uses <a href="http://arc.semsol.org/">ARC2</a>, an rdf/semantic web library for PHP to query the <a href="http://dbpedia.org/snorql/">dbpedia</a> endpoint and then put the results on a Google Map.</p>
<p>To try this out, you need to:</p>
<ol>
<li>Have a functional PHP installation</li>
<li>Download ARC2 into your web path (no setup required)</li>
<li>Set the path to ARC in the code below</li>
<li>Get a Google Maps API Key (free)</li>
<li>Set your API key in the code below</li>
<li>Run</li>
</ol>
<p>Note that this is a demo and is written to be easy to run &#8211; a real application might separate the data logic from the webpage and make more sophisticated use of Javascript/Google Maps API.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//include ARC2 libraries</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path/to/ARC2.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//instantiate a RemoteStore</span>
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remote_store_endpoint'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://dbpedia.org/sparql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> ARC2<span style="color: #339933;">::</span><span style="color: #004000;">getRemoteStore</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//build the SPARQL query</span>
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'
PREFIX dbpedia2: &lt;http://dbpedia.org/property/&gt;
PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt;
PREFIX geo: &lt;http://www.w3.org/2003/01/geo/wgs84_pos#&gt;
SELECT ?state ?mtn ?lat ?long
WHERE {
?state skos:subject &lt;http://dbpedia.org/resource/Category:States_of_the_United_States&gt; .
?state dbpedia2:highestpoint ?mtn .
?mtn geo:lat ?lat .
?mtn geo:long ?long
}
'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//process the results</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rows'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$state</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'state'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://dbpedia.org/resource/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mtn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mtn'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://dbpedia.org/resource/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lng</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'long'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$state</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mtn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
&lt;title&gt;Google Maps JavaScript API Example&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key=YOUR_KEY&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById(&quot;map_canvas&quot;));
map.setCenter(new GLatLng(37.4419, -122.1419), 3);
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl());
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//populate map with results</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$state</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mtn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;map.addOverlay(new GMarker(new GLatLng(<span style="color: #006699; font-weight: bold;">$lat</span>,<span style="color: #006699; font-weight: bold;">$lng</span>), {title: '<span style="color: #006699; font-weight: bold;">$mtn</span>'}));n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload=&quot;initialize()&quot; onunload=&quot;GUnload()&quot;&gt;
&lt;div id=&quot;map_canvas&quot; style=&quot;width: 100%; height: 100%&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>* Using substr() to chop off &#8220;http://dbpedia.org/resource/&#8221; from the names is probably cheating. I think you&#8217;re supposed to use rdfs:label@en instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.craiget.com/2009/02/sparqling-the-highest-point-in-every-us-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anatomy of a SPARQL Query Part 1 &#8211; Select</title>
		<link>http://www.craiget.com/2009/02/anatomy-of-a-sparql-query-part-1-select/</link>
		<comments>http://www.craiget.com/2009/02/anatomy-of-a-sparql-query-part-1-select/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 13:28:12 +0000</pubDate>
		<dc:creator>craiget</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[semweb]]></category>
		<category><![CDATA[sparql]]></category>

		<guid isPermaLink="false">http://www.craigethomas.com/blog/?p=31</guid>
		<description><![CDATA[..in which I try to describe a few aspects of the SPARQL query language in plain(er) English. SPARQL is the query language for the semantic web and is a W3C recommendation (that is, practically a standard). To issue a query, you need an endpoint. All my examples will be using the DBPedia endpoint. Open that [...]]]></description>
			<content:encoded><![CDATA[<p><em>..in which I try to describe a few aspects of the SPARQL query language in plain(er) English.</em></p>
<div class="level2">
<p>SPARQL is the query language for the semantic web and is a <acronym title="World Wide Web Consortium">W3C</acronym> recommendation (that is, practically a standard). To issue a query, you need an endpoint. All my examples will be using the <a class="urlextern" title="http://dbpedia.org/snorql/" rel="nofollow" href="http://dbpedia.org/snorql/">DBPedia</a> endpoint. Open that page in a new window. You should be able to copy-paste any query on this page into DBpedia and play around with the results.</p>
<p>The basic thing you can do with SPARQL is SELECT. Let&#8217;s start by getting a list of US States:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, it is important to note that the choice of variable names is arbitrary. You could have chosen <em>?s</em> or even <em>?turnip</em> just as easily. This query will give you the exact same results:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?turnip <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?turnip skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Okay, well that&#8217;s pretty sweet. So let&#8217;s learn something interesting about the nifty-fifty &#8211; how about state capitals?</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?capital <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:capital ?capital
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>So that works. But WTF are <em>skos</em> and <em>dbpedia2</em>? They are called <em>namespaces</em>. The short story is that to be useful in a SPARQL query, everything needs a unique identifier. URLs (like a web address) provide just that. If two things have the same <acronym title="Uniform Resource Locator">URL</acronym>, they are <em>exactly</em> the same. Unfortunately, URLs are often quite long. To save typing and space on the screen, <em>skos</em> and <em>dbpedia2</em> and <em>rdf</em> are all abbreviations. When you see <em>skos</em>, it actually means <a class="urlextern" title="http://www.w3.org/2004/02/skos/core#" rel="nofollow" href="http://www.w3.org/2004/02/skos/core#">http://www.w3.org/2004/02/skos/core#</a> and when you see <em>skos:subject</em> it means <a class="urlextern" title="http://www.w3.org/2004/02/skos/core#subject" rel="nofollow" href="http://www.w3.org/2004/02/skos/core#subject">http://www.w3.org/2004/02/skos/core#subject</a>.</p>
<p>Namespaces &#8211; well that&#8217;s all very interesting, but how do you know that the property is called <em>dbpedia2:capital</em> instead of, say, <em>dbpedia2:stateCapital</em>? Happily, there is a query that gives a list of all the properties for a particular subject. In this case, the subject is Alaska:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?prop <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Alaska<span style="color: #66cc66;">&gt;</span> ?prop ?obj
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Of course, you don&#8217;t have to provide the subject. You could provide the predicate or the object instead. Now, on with the show. Let&#8217;s look at the State Flower:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?flower <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:flower ?flower
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Uh oh &#8211; there are a few states missing! Awesome as it is, DBPedia doesn&#8217;t know everything. In this case, some states are missing the <em>dbpedia2:flower</em> property. Fortunately, there&#8217;s the OPTIONAL keyword:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?flower <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  OPTIONAL <span style="color: #66cc66;">&#123;</span> ?state dbpedia2:flower ?flower <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Okay, that&#8217;s better. We don&#8217;t have 50 flowers, but at least we still have all the states. So which state has the biggest population? The ORDER BY clause can help:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?pop <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:poprank ?pop
<span style="color: #66cc66;">&#125;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> ?pop</pre></div></div>

<p>Go ahead and try it. It works, but not exactly, right? The problem is that DBPedia&#8217;s dbpedia:poprank property is not always an integer value. What does that mean? It means that sometimes a “1” isn&#8217;t a “1”, sometimes it is a “1”^^dbpedia:units/Rank. So what can you do about it? In this case, you can just cast it to an integer. This query will give you the states in order of population:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?pop <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:poprank ?pop
<span style="color: #66cc66;">&#125;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> xsd:int<span style="color: #66cc66;">&#40;</span>?pop<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>So that&#8217;s useful and there are a number of conversion functions to do similar things. Now here&#8217;s something a little different &#8211; this query gets the latitude and longitude of the highest point in every state. With a little bit of scripting, you could plot these on a map:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">PREFIX geo: <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>www<span style="color: #66cc66;">.</span>w3<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2003</span><span style="color: #66cc66;">/</span>01<span style="color: #66cc66;">/</span>geo<span style="color: #66cc66;">/</span>wgs84_pos<span style="color: #808080; font-style: italic;">#&gt;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?mtn ?lat ?long <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:highestpoint ?mtn <span style="color: #66cc66;">.</span>
  ?mtn geo:lat ?lat <span style="color: #66cc66;">.</span>
  ?mtn geo:long ?long
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Here it was necessary to declare the <em>geo</em> namespace using the PREFIX keyword. The DBPedia SPARQL endpoint already declares a bunch of namespaces for your convenience, but <em>geo</em> is not among them so we need to add it in. It is worth noting that the name <em>geo</em> is arbitary &#8211; you could have called it <em>fred</em>. Namespaces in widespread use have developed conventional prefixes that should be used to prevent confusion.</p>
<p>SPARQL also supports a limited set of comparison operations using the FILTER keyword. The query below lists states that joined after January 1st, 1850:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> ?state ?date <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#123;</span>
  ?state skos:subject <span style="color: #66cc66;">&lt;</span>http:<span style="color: #66cc66;">//</span>dbpedia<span style="color: #66cc66;">.</span>org<span style="color: #66cc66;">/</span>resource<span style="color: #66cc66;">/</span>Category:States_of_the_United_States<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">.</span>
  ?state dbpedia2:admittancedate ?date
  FILTER <span style="color: #66cc66;">&#40;</span> ?date <span style="color: #66cc66;">&gt;</span> <span style="color: #ff0000;">&quot;1850-01-01T00:00:00Z&quot;</span>^^xsd:dateTime <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The recommendation lists a number of comparisons <a class="urlextern" title="http://www.w3.org/TR/rdf-sparql-query/#SparqlOps" rel="nofollow" href="http://www.w3.org/TR/rdf-sparql-query/#SparqlOps">http://www.w3.org/TR/rdf-sparql-query/#SparqlOps</a>, though in practice these may not be 100% available in a particular implementation.</p>
<p>I&#8217;ll be back with Part 2 soon. As always, I hope this will be useful, so comments/feedback are always welcome &#8211; especially from people who can correct any mistakes printed here.</p>
<p>* Update: Here&#8217;s Part 2 &#8211; <a href="http://www.craiget.com/2009/02/sparqling-the-highest-point-in-every-us-state/">SPARQLing The Highest Point in Every US State</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.craiget.com/2009/02/anatomy-of-a-sparql-query-part-1-select/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
