﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-定义世界-随笔分类-Future Works</title><link>http://www.blogjava.net/gsofhon/category/30755.html</link><description>摆动的时钟挥动死神之镰</description><language>zh-cn</language><lastBuildDate>Tue, 15 Apr 2008 10:14:49 GMT</lastBuildDate><pubDate>Tue, 15 Apr 2008 10:14:49 GMT</pubDate><ttl>60</ttl><item><title>Impedance Mismatch</title><link>http://www.blogjava.net/gsofhon/archive/2008/01/13/174920.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Sat, 12 Jan 2008 16:51:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2008/01/13/174920.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/174920.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2008/01/13/174920.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/174920.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/174920.html</trackback:ping><description><![CDATA[<p>Impedance Mismatch，阻抗失调。</p>
<p>这是一个比喻的用法，用于描述不同的系统使用不同的数据模型导致的数据不能很好的在系统之间流动的问题。</p>
<p>首先从阻抗失调的本意说起。这原本是一个电学的概念。简单的例子就是，一个220V，15W的灯泡在110V电压下不能最高效的工作，因为电流不能以最高效的方式流动。</p>
<p>同样，当数据在使用不同的模型的系统之间流动的时候，由于不同的模型描述能力不同，往往也不能很好的流动。一个典型的例子就是关系数据库到面向对象应用之间的数据流动。为了实现比较好的流动，用户往往需要编写大量的包装代码，或者说映射（比如ORM）。这种映射也指出了解决阻抗失调问题的方法——使用描述能力强的映射来提高数据流动的效率。当然这里的效率不仅仅是系统执行的效率，更多的包含了开发效率——构建这种映射总是很麻烦的。并且随着数据库系统的复杂度和软件系统的复杂度不断提升，这种映射往往变得十分复杂。那么如何进行有效的映射呢？</p>
<p>想吧，想出来就牛B了。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/174920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2008-01-13 00:51 <a href="http://www.blogjava.net/gsofhon/archive/2008/01/13/174920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从JSON看RDF</title><link>http://www.blogjava.net/gsofhon/archive/2008/01/08/173846.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Tue, 08 Jan 2008 15:59:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2008/01/08/173846.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/173846.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2008/01/08/173846.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/173846.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/173846.html</trackback:ping><description><![CDATA[<p>第一次看RDF的时候就觉得这个东西太麻烦了。相比XML的容易理解，RDF似乎由于承载了太多的语义而变得巨大而不好控制。今天看了一下《语义网原理与技术》一书，觉得其中一句话&#8220;RDF的复杂也称为工业界接收语义网缓慢的一个原因&#8221;很有道理。反观JSON的简洁以及他在AJAX中广泛的应用，RDF和语义网似乎也应该做出一些妥协。</p>
<p>当然，这并不是说我对语义网或者RDF标准存在质疑。我是说，如果想把语义网推向应用，是否应该存在一种入门门槛更低的东西来帮助推广应用。其实建模应该是一个相对简单的过程，就像用面向对象语言书写类那样，是否RDF也能那么简单和容易。或者出现一种类似XAML那样的中介语言，通过他们进行比较容易的编写，然后再使用标准工具转换成RDF。毕竟，简单才是美好的。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/173846.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2008-01-08 23:59 <a href="http://www.blogjava.net/gsofhon/archive/2008/01/08/173846.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数据交换</title><link>http://www.blogjava.net/gsofhon/archive/2008/01/07/173214.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Sun, 06 Jan 2008 16:35:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2008/01/07/173214.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/173214.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2008/01/07/173214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/173214.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/173214.html</trackback:ping><description><![CDATA[<p>从人工智能到数据库，从本体到数据库模式。模式匹配，模式映射，然后数据在迁移。</p>
<p>今天读了Arnon Resenthal的Pragmatics and Open Problems for Inter-schema Constraint Theory。里面的Comparing DB and AI Mediation Approaches to Data Exchange和Unifying Data Exchange Theory and Business Objects' Update两个小结给我印象深刻。</p>
<p>前面一小节对比了数据库领域常用的数据映射方法和人工智能领域常用的信息集成方法进行数据集成的比较。看了之后才发现自己已经忘了原本我是搞信息集成的了。数据库领域的模式集成，模式映射方法把模式处理为一些对象。方法根据对象的特征进行处理，得到需要的信息，并用这些信息和其他的模式进行匹配进而进行为数据级别的应用提供支持。而信息集成方法则似乎更人性化一些，由于本体本身已经具有了相当的信息，处理方法似乎也不会把所要处理的本体当成模式一类的对象，而是更多的考虑本体自身的特点并且映射他们到全局本体。其实无论是模式匹配和映射还是本体匹配和映射，他们最终处理问题的方法都是类似的，只不过数据库可能还需要自己构建全局模式，而人工智能则需要更多的考虑各个本体自身的一些信息。不过由于我一贯对本体的印象比较好，因此总感觉本体的方法看起来更COOL一点。</p>
<p>而对于Business Object到模式的映射和更新，文中描述的内容似乎距离现实具有一些距离。毕竟，在ActiveObject以及LINQ这类相当好用的ORM映射工具的帮助下，开发者开发数据驱动应用已经相当容易了。不过文中似乎更倾向于从数据库理论的角度出发，描述如何让Business Object 更好的支持数据库的诸多约束。这种约束从一定程度上描述了业务规则以及业务行为。很有趣，不过思路还理不清，毕竟进入这行时间太短，软件开发又离开一段时间了。</p>
<p>胡言乱语一番，自己都没有想明白，呵呵。Data Exchange，说到底还是数据啊。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/173214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2008-01-07 00:35 <a href="http://www.blogjava.net/gsofhon/archive/2008/01/07/173214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>所谓约束</title><link>http://www.blogjava.net/gsofhon/archive/2008/01/02/172043.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Tue, 01 Jan 2008 16:22:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2008/01/02/172043.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/172043.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2008/01/02/172043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/172043.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/172043.html</trackback:ping><description><![CDATA[<p>约束，Constraints，领域约束，Domain Constraints，在模式匹配技术中有着独特的地位。这里所说的约束即是数据库那种常见的主外键约束，唯一性约束等等，也是对领域知识的一种描述。一个比较容易理解领域约束在模式匹配中的作用的例子就是，假设我们得到了一个这样的约束：如果一个表可以和Products匹配，那么他一定具有一个类，类似ProductID。那么，在模式匹配的过程中，我们就可以利用这条约束。比如，一个表如果没有ProductID这样的列，那么他就不能和表Products进行匹配。</p>
<p>我靠&#8230;&#8230;，太牛了，不愧是外国人&#8230;&#8230;</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/172043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2008-01-02 00:22 <a href="http://www.blogjava.net/gsofhon/archive/2008/01/02/172043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>整体模式匹配</title><link>http://www.blogjava.net/gsofhon/archive/2007/12/31/171920.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Mon, 31 Dec 2007 14:38:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/12/31/171920.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/171920.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/12/31/171920.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/171920.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/171920.html</trackback:ping><description><![CDATA[<p>坦白说我还没看懂。本来今天应该好好看看的，不过家里的气氛实在不适合看论文，而且因为一些私事还耽误了。嗯，这私事真的够私&#8230;&#8230;</p>
<p>整体模式匹配和传统的模式匹配方法不同。传统的模式匹配方法一般只会考虑被匹配的模式的信息，比如元素的名字，相关描述，关系重复模式和所包含的数据等等。这样做的问题是由于模式本身是十分简洁的，那么几个模式所蕴含的信息可能根本不足以提供足够的线索来进行匹配。因此，整体模式匹配被提出了。整体模式匹配把大量的模式作为一个整体进行模式匹配，能够比较充分的利用各个模式所蕴含的信息，因此可以取得比较好的结果，当然是相对传统的方法来说。</p>
<p>具体的内容还没有研究，不过据我所知整体模式匹配更多的使用的是基于统计方法的数据挖掘技术。就我浅显的认识来看，更多的应该是仅仅利用了文本聚类技术。至于怎么利用其他的信息，还需要看看的说。</p>
<p>写这篇日志的时候我才想起来，整体模式匹配的方法采用的技术和过去的方法差距比较大，是不是应该对已经写好的文章的部分进行一些修改来适应这个方法。嗯，应该应该。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/171920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-12-31 22:38 <a href="http://www.blogjava.net/gsofhon/archive/2007/12/31/171920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式集成简史</title><link>http://www.blogjava.net/gsofhon/archive/2007/12/29/171387.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Fri, 28 Dec 2007 19:22:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/12/29/171387.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/171387.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/12/29/171387.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/171387.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/171387.html</trackback:ping><description><![CDATA[<p>模式集成技术研究最早开始于二十世纪八十年代早期。当时的研究主要集中在利用视图集成技术设计大型数据库应用上。在九十年代则主要研究使用全局集成模式或者联邦数据库的方法集成异构分布式数据库系统。最近的十年关于模式集成的研究则更多的关注于Deep Web领域中集成接口模式生成问题。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/171387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-12-29 03:22 <a href="http://www.blogjava.net/gsofhon/archive/2007/12/29/171387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式转换</title><link>http://www.blogjava.net/gsofhon/archive/2007/12/27/170764.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Wed, 26 Dec 2007 16:14:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/12/27/170764.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/170764.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/12/27/170764.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/170764.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/170764.html</trackback:ping><description><![CDATA[<p>模式集成过程开始于模式转换。</p>
<p>模式转换的目的是将使用不同数据模型描述的模式转换为使用公共数据模型描述的模式。这样做的好处是减低模式匹配过程中的复杂度，让模式匹配过程可以专注于处理使用相同数据模型描述的异构模式，而不需要处理不同的数据模型带来的麻烦。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/170764.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-12-27 00:14 <a href="http://www.blogjava.net/gsofhon/archive/2007/12/27/170764.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式集成中模式映射所处的地位</title><link>http://www.blogjava.net/gsofhon/archive/2007/12/24/169907.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Sun, 23 Dec 2007 17:46:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/12/24/169907.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/169907.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/12/24/169907.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/169907.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/169907.html</trackback:ping><description><![CDATA[<p>模式映射作为一种&#8220;映射&#8221;，本质上描述了集成模式中的对象和被集成模式中的对象之间的对应关系。因此，模式映射只在使用概念模式的方法进行模式集成的时候才有意义。也就是说，如果模式集成过程中采用了基于数据的方法，那么也就无所谓模式映射了。</p>
<p>模式映射的主要价值在于查询转换（Query Transformation），也就是把集成模式上的查询装换为被集成模式上的查询。</p>
<p>模式集成过程中得到模式映射并不是一个单独的过程，而是伴随着把被集成模式转换为统一格式的过程和把被集成模式集成到集成模式的过程的同时得到的。前面的过程得到了全局模型到本地模型的映射，而后一个过程得到了全局对象到本地对象的映射。</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/169907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-12-24 01:46 <a href="http://www.blogjava.net/gsofhon/archive/2007/12/24/169907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>所谓框架、模型与模式</title><link>http://www.blogjava.net/gsofhon/archive/2007/12/15/168018.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Sat, 15 Dec 2007 15:57:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/12/15/168018.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/168018.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/12/15/168018.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/168018.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/168018.html</trackback:ping><description><![CDATA[<p>看了这么久的论文，终于明白了这三个概念的区别和具体的意义。在和实验室的同学讨论的同时发现很多同学对这个问题也不是很明确，所以写个小文记录一下。</p>
<p>首先需要说明的是，这个所说的框架、模型和模式都是在看研究性论文的时候经常提到的概念，可能和软件工程领域的对应概念并不完全一致。并且因为水平有限，我的理解也可能是不正确的。</p>
<p>首先说说框架。所谓框架，应该就是一种处理流程。典型的框架可能是下面这样的：</p>
<p align="center"><img style="border-width: 0px;" alt="1a_clip_image002" src="http://www.blogjava.net/images/blogjava_net/gsofhon/WindowsLiveWriter/ed71b495cf4e_150A2/1a_clip_image002_thumb.gif" border="0" height="350" width="558" />&nbsp; </p>
<p>这个图片可能看不清楚，不过不重要。框架就是一个解决某一个问题的处理流程。我们熟悉的ASP.NET框架，Rails框架也都是这类的框架——他们解决的是如何搭建web应用的问题。ASP.NET和Rails都规定了一系列的处理流程，从获得用户请求，到把请求定向到适当的类，如何调用用户定义的函数处理问题，再到把处理结果发送给用户。</p>
<p>所谓模型，是一种描述问题的工具。这里需要注意的是我所说的模型并不是所谓&#8220;数学建模&#8221;、&#8220;软件建模&#8221;得到的模型，而是另外一种模型，比如对象模型，关系模型等等。这类模型是一些规定，这些规定描述了如何去描述一个概念，同时还规定了一系列的操作，这些操作描述了概念之间如何进行交互。比较典型的就是关系模型，他描述了使用很多很多的属性（数据库字段）来描述一个概念（数据库表），以及这些概念之间的关系，比如Union（对应union操作符），Project（对应select columnname from tablename）等等。模型是一种工具，他是用来帮助人们记录和分析问题的。其他的常用模型还包括对象模型，UML模型等等。</p>
<p>最后是模式。可以认为使用模型建模得到的东西就是模式，比如一个数据库设计，一个软件类设计等等。需要注意的是虽然MySQL管他的数据库叫做模式，但是一个运行中的数据库并不是一个模式，而是一个模式的一个具体实例。因为同一个模式可以有很多个实现，比如Northwind数据库在很多人的机器上都有，但是都是用的Northwind数据库模式。</p>
<p>这里的模式是所谓的Schema，而不是设计模式所谓的Pattern。Schema是用来描述概念和概念之间关系的，而Pattern更多的用于描述概念实例之间的关系，比如某些数据具有一些特定的模式（Pattern），比如电话号码总是【区号-号码】这种模式。另外还有一些被称为模式的东西既不是Schema又不是Pattern，今天吃晚饭的时候还在想这个问题，现在忘了&#8230;&#8230;</p>
<img src ="http://www.blogjava.net/gsofhon/aggbug/168018.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-12-15 23:57 <a href="http://www.blogjava.net/gsofhon/archive/2007/12/15/168018.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>web 3.0和Semantic Web</title><link>http://www.blogjava.net/gsofhon/archive/2007/11/08/158993.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Thu, 08 Nov 2007 01:08:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/11/08/158993.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/158993.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/11/08/158993.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/158993.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/158993.html</trackback:ping><description><![CDATA[一直感觉Semantic Web是开玩笑的东西，虽然以后要靠这个东西活命。因为至少在中国范围内，不会有人那么Semantic，不会开放自己的数据，也不会为自己的应用添加上语义标记。没有数据的开放，没有语义信息，怎么Semantic Web呢？<br />
<br />
可事实只是证明我的视角太狭窄了。Facebook的发展，最近Google制定的OpenSocail，web 3.0的到来不仅仅是API级别的开放。应该可以遇见，随着大量API的出现，语义级别的数据和接口描述很快就会成为主流应用中不可或缺的一个部分。website们真正变成了数据源，而且不是web interface，而是真正的data source。web 3.0的开放的api让我能看到的东西不再是模式级别的模式集成，或者数据集成，虽然他们也可以被看成是一种视图。这是一种真正的语义级别的应用，以一种使用&#8220;概念的概念&#8221;来推动应用的方式。<br />
<br />
先不考虑盈利的问题，因为他们会找到盈利的方法的。单从web发展的角度来说，web 3.0的到来是否为semantic web的全面发展奠定了基础？我不知道，因为我还很鼠目寸光。不过冥冥之中似乎感觉到了某种脚步声。<br />
<br />
唉，大牛们太TM猛了，总是超越我们一个时代。<br />
<img src ="http://www.blogjava.net/gsofhon/aggbug/158993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-11-08 09:08 <a href="http://www.blogjava.net/gsofhon/archive/2007/11/08/158993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RDF和Jena RDF API入门（5）</title><link>http://www.blogjava.net/gsofhon/archive/2007/09/27/148876.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Thu, 27 Sep 2007 12:29:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/09/27/148876.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/148876.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/09/27/148876.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/148876.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/148876.html</trackback:ping><description><![CDATA[容器<br />
<br />
RDF定义了一类特殊的资源来表示事物的集合。这些资源称为容器。一个容器的成员可以是资源也可以是文本。有三类容器：<br />
<br />
一个BAG是一个无序的集合。<br />
一个ALT是一个用来表示备选项的无序的集合。<br />
一个SEQ是一个有序的集合。<br />
<br />
一个容器由一个资源表示。该资源会有一个rdf:type属性，属性值为rdf:Bag，或rdf:Alt，或是rdf:Seq，再或是这些类型的子类型，这取决于容器的类型。容器的第一个成员是容器的rdf:_1的属性所对应的属性值；第二个成员是容器的rdf:_2属性的值，依此类推。这些rdf:_nnn属性被称为序数属性。<br />
<br />
例如，一个含有Smith的vcard的简单bag容器的模型可能会看起来是这样的：<br />
<br />
<div align="center"><img src="http://www.blogjava.net/images/blogjava_net/gsofhon/7.png" alt="" border="0" /></div>
<br />
虽然bag容器的成员们被rdf:_1，rdf_2等等的属性所表示，但是这些属性的顺序却并不重要。即便我们将rdf:_1和rdf:_2的属性值交换，但是交换后的模型仍然表示相同的信息。<br />
<br />
Alt是设计用来表示被选项的。例如，我们假定有一个表示软件产品的资源。它可能有一个属性指示从哪里可以获得次软件产品。这个属性值可能是一个包含各种下载地址的Alt集合。Alt是无序的，除了rdf:_1属性有着特殊的意义，它表示默认的选项。<br />
<br />
尽管我们可以用基本的资源和属性机制来处理容器，Jena为处理容器设计了显式的接口和执行类。要避免在使用一个对象来操作容器的同时去使用低层方法来改变容器。<br />
<br />
让我们修改Tutorial8以创建一个bag：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;create&nbsp;a&nbsp;bag</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Bag&nbsp;smiths&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.createBag();<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;select&nbsp;all&nbsp;the&nbsp;resources&nbsp;with&nbsp;a&nbsp;VCARD.FN&nbsp;property<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;whose&nbsp;value&nbsp;ends&nbsp;with&nbsp;"Smith"</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">StmtIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listStatements(<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;VCARD.FN,&nbsp;(RDFNode)&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);">&nbsp;selects(Statement&nbsp;s)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;s.getString().endsWith(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;});<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;add&nbsp;the&nbsp;Smith's&nbsp;to&nbsp;the&nbsp;bag</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;smiths.add(iter.next().getSubject());<br />
}</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">smiths&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createBag<br />
<br />
iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">listStatements(<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">Class</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">SimpleSelector)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;selects&nbsp;s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">lang</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">String</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(s</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">endsWith&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(nil</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FN</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;nil))<br />
<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;iter</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">hasNext<br />
&nbsp;&nbsp;&nbsp;&nbsp;smiths</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">add&nbsp;iter</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">nextStatement</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getSubject<br />
</span><span style="color: rgb(0, 128, 128);">end</span></div>
<br />
如果我们将次模型输出可以看见它含有类似如下的成分：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:RDF<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns:rdf</span><span style="color: rgb(0, 0, 255);">='http://www.w3.org/1999/02/22-rdf-syntax-ns#'<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns:vcard</span><span style="color: rgb(0, 0, 255);">='http://www.w3.org/2001/vcard-rdf/3.0#'<br />
&nbsp;</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
...<br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:Description&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:nodeID</span><span style="color: rgb(0, 0, 255);">="A3"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:type&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:resource</span><span style="color: rgb(0, 0, 255);">='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;rdf:_1&nbsp;rdf:resource</span><span style="color: rgb(0, 0, 255);">='http://somewhere/JohnSmith/'/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;rdf:_2&nbsp;rdf:resource</span><span style="color: rgb(0, 0, 255);">='http://somewhere/RebeccaSmith/'/&gt;<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;/rdf:Description</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">rdf:RDF</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />
</span></div>
<br />
这表示了Bag资源。<br />
<br />
容器接口提供了一个iterator来列举容器的内容：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;print&nbsp;out&nbsp;the&nbsp;members&nbsp;of&nbsp;the&nbsp;bag</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">NodeIterator&nbsp;iter2&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;smiths.iterator();<br />
</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter2.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">The&nbsp;bag&nbsp;contains:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter2.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Resource)&nbsp;iter2.next())<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getProperty(VCARD.FN)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getString());<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">The&nbsp;bag&nbsp;is&nbsp;empty</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
} <br />
</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">iter2&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;smiths</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">iterator<br />
<br />
</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;iter2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">hasNext<br />
&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">The&nbsp;bag&nbsp;contains:</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;iter2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">hasNext<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;model\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getResource(iter2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">next</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString)\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getRequiredProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FN)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">The&nbsp;bag&nbsp;is&nbsp;empty</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">end</span></div>
<br />
并会产生如下的输出: <br />
The bag contains: <br />
&nbsp; John Smith <br />
&nbsp; Becky Smith<br />
<br />
这里发生了一些小小的问题。正常来说，jruby是不需要类型转换的。然而这里如果直接使用下面的代码：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">puts&nbsp;iter2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">next</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getRequiredProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FN)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString</span></div>
<br />
却并不能正确的执行。具体的原因没有弄清楚，只是知道iter2.next返回的对象是com.hp.hpl.jena.rdf.model.impl.LiteralImpl类型的对象，而且并不包含对getRequiredProperty函数的相应。因为这个问题我也找了一些东西，可是没有得到明确的答案，因此使用了一个折衷的办法来实现功能。<br />
<br />
本例的可执行代码可以在Tutorial10中找到。<br />
<br />
Jena类所提供的操纵容器的方法包括增加新成员，在容器中间插入新成员和删除已有的成员。Jena容器类目前保证所使用的序数属性列表会从rdf:_1开始并且是相邻的。RDF核心工作小组放松了此项限制，以允许有局部的容器表示。所以这是Jena将来可能会修改的地方之一。<br />
<br />
关于文本（Literals）和数据类型的更多探讨<br />
<br />
RDF 文本（literals）并不仅仅是简单的字符串而已。文本可能有一个语言标签来指示该文本使用的语言。有英语语言标签的文本&#8220;chat&#8221;会被认为与有着法语语言标签的文本&#8220;chat&#8221;是不同的。这个奇怪的特性是原有RDF/XML语法产生的赝象（artefact）。<br />
<br />
另外，事实上共有两种文本。在一种里，字符串成分只是简单的字符串。而在另一种里，字符串成分被预计为格式良好的XML片段。当一个RDF模型被写成 RDF/XML形式时，一个特殊的使用parseType='Literal'的属性（attribute）构造会被使用来表示它。<br />
<br />
在jena中，当一个文本被创建时，这些属性就被设置了。例如，在Tutorial11中：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;create&nbsp;the&nbsp;resource</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Resource&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.createResource();<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;add&nbsp;the&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">r.addProperty(RDFS.label,&nbsp;model.createLiteral(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">chat</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">en</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">))<br />
&nbsp;.addProperty(RDFS.label,&nbsp;model.createLiteral(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">chat</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">fr</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">))<br />
&nbsp;.addProperty(RDFS.label,&nbsp;model.createLiteral(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;em&gt;chat&lt;/em&gt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">));<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;write&nbsp;out&nbsp;the&nbsp;Model</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">model.write(system.out); <br />
</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">require</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
<br />
module&nbsp;Java<br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.rdf.model</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.vocabulary</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.util</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java.io</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ModelFactory</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createDefaultModel<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createResource<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;r</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(RDFS</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">label</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createLiteral(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">chat</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">en</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">))\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(RDFS</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">label</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createLiteral(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">chat</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">fr</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">))\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(RDFS</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">label</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createLiteral(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&lt;em&gt;chat&lt;/em&gt;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">))<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">write&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">PrintWriter</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(java</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">lang</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">System</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">out)<br />
&nbsp;&nbsp;&nbsp;&nbsp;puts<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;ModelFactory</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createDefaultModel<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createResource<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;r</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(RDFS</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">label</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(RDFS</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">label</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">)<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">write&nbsp;java</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">lang</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">System</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">out</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">N-TRIPLE</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">end</span></div>
<br />
会产生：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:RDF<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns:rdf</span><span style="color: rgb(0, 0, 255);">='http://www.w3.org/1999/02/22-rdf-syntax-ns#'<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns:rdfs</span><span style="color: rgb(0, 0, 255);">='http://www.w3.org/2000/01/rdf-schema#'<br />
&nbsp;</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:Description&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:nodeID</span><span style="color: rgb(0, 0, 255);">="A0"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdfs:label&nbsp;</span><span style="color: rgb(255, 0, 0);">xml:lang</span><span style="color: rgb(0, 0, 255);">='en'&gt;chat&lt;/rdfs:label&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;rdfs:label&nbsp;xml:lang</span><span style="color: rgb(0, 0, 255);">='fr'&gt;chat&lt;/rdfs:label&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;rdfs:label&nbsp;xml:lang</span><span style="color: rgb(0, 0, 255);">='en'&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:parseType</span><span style="color: rgb(0, 0, 255);">='Literal'&gt;&lt;em&gt;chat&lt;/em&gt;&lt;/rdfs:label&gt;<br />
&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">&lt;/rdf:Description</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">rdf:RDF</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />
</span></div>
<br />
如果两个文本被认为是相同的，它们一定都是XML的文本或都是简单的文本。另外，它们两个要么都没有语言标签，要么有相同的语言标签。对简单的文本而言，两者的字符串一定是相同的。XML文本的等同有两点要求。第一，前面提到的要求必须被满足并且字符串必须相同。第二，如果它们字符串的cannonicalization一样的话，它们就是一样的。（译者注: 找不到cannonicalization中文的解释。）。<br />
&nbsp;<br />
Jena 接口也支持类型文字。老式的对待类型文字的方法是把他们当成是字符串的缩写：有类型的值会通过Java的常用方法转换为字符串，并且这些字符串被存储在模型中。例如，可以试一试（注意：对于简单类型文字，我们可以省略对model.createLiteral(&#8230;)的调用）：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;create&nbsp;the&nbsp;resource</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Resource&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.createResource();<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;add&nbsp;the&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">r.addProperty(RDFS.label,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />
&nbsp;.addProperty(RDFS.label,&nbsp;</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">);<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;write&nbsp;out&nbsp;the&nbsp;Model</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">model.write(system.out,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">N-TRIPLE</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br />
</span></div>
<br />
产生的输出如下: <br />
_:A... &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; "11" . <br />
<br />
因为两个文本都是字符串&#8220;11&#8221;，所以只会有一个陈述被添加。<br />
<br />
RDF核心工作小组定义了支持RDF数据类型的机制。Jena支持那些使用类型文字的机制；但是本教程中不会对此讨论。<br />
<img src ="http://www.blogjava.net/gsofhon/aggbug/148876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-09-27 20:29 <a href="http://www.blogjava.net/gsofhon/archive/2007/09/27/148876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RDF和Jena RDF API入门（4）</title><link>http://www.blogjava.net/gsofhon/archive/2007/09/17/145999.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Mon, 17 Sep 2007 14:43:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/09/17/145999.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/145999.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/09/17/145999.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/145999.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/145999.html</trackback:ping><description><![CDATA[让我们看看如何对所选择的陈述实行更好的控制。SimpleSelector可以被继承，它的select方法可以被修改来实现更好的过滤：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;select&nbsp;all&nbsp;the&nbsp;resources&nbsp;with&nbsp;a&nbsp;VCARD.FN&nbsp;property<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;whose&nbsp;value&nbsp;ends&nbsp;with&nbsp;"Smith"</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">StmtIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listStatements(<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;VCARD.FN,&nbsp;(RDFNode)&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);">&nbsp;selects(Statement&nbsp;s)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;s.getString().endsWith(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);}<br />
});</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">list_statements(<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">Class</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">SimpleSelector)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;selects&nbsp;s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">lang</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">String</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(s</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">endsWith&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">(nil</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FN</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;nil))</span></div>
<br />
这个示例使用了一个简洁的Java技术，就是当创建此类的一个实例时重载一个内联的方法。（类似的，jruby中也有这种方法。）这里selects(&#8230;)方法会检查以保证全名以&#8220;Smith&#8221;做结尾。重要的是要注意对主体，谓语和客体的过滤是在调用selects(&#8230;)方法之前的执行的，所以额外的测试只会被应用于匹配的陈述。完整的代码可以在Tutorial8中找到，并会产生如下的输出：<br />
<br />
The database contains vcards for: <br />
&nbsp; John Smith <br />
&nbsp; Becky Smith<br />
<br />
你也许会认为下面的代码：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;do&nbsp;all&nbsp;filtering&nbsp;in&nbsp;the&nbsp;selects&nbsp;method</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">StmtIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listStatements(<br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SimpleSelector(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;(RDFNode)&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);">&nbsp;selects(Statement&nbsp;s)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;(subject&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">&nbsp;s.getSubject().equals(subject))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">&nbsp;(predicate&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">&nbsp;s.getPredicate().equals(predicate))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">&nbsp;(object&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">&nbsp;s.getObject().equals(object))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;});</span></div>
<br />
等同于：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">StmtIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;model.listStatements(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(subject,&nbsp;predicate,&nbsp;object) <br />
</span></div>
<br />
虽然在功能上它们可能是等同的，但是第一种形式会列举出模型中所有的陈述，然后再对它们进行逐一的测试。而第二种形式则允许执行时建立索引来提供性能。你可以在一个大模型中自己试试验证一下，但是现在先为自己倒一杯咖啡休息一下吧。<br />
<br />
对模型的操作<br />
<br />
Jena提供了把模型当作一个集合整体来操纵的三种操作方法。即三种常用的集合操作：并，交和差。<br />
<br />
两个模型的并操作就是把表示两个模型的陈述集的并操作。这是RDF设计所支持的关键操作之一。它此操作允许把分离的数据源合并到一起。考虑下面两个模型：<br />
<br />
<div align="center"><img src="http://www.blogjava.net/images/blogjava_net/gsofhon/4.png" alt="" border="0" /></div>
<br />
和<br />
<br />
<div align="center"><img src="http://www.blogjava.net/images/blogjava_net/gsofhon/5.png" alt="" border="0" /></div>
<br />
当它们被合并时，两个http://...JohnSmith会合并成一个，重复的vcard:FN箭头会被丢弃，此时就会产生：<br />
<br />
<div align="center"><img src="http://www.blogjava.net/images/blogjava_net/gsofhon/6.png" alt="" border="0" /></div>
<br />
让我们看一下这个代码的功能（完整的代码在Tutorial9中），再看看会发生什么。<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;read&nbsp;the&nbsp;RDF/XML&nbsp;files</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">model1.read(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;InputStreamReader(in1),&nbsp;</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">);<br />
model2.read(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;InputStreamReader(in2),&nbsp;</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">);<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;merge&nbsp;the&nbsp;Models</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Model&nbsp;model&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model1.union(model2);<br />
<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;print&nbsp;the&nbsp;Model&nbsp;as&nbsp;RDF/XML</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">model.write(system.out,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">RDF/XML-ABBREV</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">require</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
<br />
module&nbsp;Java<br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.rdf.model</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.vocabulary</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.util</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java.io</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;InputFileName1&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">vc-db-3.rdf</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;InputFileName2&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">vc-db-4.rdf</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model1&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ModelFactory</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createDefaultModel<br />
&nbsp;&nbsp;&nbsp;&nbsp;model2&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ModelFactory</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createDefaultModel<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;in1&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FileManager</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">get</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">open&nbsp;InputFileName1<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;in1&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;nil<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise&nbsp;ArgumentError</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">File:&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;InputFileName1&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;not&nbsp;found</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;in2&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FileManager</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">get</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">open&nbsp;InputFileName2<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;in2&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;nil<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise&nbsp;ArgumentError</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">File:&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;InputFileName2&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;not&nbsp;found</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model1</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">read&nbsp;in1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;model2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">read&nbsp;in2</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model1</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">union&nbsp;model2<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">write&nbsp;java</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">lang</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">System</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">out</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">RDF/XML-ABBREV</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;puts<br />
</span><span style="color: rgb(0, 128, 128);">end</span></div>
<br />
petty writer会产生如下的输出：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:RDF<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns:rdf</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/1999/02/22-rdf-syntax-ns#"</span><span style="color: rgb(255, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xmlns:vcard</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/vcard-rdf/3.0#"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:Description&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:about</span><span style="color: rgb(0, 0, 255);">="http://somewhere/JohnSmith/"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:EMAIL</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:internet</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">rdf:value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">John@somewhere.com</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">rdf:value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:internet</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:EMAIL</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:N&nbsp;</span><span style="color: rgb(255, 0, 0);">rdf:parseType</span><span style="color: rgb(0, 0, 255);">="Resource"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:Given</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">John</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:Given</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:Family</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Smith</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:Family</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:N</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">vcard:FN</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">John&nbsp;Smith</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">vcard:FN</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">rdf:Description</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">rdf:RDF</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />
</span></div>
<br />
即便你不熟悉RDF/XML的语法细节，你仍然可以清楚的看见模型如同预期般被合并了。我们可以在类似的方式下运算模型的交操作和差操作。<br />
<img src ="http://www.blogjava.net/gsofhon/aggbug/145999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-09-17 22:43 <a href="http://www.blogjava.net/gsofhon/archive/2007/09/17/145999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Practical RDF学习笔记（2）</title><link>http://www.blogjava.net/gsofhon/archive/2007/09/14/145241.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Fri, 14 Sep 2007 13:39:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/09/14/145241.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/145241.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/09/14/145241.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/145241.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/145241.html</trackback:ping><description><![CDATA[RDF的目标是很简单的。他提供一种以机器可以理解的方式来记录数据的方法，允许更有效和更复杂的数据交换，搜索，编目，导航，分类等等。当然他不是仅仅能够做这些工作。<br />
<br />
目前的搜索引擎的问题是搜索出来的结果仅仅是一些内容的罗列。比如一个超级没有意思的例子，如果我们baidu&#8220;苹果&#8221;，我们可能得到各种各样的信息，包括出售苹果的信息，苹果电脑的信息，制作苹果馅饼的信息，甚至可能有苹果味汽水的信息。发生这种事情的原因是搜索引擎仅仅使用关键字来搜索信息，而没有考虑到被资源的领域以及用户所感兴趣的领域。搜索的依据是蜘蛛程序从Web页面上找到的关键字。<br />
<br />
一个好一点的方法是给相关的信息加上领域信息。比如一篇文本是苹果电脑公司的一系列新产品推荐文章中的一个，这个东西的销售信息可以在什么地方找到，关于他的用户评论在什么地方，等等。这些信息就构成了一个更为丰富的视图，并且远远好于原来的一维的关键字搜索。<br />
<br />
现在的关键字搜索所缺乏的是关于Web资源的的描述能力，比如作者，标题，文章所述的系列，相关文章，主题等等信息。<br />
<br />
很显然关键字搜索不能得到这些信息，至少不能用一种计算机可以比较容易理解的方式得到这些信息。<br />
<br />
RDF提供了这种能力，并且由于RDF的中立性，他还支持这种信息的合并。这样以来关心不同应用的程序可以各取所需，更好的为用户服务。<br />
<br />
RDF的这种目的让我想起了baidu的搜索联盟和开放搜索协议。或者说，baidu有可能就是受了这种思想的启发才发动了搜索联盟。这是一个不错的想法，尤其是现在的大量网站其实都是通过程序半自动生成的情况。只要修改一下页面生成程序，让他针对每一个页面再生成一个开放搜索XML或者RDF文档，就可以最大化搜索效果。只不过这种应用对于一些个人站点来说有点稍微恐怖了。并且对于很多站点，尤其是IT类站点，很多还是靠美工（他们也只能被称为是美工，而不是UI设计师）用DreamWaver等等软件画出来的，不要说指望他们能RDF了，连HTML 4.01标准他们都不能达到。所以这个东东的实现能力还是有待研究。<br />
<br />
RDF使用三元组来记录信息。三元组包含三者部分，分别是主体，属性和值。这更像是很多个陈述句组成的记录，比如这篇文档（主体）的作者（属性）是我（值）。对于RDF来说，可能就是这么记录这样的信息的：<br />
<br />
这篇文档（无论你用什么方式表达，比如URI）——作者（这可以是一个Common Sense）——我（可以使用我的电子邮件来表示我，或者我的Blog地址，随应用需要）<br />
<br />
恩，看起来很计算机的一种表达方式，不过很有效，也很好理解，不是吗。<br />
<br />
对于这篇文档，可能还有很多其他的属性，那就一个一个描述，比如这篇文档的状态是尚未完成（至少我在写他的时候是），这篇文档发布于BlogJava，等等。<br />
<br />
不过三元组只是序列化RDF数据的一种方法。标准的表示数据的方法还是一张直观的RDF图。其他的方法还包括N-三元组以及大家都觉得看起来更专业的RDF/XML。不过无论怎么样，记住，RDF其实是图，而用图去理解他，一切就变得很容易了。<br />
<br />
另外我很不喜欢这种所谓&#8220;序列化&#8221;的说法，就好像我很不喜欢&#8220;形而上学&#8221;这个词一样。序列化给我的感觉更像是在讨论C#或者别的什么，而不是RDF。<br />
<br />
RDF核心工作组决定使用RDF图——有向的带有标签的图——作为RDF的默认的描述RDF数据模型的方法。这么做有两个原因：好读而没有歧义，并且有些可以使用RDF图来描述的东西使用RDF/XML是无法描述的。<br />
<br />
RDF有向图由一系列由边连接的节点组成，形成一个点－边－点的模式。进一步的，节点有三种类型：uri引用（uriref），空节点（blank nodes）以及文本（literals）。<br />
<br />
uri引用节点使用uri来引用一个特定的资源，但是这个资源并不一定非要在网上能找到才可以。事实上，当RDF被广泛使用的时候，这种要求几乎是不可能实现的。当一个资源的uri在构建RDF图的时候还是不可用的，或者这个节点本身并不重要，那么就可以使用空节点。uri引用节点使用椭圆表示，里面写上uri，空节点使用空白的圆表示。有些自动生成的图可能使用一个带有临时uri的圆来表示空节点。文本节点包含三个部分，正文内容以及可选的语言标识和数据类型。文本值只能表示RDF对象，不可以作为主体和属性使用。在RDF图中会使用一个长方形包裹着文本内容。<br />
<br />
来自RDF Primer的图片是一个不错的例子。<br />
<br />
<div align="center"><img src="http://www.blogjava.net/images/blogjava_net/gsofhon/3.png" alt="" border="0" /></div>
<br />
空节点是有效的RDF，但是很多程序都会生成一个临时uri来表示空节点。在<a href="http://www.blogjava.net/gsofhon/archive/2007/09/14/145075.html" target="_blank">《RDF和Jena RDF API入门（2）》</a>中就有一个jena输出的例子：<br />
<br />
http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N anon:14df86:ecc3dee17b:-7fff . <br />
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Family "Smith" . <br />
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Given "John" . <br />
http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John Smith" . <br />
<br />
上面的那些谁也看不懂的数字字母冒号的混合就是空白节点临时uri的例子。<br />
<br />
到目前位置RDF似乎都很简单，但是他的复杂性应该是随着应用的复杂而边的复杂的——因为RDF几乎没有什么约束，所以他的可能性应该是无限的。<br />
<br />
说到这里不得不提一下，我在这里写的东西更倾向于一种理解，而不是准确的描述，所以并不会很注重细节，而更强调了解。如果需要准确的定义和描述，应该看看W3C的文档。<br />
<br />
由于uri节点是RDF的核心，所以关于uri有必要多了解一些。关于uri更详细的内容可以去baidu一下，不过这里有一个很重要的东西，那就是符号&#8220;#&#8221;。这个东东在做网页的时候经常用到，比如http://www,example.com/AboutUs.htm#Fax表示了页面AboutUs.htm的Fax区段，用在RDF里面也是类似的效果，比如http://www.example.com/ontology.owl#Class1表示example.com的某一个本体的Class1类。<br />
<br />
这里书中提到了有趣的东西：URI，URL和URN的区别。URI是Uniform Resource Identifier，可以用来表示一个资源的名字，也可以表示地址。而URL只能表示地址，URN只能表示名字。哎&#8230;&#8230;我怎么连这个都不知道&#8230;&#8230;<br />
<br />
RDF说明允许使用绝对URI和相对URI，比如http://www.example.com/index.htm和index.htm。当使用相对URI的时候，如果没有指定Base URI，那么就假设Base URI是当前RDF的地址。怪不得Redland总需要指定一个base_uri参数，而且默认值还是nil，原来如此。<br />
<br />
把RDF图序列化，除了可以使用RDF/XML之外，另一种方法是使用N-三元组。使用N-三元组的好处是可以确保序列化和反序列化的结果是相同的（似乎是针对RDF/XML不能处理空白节点的缺点）。而N-三元组是基于另一个标记法：N3。Protege就支持这种形式的导出，支持导入嘛？好像不吧，没注意。<br />
<br />
基本的N3三元组是这样的：<br />
<br />
subject predicate object .<br />
<br />
晕，这不是RDF用来表示数据的三元组表示嘛。好了，一切到这里就没有悬念了，直接给一个例子，事实说明一切。<br />
<br />
&lt;http://www.example.com/index.htm&gt; &lt;http://purl.ont/dc/elements/1.1/creator&gt; Tim .<br />
<br />
看清楚了哦，这可不是XML或者什么Markup Language，虽然他也有&lt;&gt;。当然为了简单起见，还是可以借鉴一点XML的技术的，比如QNames。并且，如果使用了QNames，那么对于谓词就可以省略&lt;&gt;。<br />
<br />
关于QName，我还特意baidu了一下下，结果如下：QName是qualified name的简写，由名字空间（namespace）前缀（prefix）以及冒号（:）组成，还有一个元素名称构成，比如xsl:stylesheet。（靠，啥都不懂）<br />
<br />
上面的例子就可以写成：<br />
<br />
&lt;exp:index.htm&gt; dc:creator Tim .<br />
<br />
对于空白节点则可以使用任何东西来代替他，比如刚刚看到那个例子：<br />
<br />
http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N anon:14df86:ecc3dee17b:-7fff . <br />
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Family "Smith" . <br />
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Given "John" . <br />
http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John Smith" . <br />
<br />
由于N-三元组是N3的子集，他支持RDF三元组的同样的格式。<br />
<br />
Subject predicate object .<br />
<br />
以及使用&#8220;#&#8221;开头的注释，就像ruby一样。记得把一个三元组写在一行上。而且同一行上不能同时有三元组和注释。<br />
<br />
当然这里说的十分不详细，如果需要比较具体的规范，还是应该参看W3C的文档。
<img src ="http://www.blogjava.net/gsofhon/aggbug/145241.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gsofhon/" target="_blank">光荣之翼</a> 2007-09-14 21:39 <a href="http://www.blogjava.net/gsofhon/archive/2007/09/14/145241.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RDF和Jena RDF API入门（3）</title><link>http://www.blogjava.net/gsofhon/archive/2007/09/14/145153.html</link><dc:creator>光荣之翼</dc:creator><author>光荣之翼</author><pubDate>Fri, 14 Sep 2007 07:42:00 GMT</pubDate><guid>http://www.blogjava.net/gsofhon/archive/2007/09/14/145153.html</guid><wfw:comment>http://www.blogjava.net/gsofhon/comments/145153.html</wfw:comment><comments>http://www.blogjava.net/gsofhon/archive/2007/09/14/145153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gsofhon/comments/commentRss/145153.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gsofhon/services/trackbacks/145153.html</trackback:ping><description><![CDATA[Jena RDF 包 <br />
<br />
Jena是一个为语义网应用设计的一个Java API。对应用开发者而言，主要可用的RDF包是com.hp.hpl.jena.rdf.model。因为API是以接口的方式定义的，所以应用代码可以使用不同的实现机制而不用改变代码本身。这个包包含了可以表示模型，资源，属性，文本，陈述和其他RDF关键概念的接口，还有一个用来创建模型的ModelFactory。所以如果要应用代码与实现类保持独立，最好尽可能地使用接口，而不要使用特定的实现类。（关于面向接口编程，请参考kafka0102先生的文章<a href="http://www.blogjava.net/kafka0102/archive/2007/09/03/142207.html" target="_blank">《消除实现继承和面向接口编程》</a>）<br />
<br />
com.hp.hpl.jena.Tutorial包包含了本教程所有例子中使用到的工作源代码。<br />
<br />
com.hp.hpl.jena.impl这些包包含了许多执行时所常用的执行类。比如，它们定义了诸如ResourseImpl，PropertyImpl和LiteralImpl的类，这些类可以被不同的应用直接使用也可以被继承使用。应用程序应该尽可能少地直接使用这些类。例如，与其使用ResouceImpl来创建一个新的实例，更好的办法是使用任何正在使用的模型的createResource方法来完成。那样的话，如果模型的执行采用了一个优化的Resouce执行，那么在这两种类型中不需要有任何的转换工作。<br />
<br />
操纵模型<br />
<br />
到目前为止，本教程主要讲述的是如何创建，读入和输出RDF模型。现在是时候要讲述如何访问模型中的信息。<br />
<br />
如果有了一个资源的URI，那么就可以用Model.getResource(String uri)来从模型获取这个资源对象。这个方法被定义来返回一个资源对象，如果它确实存在于模型中，否则的话就创建一个新的。例如，如何从模型中获取Adam Smith资源，这个模型是Tutorial5中从文件读入的：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;retrieve&nbsp;the&nbsp;John&nbsp;Smith&nbsp;vcard&nbsp;resource&nbsp;from&nbsp;the&nbsp;model</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Resource&nbsp;vcard&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.getResource(johnSmithURI); <br />
</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">vcard&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getResource&nbsp;JohnSmithURI</span></div>
<br />
Resouce 接口定义了一系列用于访问某个资源的属性的方法。Resource.getProperty(Property p)方法访问了该资源的属性。这个方法不允许通常的Java访问的转换，因为所返回的对象是Statement，而不是你所预计的Property。返回整个陈述的好处是允许应用程序通过使用它的某个访问方法来访问该陈述的客体来访问这个属性值。例如如何获取作为vcard:N属性值的资源：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;retrieve&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;N&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Resource&nbsp;name&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(Resource)&nbsp;vcard.getProperty(VCARD.N)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getObject();</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
#</span><span style="color: rgb(0, 128, 0);">&nbsp;由于jruby是无类型的，所以不需要类型转换。</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">name&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getRequiredProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">N)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getObject</span></div>
<br />
一般而言，一个陈述的客体可以是一个资源或是一个文本。所以此应用程序代码知道这个值一定是个资源，就将类型资源映射到返回的对象上。Jena的目标之一是提供会返回值为特定类型的方法，这样，应用程序就不必再做类型转换工作，也不必再编译时做类型检查工作。以上的代码片段也可以写成更方便的形式：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;retrieve&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;FN&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">Resource&nbsp;name&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard.getProperty(VCARD.N)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getResource();</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">name&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">N)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getResource</span></div>
<br />
类似地, 属性的文本值也可以被获取：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;retrieve&nbsp;the&nbsp;given&nbsp;name&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">String&nbsp;fullName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard.getProperty(VCARD.FN)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getString();</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">fullName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">FN)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getString</span></div>
<br />
在这个例子中，资源vcard只有一个vcard:FN属性和一个vcard:N属性。RDF允许资源有重复的属性，例如Adam可能有超过一个的昵称。让我们假设他有两个昵称：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;add&nbsp;two&nbsp;nickname&nbsp;properties&nbsp;to&nbsp;vcard</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">vcard.addProperty(VCARD.NICKNAME,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Smithy</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addProperty(VCARD.NICKNAME,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Adman</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">vcard</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">NICKNAME</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Smithy</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">addProperty(VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">NICKNAME</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Adman</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)</span></div>
<br />
正如前面所提到的那样，Jena将RDF模型表示为一组陈述，所以在模型中新增一个与原有陈述有着相同的主体，谓词和客体的陈述并不会后什么作用。Jena没有定义会返回模型中存在的两个昵称中的哪一个。vcard.getProperty(VCARD.NICKNAME)调用的结果是不确定的。Jena会返回这些值中的某一个，但是并不保证两次连续的调用会同一个值。<br />
<br />
一个属性很有可能会出现多次，而方法Resource.listProperty(Property p)可以用来返回一个iterator，这个iterator会列出所有的值。此方法所返回的iterator返回的对象的类型为Statement。我们可以像这样列出所有的昵称：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;set&nbsp;up&nbsp;the&nbsp;output</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">The&nbsp;nicknames&nbsp;of&nbsp;\</span><span style="color: rgb(0, 0, 0);">""<br />
</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;fullName&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;are:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;list&nbsp;the&nbsp;nicknames</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">StmtIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard.listProperties(VCARD.NICKNAME);<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;iter.nextStatement()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getObject()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.toString());<br />
} <br />
</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">puts&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">The&nbsp;nicknames&nbsp;of&nbsp;"</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;full_name&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">"&nbsp;are</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;vcard</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">listProperties&nbsp;VCARD</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">NICKNAME<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;iter</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">hasNext<br />
&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;iter</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">nextStatement</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">getObject</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">toString<br />
</span><span style="color: rgb(0, 128, 128);">end</span></div>
<br />
此代码可以在Tutorial6中找到，运行后会产生如下输出：<br />
<br />
The nicknames of "John Smith" are: <br />
&nbsp;&nbsp;&nbsp; Smithy <br />
&nbsp;&nbsp;&nbsp; Adman<br />
<br />
一个资源的所有属性可以用不带参数的listStatement()方法列出。<br />
<br />
查询模型<br />
<br />
前一节讨论了如何通过一个有着已知URI的资源来操纵模型。本节要讨论查询模型。核心的Jena API只支持一些有限的查询原语。对于更强大查询设备RDQL的介绍不在此文档中。<br />
<br />
列出模型所有陈述的Model.listStatements()方法也许是最原始的查询模型方式。然而并不推荐在大型的模型上使用这个方法。类似的有Model.listSubjects()，但其所返回的iterator会迭代所有含有属性的资源，例如是一些陈述的主体。<br />
<br />
Model.listSubjectsWithProperty(Property p, RDFNode o)方法所返回的iterator跌代了所有具有属性p且p属性的值为o的资源。我们可能会预计使用rdf:type属性来搜索资源的类型属性以获得所有的vcard资源：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;retrieve&nbsp;all&nbsp;resource&nbsp;of&nbsp;type&nbsp;Vcard.</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">ResIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listSubjectsWithProperty(RDF.type,&nbsp;VCARD.Vcard);</span></div>
<br />
然而，不幸的是，我们现在正在使用的vcard模式并没有为vcard定义类型。然而，如果我们假设只有类型为vcard的资源才会使用vcard:FN属性，并且在我们的数据中，所有此类资源都有这样一个属性，那么我们就可以像这样找到所有的vcard：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;list&nbsp;vcards</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">ResIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listSubjectsWithProperty(VCARD.FN);<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;Resource&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;iter.nextResource();<br />
&nbsp;&nbsp;&nbsp; ...<br />
}</span></div>
<br />
所有的这些查询方法不过是在原语查询方法model.listStatements(Select s)上稍做变化而已。此方法会返回一个iterator，该iterator会跌代模型中所有被s选中的陈述。这个selector接口被设计成可扩展的，但是目前，它只有一个执行类，那就是com.hp.hpl.jena.rdf.model包中的SimpleSelector类。在Jena中使用SimpleSelector 是很少见的情况，即当需要直接使用一个特定类而不是使用接口。SimpleSelector的构造函数带有三个参数：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">Selector&nbsp;selector&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(subject,&nbsp;predicate,&nbsp;object)</span></div>
<br />
这个selector会选择所有主体与参数subject相配，谓词与参数predicate相配，且客体与参数object相配的陈述。<br />
<br />
如果某个参数值为null，则它表示与任何值均匹配；否则的话，它们就会匹配一样的资源或文本。（当两个资源有相同的URI或是同一个空白结点时，这两个资源就是一样的；当两个文本是一样的当且仅当它们的所有成分都是一样的。）所以：<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">Selector&nbsp;selector&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">); <br />
</span></div>
<br />
会选择模型中所有的陈述。<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">Selector&nbsp;selector&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,&nbsp;VCARD.FN,&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">); <br />
</span></div>
<br />
会选择所有谓词为VCARD.FN的陈述，而对主体和客体没有要求。作为一个特殊的缩写<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">listStatements(S,&nbsp;P,&nbsp;O)</span></div>
<br />
等同于<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">listStatements(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;SimpleSelector(S,&nbsp;P,&nbsp;O))</span></div>
<br />
下面的代码可以在Tutorial7中找到，列举了数据库中所有vcard中的全名。<br />
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;java&nbsp;code<br />
</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;select&nbsp;all&nbsp;the&nbsp;resources&nbsp;with&nbsp;a&nbsp;VCARD.FN&nbsp;property</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);">ResIterator&nbsp;iter&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;model.listSubjectsWithProperty(VCARD.FN);<br />
</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">The&nbsp;database&nbsp;contains&nbsp;vcards&nbsp;for:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(iter.hasNext())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;iter.nextStatement()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getProperty(VCARD.FN)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getString());<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">No&nbsp;vcards&nbsp;were&nbsp;found&nbsp;in&nbsp;the&nbsp;database</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
}</span></div>
<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;jruby&nbsp;code</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">require</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
<br />
module&nbsp;Java<br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.rdf.model</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.vocabulary</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">com.hp.hpl.jena.util</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;include_package&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">java.io</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;InputFileName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">vc-db-1.rdf</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Java</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ModelFactory</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">createDefaultModel<br />
&nbsp;&nbsp;&nbsp;&nbsp;input_stream&nbsp;<