XML Design - (A Gentle Transition from XML to RDF)(一个很好的关于RDF的slides)
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>
表明当前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>
<?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>
<?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>
前者通常用来定义一个资源;后者通常用来扩展这个资源的信息.
假设已经定义了:
<?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>
<?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>
<?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>
<?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>
<?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>
(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>
一个集合中任一资源
有先后顺序的property
用来标识Bag/Alt/Seq里的一个item
This may be added as an attribute of a property to indicate that the contents of the property is a list of resources.
rdf:Bag/Alt/Seq都属于容器,容器的一个缺点是没有办法封闭它,即没有办法说这些是容器的所有成员。一个容器只说一些有标识的资源是它的成员,无法说没有其他的成员了。而且,如果有一个图描述它的一些成员,我们没法排除在其他地方有图也描述这个容器的其它成员的可能。RDF以RDF集合(collection)的形式提供了对描述特定成员的组的支持。一个RDF集合是用列表结构表示的一组事物,这个列表结构是用一些预定义的集合词汇表示的。
使用这个属性会使内容失去resource/property/value的结构,应该尽量少用.
推荐所有的XML文档都符合RDF规范.
(1) RDF文档中的跟资源不应该是匿名的,否则就没有意义了.
(2) RDF中property不能有attribute(RDF attribute除外).