Roger L. Costello , David B. Jacobs
The MITRE Corporation
(The creation of this tutorial was sponsored by DARPA)
2003
这个ppt全面地介绍了RDF的内容,着重于比较XML与RDF的区别,有比较丰富的示例,明白易懂,是RDF入门的好材料. 文档里的练习过一段实践可以再做一遍,加深印象.
1. 一个基本的 RDF 文件
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#">
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
2. xml:base
表明当前rdf文档的”位置”, 由此文档中描述的资源可以被引用
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#"
xml:base="http://www.china.org/geography/rivers">
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
3. RDF 中的命名规则
type(class)由大写字母开头
property由小写字母开头
4. 3种等价的RDF文档表示方法
(1)
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#"
xml:base="http://www.china.org/geography/rivers">
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
(2)
<?xml version="1.0"?>
<River rdf:about="http://www.china.org/geography/rivers#Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#">
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
(3)
<?xml version="1.0"?>
<rdf:Description rdf:about="http://www.china.org/geography/rivers#Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#">
<rdf:type rdf:resource="http://www.geodesy.org/river#River"/>
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</rdf:Description>
rdf:ID 和rdf:about 的区别:
前者通常用来定义一个资源;后者通常用来扩展这个资源的信息.
5. 引用其它地方定义的 Resource
假设已经定义了:
<?xml version="1.0"?>
<Dam rdf:ID="ThreeGorges"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/dam#"
xml:base="http://www.china.org/geography/rivers">
<name>The Three Gorges Dam</name>
<width>1.5 miles</width>
<height>610 feet</height>
<cost>$30 billion</cost>
</Dam>
在下面的 RDF 文档里引用 ThreeGorges 这个 Resource:
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#"
xml:base="http://www.china.org/geography/rivers">
<length>6300 kilometers</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
<obstacle rdf:resource="http://www.china.org/geography/rivers#ThreeGorges"/>
</River>
6. 使用 aggregator tool 可以收集关于一个资源的分散的信息 .
7. anonymous resource
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#"
xmlns:uom="http://www.measurements.org/units-of-measure#">
<length>
<rdf:Description>
<rdf:value>6300</rdf:value>
<uom:units>kilometers</uom:units>
</rdf:Description>
</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
或写成 :
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#"
xmlns:uom="http://www.measurements.org/units-of-measure#">
<length rdf:parseType="Resource">
<rdf:value>6300</rdf:value>
<uom:units>kilometers</uom:units>
</length>
<startingLocation>western China's Qinghai-Tibet Plateau</startingLocation>
<endingLocation>East China Sea</endingLocation>
</River>
8. RDF Model
9. rdf:datatype
<?xml version="1.0"?>
<River rdf:ID="Yangtze"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.geodesy.org/river#">
<length rdf:datatype="http://www.uom.org/distance#kilometer">6300</length>
<maxWidth rdf:datatype="http://www.uom.org/distance#meter">175</maxWidth>
<maxDepth rdf:datatype="http://www.uom.org/distance#meter">55</maxDepth>
</River>
datatype 在 uom.xsd 里定义 :
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uom.org/distance#">
<simpleType name="kilometer">
<restriction base="integer">
</restriction>
</simpleType>
<simpleType name="meter">
<restriction base="integer">
</restriction>
</simpleType>
</schema>
10. rdf:Bag/Alt/Seq class
(1) rdf:Bag class
无序集合
e.g.
<?xml version="1.0"?>
<Meeting rdf:ID="XML-Design-Pattern"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.business.org#">
<attendees>
<rdf:Bag>
<rdf:li>John Smith</rdf:li>
<rdf:li>Sally Jones</rdf:li>
</rdf:Bag>
</attendees>
</Meeting>
(2) rdf:Alt class
一个集合中任一资源
(3) rdf:Seq class
有先后顺序的property
(4) rdf:li
用来标识Bag/Alt/Seq里的一个item
11. rdf:parseType="Collection"
This may be added as an attribute of a property to indicate that the contents of the property is a list of resources.
rdf:parseType="Collection" 与 rdf:Bag/Alt/Seq 的区别 ?
rdf:Bag/Alt/Seq都属于容器,容器的一个缺点是没有办法封闭它,即没有办法说这些是容器的所有成员。一个容器只说一些有标识的资源是它的成员,无法说没有其他的成员了。而且,如果有一个图描述它的一些成员,我们没法排除在其他地方有图也描述这个容器的其它成员的可能。RDF以RDF集合(collection)的形式提供了对描述特定成员的组的支持。一个RDF集合是用列表结构表示的一组事物,这个列表结构是用一些预定义的集合词汇表示的。
12. rdf:parseType="Literal"
使用这个属性会使内容失去resource/property/value的结构,应该尽量少用.
13. 结论
推荐所有的XML文档都符合RDF规范.
14. 注意事项 :
(1) RDF 文档中的跟资源不应该是匿名的 , 否则就没有意义了 .
(2) RDF 中 property 不能有 attribute(RDF attribute 除外 ).