<?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>Beyond Search &#187; sparql</title>
	<atom:link href="http://www.guwendong.com/post/tag/sparql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.guwendong.com</link>
	<description>最好走的路越走越难，最难走的路越走越容易</description>
	<lastBuildDate>Tue, 31 Jan 2012 05:30:38 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Semantic Web: SPARQL——RDF查询语言</title>
		<link>http://www.guwendong.com/post/2006/semweb_intro_6.html</link>
		<comments>http://www.guwendong.com/post/2006/semweb_intro_6.html#comments</comments>
		<pubDate>Thu, 30 Nov 2006 19:19:11 +0000</pubDate>
		<dc:creator>guwendong</dc:creator>
				<category><![CDATA[语义网]]></category>
		<category><![CDATA[rdf]]></category>
		<category><![CDATA[semantic-web]]></category>
		<category><![CDATA[sparql]]></category>

		<guid isPermaLink="false">http://www.guwendong.com/post/2006/semweb_intro_6.html</guid>
		<description><![CDATA[SPARQL，和“sparkle”的发音一样，它是一种 RDF 查询语言，可以从 RDF 图中查询信息。在 W3C Technical Reports and Publications 页面上，我们可以看到，现在和 SPARQL 相关的共有三项内容：其中两个是 Candidate Recommendations（候选推荐），SPARQL Protocol for RDF 和 SPARQL Query Results XML Format；另外一个是 Word Drafts（工作草案），SPARQL Query Language for RDF。上了这个页面，基本上就已经说明这个要成为 W3C 的推荐标准了，就像 RDF 和 OWL 一样。而且，在 WWW2006 发言时，TimBL 也已经表示，随着 SPARQL 查询语言即将完成标准化，语义网已经具备了成功所需要的所有标准和技术，Web开发人员和内容创作人员可以开始使用这些语义语言了。
在 SPARQL 之前，已经有不少研究人员致力于开发针对 RDF 的查询语言，在这个网页  http://www.w3.org/2001/11/13-RDF-Query-Rules/ 上有一个比较完整的列表。SPARQL 是基于以前的 RDF 查询语言（如rdfDB、RDQL 和 SeRQL）发展而来的，拥有一些有价值的新特性，并且受到 Jena 开发团队的鼎立支持。Jena [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="分析互联网发展趋势 探索Web开发新策略" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ftech2ipo.com%2F42949%2F&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/03/14698336.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分析互联网发展趋势 探索Web开发新策略 (@tech2ipo)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[译记]语义网模式：语义技术概论（3）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.wentrue.net%2Fblog%2F%3Fp%3D45&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[译记]语义网模式：语义技术概论（3） (@wentrue)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Social Graph 与 Semantic Web" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2007%2Fsocial_graph_and_semantic_web.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Social Graph 与 Semantic Web</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Semantic Web: RDF实战" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro_5.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/04/1802134.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Semantic Web: RDF实战</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Semantic Web：语义网是如何运作的？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro_4.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/04/1802137.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Semantic Web：语义网是如何运作的？</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.w3.org/TR/rdf-sparql-query/">SPARQL</a>，和“sparkle”的发音一样，它是一种 RDF 查询语言，可以从 <a href="http://www.w3.org/RDF/">RDF</a> 图中查询信息。在 <a href="http://www.w3.org/TR/">W3C Technical Reports and Publications</a> 页面上，我们可以看到，现在和 SPARQL 相关的共有三项内容：其中两个是 Candidate Recommendations（候选推荐），<a href="http://www.w3.org/TR/2006/CR-rdf-sparql-protocol-20060406/">SPARQL Protocol for RDF</a> 和 <a href="http://www.w3.org/TR/2006/CR-rdf-sparql-XMLres-20060406/">SPARQL Query Results XML Format</a>；另外一个是 Word Drafts（工作草案），<a href="http://www.w3.org/TR/2006/WD-rdf-sparql-query-20061004/">SPARQL Query Language for RDF</a>。上了这个页面，基本上就已经说明这个要成为 W3C 的推荐标准了，就像 RDF 和 OWL 一样。而且，在 <a href="http://www2006.org/">WWW2006</a> 发言时，TimBL 也已经<a href="http://uk.builder.com/webdevelopment/design/0,39026630,39313738,00.htm">表示</a>，随着 <font>SPARQL 查询语言即将完成标准化</font>，<font>语义网已经具备了成功所需要的所有标准和技术，</font><font>Web开发人员和内容创作人员可以开始使用这些语义语言了。</font></p>
<p>在 SPARQL 之前，已经有不少研究人员致力于开发针对 RDF 的查询语言，在这个网页  <a href="http://www.w3.org/2001/11/13-RDF-Query-Rules/">http://www.w3.org/2001/11/13-RDF-Query-Rules/</a> 上有一个比较完整的列表。SPARQL 是基于以前的 RDF 查询语言（如rdfDB、RDQL 和 SeRQL）发展而来的，拥有一些有价值的新特性，并且受到 Jena 开发团队的鼎立支持。Jena 是 HP 公司语义网研究小组开发的一套 Java 工具包，用来支持人们进行语义网的相关研究和应用开发。SPARQL 的语法细节这里就不一一列举了，直接给出一个例子。总体来说，SPARQL 的语法和传统 SQL 的语法还是有几分相似的，大家应该不会陌生。</p>
<table width="90%" cellspacing="1" cellpadding="5" border="0" bgcolor="#cccccc">
<tr>
<td bgcolor="#e5e5e5">BASE &lt;http://my.donews.com/&gt;<br />
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;<br />
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;<br />
# 这是一个以 BASE 为根的相对 IRI</p>
<div>PREFIX user: &lt;users#&gt;</div>
<p>SELECT ?person ?name ?age<br />
FROM &lt;users.rdf&gt;<br />
WHERE {<br />
?person a foaf:Person ;<br />
foaf:name ?name .<br />
OPTIONAL { ?person user:age ?age } .<br />
FILTER (REGEX(?name, “clickstone”))<br />
}<br />
ORDER BY ASC(?name)<br />
LIMIT 10<br />
OFFSET 10</p>
</td>
</tr>
</table>
<p>简要的说明一下例子中出现的语法。</p>
<ol>
<li>BASE，根 IRI，其他以此为根的 IRI 就可以写成相对形式了，见例子里面的注释。一旦定义了 BASE，就可以在 SPARQL 的任何地方进行使用了，例子中共用到了 2 处。</li>
<li>使用 # 进行注释。</li>
<li>PREFIX，IRI 前缀的缩写。</li>
<li>SELECT，查询关键字，和 SQL 中的一个意思。</li>
<li>?person ?name ?age，要查询的变量，使用 ? 标识变量，也可以使用 $。变量间使用空白分隔（现在正在<a href="http://www.w3.org/TR/rdf-sparql-query/#punctuationSyntax">征集意见</a>，正式标准中使用空白还是逗号分隔尚未最终确定）。</li>
<li>FROM，从何处查询数据。可以一次查询多个 RDF 数据集，只需要使用 FROM 逐一列出即可。</li>
<li>WHERE，过滤条件集合，和 SQL 的 WHERE 一个意思。</li>
<li>?person a foaf:Person，具体的过滤条件，使用 <a href="http://www.dajobe.org/2004/01/turtle/">Turtle</a> 语法。还记得“a”是什么意思吗？具体的介绍可以参看《<a href="http://my.donews.com/clickstone/2006/11/23/amnvbeuqomlpszgvpnlhoxjfovkecyedlrym/">RDF 实战</a>》。</li>
<li>例子中两个过滤条件的主语都是“?person”，因此，使用了简写的形式。如果主语不同，逐一列出检索条件即可。</li>
<li>OPTIONAL，可选过滤条件。比如有些 ?person 可能没有填写 age 属性，如果不使用 OPTIONAL，那么查询结果将不包含这些 ?person；使用了 OPTIONAL 关键字，没有填写 age 属性的 ?person，同样可以被查询到。</li>
<li>FILTER (REGEX(?name, “clickstone”))，明确化的过滤条件，类似于 SQL 中的 LIKE、=、&gt;  等的左右。例子中的意思是说，返回的 ?name 变量中，必须包含“clickstone”。</li>
<li>ORDER BY，排序，可以指定多个排序，比如例子可以改为，ORDER BY ASC(?name) DESC(?age)。默认排序是 ASC。</li>
<li>LIMIT 10，将返回结果限定在 10 条，类似于 SQL 中的 SELECT TOP 10。</li>
<li>OFFSET 10，掠过前边的 10 条，从 第 11 条开始返回。这个功能比 SQL 强大，SQL 要自己写翻页。</li>
</ol>
<p>其他的还有 UNION、DISTINCT 等的使用，大家就自己看<a href="http://www.w3.org/TR/rdf-sparql-query/">文档</a>吧。但必须强调一点，SPARQL 的使用中和 SQL 一个非常大的区别，需要大家注意：<strong>SELECT 子句中出现的变量</strong>，比如例子中的 ?person ?name ?age，<strong>在 WHERE 子句中必须全部出现</strong>。为什么会这样呢？因为对于一个 SPARQL 查询处理器来讲，它不具备类似于关系数据库中数据字典的东西以供参考，所以每一个 SELECT 的变量，在 WHERE 中必须指定一个用来匹配的triple。</p>
<p>这篇文章只是抛砖引玉，更详细的内容，还需要大家深入研究。推荐阅读：<a href="http://www.xml.com/pub/a/2005/11/16/introducing-sparql-querying-semantic-web-tutorial.html">Introducing SPARQL: Querying the Semantic Web</a>。欢迎互动交流。</p>
<hr id="rss-footer" />
<small>© guwendong for <a href="http://www.guwendong.com">Beyond Search</a>, 2006.<br/>
本文网址：<a href="http://www.guwendong.com/post/2006/semweb_intro_6.html">http://www.guwendong.com/post/2006/semweb_intro_6.html</a><br/>
tags: <a href="http://www.guwendong.com/post/tag/rdf" rel="tag">rdf</a>, <a href="http://www.guwendong.com/post/tag/semantic-web" rel="tag">semantic-web</a>, <a href="http://www.guwendong.com/post/tag/sparql" rel="tag">sparql</a> | <a href="http://www.guwendong.com/post/2006/semweb_intro_6.html#comments">参与讨论</a>
</small><br><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="分析互联网发展趋势 探索Web开发新策略" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ftech2ipo.com%2F42949%2F&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/02/03/14698336.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">分析互联网发展趋势 探索Web开发新策略 (@tech2ipo)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="[译记]语义网模式：语义技术概论（3）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.wentrue.net%2Fblog%2F%3Fp%3D45&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[译记]语义网模式：语义技术概论（3） (@wentrue)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Social Graph 与 Semantic Web" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2007%2Fsocial_graph_and_semantic_web.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Social Graph 与 Semantic Web</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Semantic Web: RDF实战" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro_5.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/04/1802134.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Semantic Web: RDF实战</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Semantic Web：语义网是如何运作的？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro_4.html&from=http%3A%2F%2Fwww.guwendong.com%2Fpost%2F2006%2Fsemweb_intro.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/01/04/1802137.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Semantic Web：语义网是如何运作的？</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.guwendong.com/post/2006/semweb_intro_6.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

