+ All Categories
Home > Documents > 1 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation. XML Design (A Gentle Transition...

1 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation. XML Design (A Gentle Transition...

Date post: 24-Dec-2015
Category:
Upload: justin-barton
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
85
1 Costello, David B. Jacobs. © 2003 The MITRE Corporation. XML Design (A Gentle Transition from XML to RDF) Roger L. Costello David B. Jacobs The MITRE Corporation (The creation of this tutorial was sponsored by DARPA)
Transcript

1 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

XML Design(A Gentle Transition from XML to RDF)

Roger L. Costello

David B. Jacobs

The MITRE Corporation(The creation of this tutorial was sponsored by DARPA)

2 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Acknowledgments

• We are very grateful to the Defense Agency Research Projects Agency (DARPA) for funding the creation of this tutorial. We are especially grateful to Murray Burke (DARPA) and John Flynn (BBN) for making it all happen.

• Special thanks to Frank Manola for answering our many questions.

3 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

What is the Purpose of RDF?• The purpose of RDF (Resource Description

Framework) is to give a standard way of specifying data "about" something.

• Here's an example of an XML document that specifies data about China's Yangtze river:

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river"> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

"Here is data about the Yangtze River. It has a length of 6300 kilometers.Its startingLocation is western China's Qinghai-Tibet Plateau. Its endingLocationis the East China Sea."

4 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

XML --> RDF

<?xml version="1.0"?><River id="Yangtze" 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

Modify the following XML document so that it is also a valid RDF document:

<?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

Yangtze.xml

Yangtze.rdf

"convert to"

5 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The RDF Format

<?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 provides an ID attribute for identifying the resource being described.

The ID attribute is in the RDF namespace.

Add the "fragment identifier symbol" to the namespace.

1

2

3

6 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The RDF Format (cont.)

<?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>

Identifies the type(class) of the resource being described.

Identifies the resource being described. Thisresource is an instance of River.

These are properties,or attributes, of thetype (class).

Values of the properties

1

2

3

4

7 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Namespace Convention

xmlns="http://www.geodesy.org/river#"

Question: Why was "#" placed onto the end of the namespace? E.g.,

Answer: RDF is very concerned about uniquely identifying things - uniquely identifying the type (class) and uniquely identifying the properties.If we concatenate the namespace with the type then we get a uniqueidentifier for the type, e.g.,

http://www.geodesy.org/river#River

If we concatenate the namespace with a property then we get a uniqueidentifier for the property, e.g.,

http://www.geodesy.org/river#length

http://www.geodesy.org/river#startingLocation

http://www.geodesy.org/river#endingLocation

Thus, the "#" symbol is simply a mechanism for separating the namespace from the type name and the property name.

Bes

t Pra

ctic

eB

est Practice

8 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The RDF Format

<?xml version="1.0"?><Class rdf:ID="Resource" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="uri"> <property>value</property> <property>value</property> ...</Class>

9 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Advantage of using the RDF Format• You may ask: "Why should I bother designing my XML to be in the

RDF format?"

• Answer: there are numerous benefits:– The RDF format, if widely used, will help to make XML more

interoperable:• Tools can instantly characterize the structure, "this element is a type (class), and

here are its properties”.

• RDF promotes the use of standardized vocabularies ... standardized types (classes) and standardized properties.

– The RDF format gives you a structured approach to designing your XML documents. The RDF format is a regular, recurring pattern.

– It enables you to quickly identify weaknesses and inconsistencies of non-RDF-compliant XML designs. It helps you to better understand your data!

– You reap the benefits of both worlds:• You can use standard XML editors and validators to create, edit, and validate

your XML.

• You can use the RDF tools to apply inferencing to the data.

– It positions your data for the Semantic Web!

Net

wor

k ef

fect

Inte

rope

rabi

lity

10 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Disadvantage of using the RDF Format

• Constrained: the RDF format constrains you on how you design your XML (i.e., you can't design your XML in any arbitrary fashion).

• RDF uses namespaces to uniquely identify types (classes), properties, and resources. Thus, you must have a solid understanding of namespaces.

• Another XML vocabulary to learn: to use the RDF format you must learn the RDF vocabulary.

11 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Uniquely Identify the Resource

• Earlier we said that RDF is very concerned about uniquely identifying the type (class) and the properties. RDF is also very concerned about uniquely identifying the resource, e.g.,

<?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>

This is the resource being described. We want to uniquelyidentify this resource.

12 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:ID• The value of rdf:ID is a "relative URI".

• The "complete URI" is obtained by concatenating the URL of the XML document with "#" and then the value of rdf:ID, e.g.,

<?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>

Suppose that this RDF/XML document is located at this URL: http://www.china.org/geography/rivers.Thus, the complete URI for this resource is:

Yangtze.rdf

http://www.china.org/geography/rivers#Yangtze

13 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

xml:base• On the previous slide we showed how the URL of the document provided the base URI.

• Depending on the location of the document is brittle: it will break if the document is moved, or is copied to another location.

• A more robust solution is to specify the base URI in the document, e.g.,

<?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>

Resource URI = concatenation(xml:base, '#', rdf:ID) = concatenation(http://www.china.org/geography/rivers, '#', "Yangtze") = http://www.china.org/geography/rivers#Yangtze

14 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:about

• Instead of identifying a resource with a relative URI (which then requires a base URI to be prepended), we can give the complete identity of a resource. However, we use rdf:about,

rather than rdf:ID, e.g.,

<?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>

15 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Triple -> resource/property/value

http://www.china.org/geography/rivers#Yangtze has a http://www.geodesy.org/river#length of 6300 kilometers

resource property value

http://www.china.org/geography/rivers#Yangtze has a http://www.geodesy.org/river#startingLocation of western China's ...

resource property value

http://www.china.org/geography/rivers#Yangtze has a http://www.geodesy.org/river#endingLocation of East China Sea

resource property value

16 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The RDF Format = triples!• The fundamental design pattern of RDF is to structure your XML data

as resource/property/value triples!

The value of a property can be a literal (e.g., length has a value of 6300 kilometers).Also, the value of a property can be a resource, as shown above (e.g., property-Ahas a value of Resource-B, property-B has a value of Resource-C). We will see examplesof properties having a resource value in a little bit.

<?xml version="1.0"?><Resource-A> <property-A> <Resource-B> <property-B> <Resource-C> <property-C> Value-C </property-C> </Resource-C> </property-B> </Resource-B> </property-A></Resource-A>

value of property-A

value of property-B

Notice that the RDF design pattern is analternating sequence of resource-property.

This pattern is known as "striping".

17 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Naming Convention

• The convention is to use a capital letter to start a type (class) name, and use a lowercase letter to start a property name.– This helps the eye quickly discern the striping

pattern.<?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>

uppercase

lowercase

18 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Model (graph)

Legend: Ellipse indicates "Resource" Rectangle indicates "literal string value"

19 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:Description + rdf:type• There is still another way of representing the XML. This way makes it

very clear that you are describing something, and it makes it very clear what the type (class) is of the thing you are describing:

<?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>

This is read as: "This is a Description about the resource http://www.china.org/geography/rivers#Yangtze.This resource is an instance of the River type (class). The http://www.china.org/geography/rivers#Yangtzeresource has a length of 6300 kilometers, a startingLocation of western China's Qinghai-Tibet Plateau,and an endingLocation of the East China Sea."

Note: this form of describing a resource is called the "long form". The form we have seen previously is anabbreviation of this long form. An RDF Parser interprets the abbreviated form as if it were this long form.

20 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Alternative

• Alternatively we can use rdf:ID rather than rdf:about, as shown here:

<?xml version="1.0"?><rdf:Description 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"> <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>

21 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Equivalent Representations!

<?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>

Note: In the RDF literature the examplesare typically shown in this form.

22 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Namespace

http://www.w3.org/1999/02/22-rdf-syntax-ns#

ID

about

type

resource

Description

23 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Terminology

• As you read the RDF literature you may see the following terminology:– Subject: this term refers to the item that is playing the role of the

resource.

– predicate: this term refers to the item that is playing the role of the property.

– Object: this term refers to the item that is playing the role of the value.

Subject Objectpredicate

Resource Valueproperty

Equivalent!

24 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Parser

• There is a nice RDF parser at the W3 Web site:

http://www.w3.org/RDF/Validator/

This RDF parser will tell you if your XMLis in the proper RDF format.

Do Lab1

25 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #2

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river"> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation> <Dam id="ThreeGorges" xmlns="http://www.geodesy.org/dam"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam></River>

Yangtze2.xml

Modify the following XML document so that it is RDF-compliant:

26 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Note the two types (classes)

River Dam

Instance: YangtzeProperties:

lengthstartingLocationendingLocation

Instance: ThreeGorgesProperties:

namewidthheightcost

27 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Dam - out of place<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river"> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation> <Dam id="ThreeGorges" xmlns="http://www.geodesy.org/dam"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam></River>Dam

Types (classes) contain properties . Here we see the River type containing the properties - length, startingLocation, and endingLocation. It also shows River containing a type - Dam. Thus, there is a Resource that contains another Resource. This is inconsistent with RDF design pattern. (We are seeing one of the benefits of using the RDF format - to identify inconsistencies in an XML design.)

28 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Property value must be a Literal or a Resource

<length>6300 kilometers</length>

property

Value is a Literal

<obstacle> <Dam id="ThreeGorges" xmlns="http://www.geodesy.org/dam"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam></obstacle>

property

Value is a Resource

29 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Modified XML (to make it consistent)<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river"> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation> <obstacle> <Dam id="ThreeGorges" xmlns="http://www.geodesy.org/dam"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam> </obstacle></River>

Yangtze2,v2.xml

"The Yangtze River has an obstacle that is the ThreeGorges Dam. The Damhas a name - The Three Gorges Dam. It has a width of 1.5 miles, a height of 610 feet,and a cost of $30 billion."

30 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Format<?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> <Dam rdf:ID="ThreeGorges" xmlns="http://www.geodesy.org/dam#"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam> </obstacle></River>

Changed id to rdf:IDAdded the '#' symbol

As always, the other representations using rdf:about and rdf:Description are available.

31 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Model (graph)

32 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?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>

Three-Gorges-Dam.rdf

Alternatively, suppose that someone has already created a document containing information about the Three Gorges Dam:

Yangtze.rdf

Then we can simply reference the Three Gorges Dam resource using rdf:resource, as shown here:

33 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Note: reference is to a resource, not to a file

<obstacle rdf:resource="http://www.china.org/geography/rivers #ThreeGorges"/>

Why was this the reference:

<obstacle rdf:resource="http://www.china.org/geography/rivers /Three-Gorges-Dam.rdf"/>

and not this:

That is, why wasn't the reference to a "file"?

Answer:1. What if the file moved? Then the reference would break.2. By using an identifier of the Three Gorges Dam, and keeping a particular file unspecified, then an "aggregator tool" will be able to collect information from all the files that talk about the Three Gorges Dam resource (see next slide).

Do Lab2

34 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Anyone, Anywhere, Anytime Can Talk About a Resource

• In all of our examples we have provided a unique identifier to resources, e.g.,

http://www.china.org/geography/rivers#Yangtze

• Consequently, if another RDF document identifies the same resource then the data that it specifies gives additional data about that resource.

• An aggregator tool will be able to collect all data about a resource and present a consolidated set of data for the resource. That's powerful!

35 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:ID versus rdf:about

• When should rdf:ID be used? When should rdf:about be used?– When you want to introduce a resource, and provide

an initial set of information about a resource use rdf:ID

– When you want to extend the information about a resource use rdf:about

• The RDF philosophy is akin to the Web philosophy. That is, anyone, anywhere, anytime can provide information about a resource.

36 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?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>

http://www.china.org/geography/rivers/yangtze.rdf <?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#"> <name>Dri Chu - Female Yak River</name> <name>Tongtian He, Travelling-Through-the-Heavens River</name> <name>Jinsha Jiang, River of Golden Sand</name> </River>

http://www.encyclopedia.org/yangtze-alternate-names.rdf

<?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> <name>Dri Chu - Female Yak River</name> <name>Tongtian He, Travelling-Through-the-Heavens River</name> <name>Jinsha Jiang, River of Golden Sand</name> </River>

Aggregated Data!

Aggregator tool collectsdata about the Yangtze

A distributed network of data!

37 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?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>

http://www.china.org/geography/rivers/yangtze.rdf

http://www.encyclopedia.org/three-gorges-dam.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> <obstacle> <Dam rdf:ID="ThreeGorges" xmlns="http://www.geodesy.org/dam#"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam> </obstacle></River>

Aggregate!

Note that the reference to the ThreeGorges Dam resource has been replaced by whatever information the aggregator could find on this resource!

Another Example of Aggregation

38 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #3

<?xml version="1.0"?><River xmlns="http://www.geodesy.org/river#"> <name>Yangtze</name> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

Notice that in this XML document there is no unique identifier:

Yangtze3.xml

XML

<?xml version="1.0"?><River xmlns="http://www.geodesy.org/river#"> <name>Yangtze</name> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

Yangtze3.rdf

RDF

The RDF isidentical to theXML!

39 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Interpreting the RDF

<?xml version="1.0"?><River xmlns="http://www.geodesy.org/river#"> <name>Yangtze</name> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

Yangtze3.rdf

This is read as: "This is an instance of the River type (class). The River has aname of Yangtze, a length of 6300 kilometers, a startingLocation of western China's Qinghai-Tibet Plateau, and an endingLocation of the East China Sea."

In this document the resource is anonymous - it has no identifier.

40 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Disadvantage of anonymous resources

<?xml version="1.0"?><River xmlns="http://www.geodesy.org/river#"> <name>Yangtze</name> <length>6300 kilometers</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

http://www.china.org/geography/rivers/yangtze.rdf

<?xml version="1.0"?><River xmlns="http://www.geodesy.org/river#"> <name>Yangtze</name> <name>Dri Chu - Female Yak River</name> <name>Tongtian He, Travelling-Through-the-Heavens River</name> <name>Jinsha Jiang, River of Golden Sand</name> </River>

http://www.encyclopedia.org/yangtze-alternate-names.rdf

An aggregator tool will not be able to determine if these documents are talking about the same resource.

Aggregate

41 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #4<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" xmlns:uom="http://www.measurements.org/units-of-measure"> <length uom:units="kilometers">6300</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

XML

Yangtze4.xml

Yangtze4.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#" 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>

RDF

42 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" xmlns:uom="http://www.measurements.org/units-of-measure#"> <length uom:units="kilometers">6300</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

Yangtze4.xml

RDF does not allow attributes on the properties (except for special RDFattributes such as rdf:resource). So we need to make the uom:units attributea child element.Your first instinct might be to modify length to have two child elements:

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" xmlns:uom="http://www.measurements.org/units-of-measure#"> <length> <value>6300</value> <uom:units>kilometers</uom:units> </length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation></River>

However, nowthe lengthproperty hasas its value twovalues.RDF only binary relationsi.e., a single value for aproperty.

43 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:value

length6300

kilometers

length has two values - 6300 and kilometers.RDF provides a special property, rdf:value, tobe used for specifying the "primary" value.In this example, 6300 is the primary value, andkilometers is a value which provides additionalinformation about the primary value.

44 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Format

<?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>

Yangtze4.rdf

An anonymousresource

Read this as: "The Yangtze River has a length whose value is a resourcewhich has a value of 6300 and whose units is kilometers.

45 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Advantage of anonymous resources

<rdf:Description> <rdf:value>6300</rdf:value> <uom:units>kilometers</uom:units></rdf:Description>

This is an anonymous resource. Its purposeis solely to provide a context for the twoproperties. Other RDF documents will haveno need to amplify this resource. So, in this case, there is no reason for giving theresource an identifier. In this case it makes good sense to use an anonymous resource.

46 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Model (graph)

An anonymous resource (also called a "blank node"). That is, a resource with no identifier. (Note: RDF Parsers will typicallygenerate a unique identifier for anonymous resources, todistinguish one anonymous resource from another.)

Legend:

47 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:parseType="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: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>

Yangtze4,v2.rdf

If the value of a property is comprised of several values then one option is to create an anonymous resource, as we saw. RDF provides a shorthand,so that you don't need to create an rdf:Description element, by using rdf:parseType="Resource", as shown here:

The meaning of this is identical to that shown on the previous slide.

48 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Equivalent!

<length> <rdf:Description> <rdf:value>6300</rdf:value> <uom:units>kilometers</uom:units> </rdf:Description></length>

<length rdf:parseType="Resource"> <rdf:value>6300</rdf:value> <uom:units>kilometers</uom:units></length>

Do Lab3

49 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Summary

Modify the following XML document so that it is also a valid RDF document:

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" xmlns:uom="http://www.measurements.org/units-of-measure#"> <length uom:units="kilometers">6300</length> <startingLocation>western China's Qinghai-Tibet Plateau</startingLocation> <endingLocation>East China Sea</endingLocation> <Dam id="ThreeGorges" xmlns="http://www.geodesy.org/dam"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam></River>

Yangtze.xml

See next slide -->

50 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Format!

<?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#" xml:base="http://www.china.org/geography/rivers"> <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> <obstacle> <Dam rdf:ID="ThreeGorges" xmlns="http://www.geodesy.org/dam#"> <name>The Three Gorges Dam</name> <width>1.5 miles</width> <height>610 feet</height> <cost>$30 billion</cost> </Dam> </obstacle></River>

Yangtze.rdf

With relativelyfew changes theXML documentis now usable byboth XML toolsand RDF tools!

51 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #5<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" xmlns:uom="http://www.measurements.org/units-of-measure#"> <length uom:units="kilometers">6300</length> <maxWidth uom:units="meters">175</maxWidth> <maxDepth uom:units="meters">55</maxDepth></River>

Yangtze5.xml

Modify the following XML document so that it is also a valid RDF document:

<?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> <maxWidth rdf:parseType="Resource"> <rdf:value>175</rdf:value> <uom:units>meters</uom:units></maxWidth> <maxDepth rdf:parseType="Resource"> <rdf:value>55</rdf:value> <uom:units>kilometers</uom:units> </maxDepth></River>

Yangtze5.rdf

This is one way of doing it.Now we will see a betterway - using "typed literals".(See next slide)

52 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Alternate RDF Format

<?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>

Yangtze5.rdf

With rdf:datatype you can give a property's value a datatype label. Therdf:datatype value acts as a semantic label for the datatype of the value.This is called a typed literal.

For this example there must be a namespace, http://www.uom.org/distance#,which defines two datatypes - kilometer and meter.

On the next slide is shown how to do this using XML Schemas.

53 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Defining the kilometer and meter datatypes using XML Schemas

<?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>

uom.xsd

54 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Another example using rdf:datatype

<?xml version="1.0"?><Person rdf:ID="JohnSmith" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.person.org#"> <age rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">30</age></Person>

In this example we are specifying that the value (30) of age is a nonNegativeInteger (which is defined in the XML Schema namespace).

55 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #6

<?xml version="1.0"?><WeatherReading xmlns="http://www.meteorology.org#"> <Weather> <temperature>-2 degrees Celsius</temperature> <barometer>30.4 (rising)</barometer> </Weather> <Location xmlns="http://www.geodesy.org#"> <country>USA</country> <state>Massachusetts</state> <city>Boston</city> </Location> <datetime>January 22, 2003, 11:15 EST</datetime></WeatherReading>

WMUR_TV_WeatherReading.xml

Modify the following XML document so that it is also a valid RDF document:

56 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Things to note

1. The XML document is using three types (classes):

WeatherReading Weather Location

2. The 3 type instances are anonymous. Consequently, we cannot benefit from others, and others cannot benefit from us. Where does it make sense to give an identifier to an instance? - In general, the root element should have an identifier. - There is lots of information about Boston. Let's give the Location instance an identifier.

57 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Modification 1: Identifiers added

<?xml version="1.0"?><WeatherReading id="BOS-012203-1115" xmlns="http://www.meteorology.org#"> <Weather> <temperature>-2 degrees Celsius</temperature> <barometer>30.4 (rising)</barometer> </Weather> <Location id="BOS" xmlns="http://www.geodesy.org#"> <country>USA</country> <state>Massachusetts</state> <city>Boston</city> </Location> <datetime>January 22, 2003, 11:15 EST</datetime></WeatherReading>

WMUR_TV_WeatherReading,v2.xml

58 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Modification 2: Create a property for the Weather, Location types

Types (classes) contain properties. We need to wrap the Weather and Locationtypes within a property:

<?xml version="1.0"?><WeatherReading id="BOS-012203-1115" xmlns="http://www.meteorology.org#"> <instrumentReading> <Weather> <temperature>-2 degrees Celsius</temperature> <barometer>30.4 (rising)</barometer> </Weather> </instrumentReading> <instrumentLocation> <Location id="BOS" xmlns="http://www.geodesy.org#"> <country>USA</country> <state>Massachusetts</state> <city>Boston</city> </Location> </instrumentLocation> <datetime>January 22, 2003, 11:15 EST</datetime></WeatherReading>

WMUR_TV_WeatherReading,v3.xml

59 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Format!<?xml version="1.0"?><WeatherReading rdf:ID="BOS-012203-1115" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.meteorology.org#" xml:base="http://www.wmur-tv.com/weather"> <instrumentReading> <Weather> <temperature>-2 degrees Celsius</temperature> <barometer>30.4 (rising)</barometer> </Weather> </instrumentReading> <instrumentLocation> <Location rdf:ID="BOS" xmlns="http://www.geodesy.org#" xml:base="http://www.airports.org/icao"> <country>USA</country> <state>Massachusetts</state> <city>Boston</city> </Location> </instrumentLocation> <datetime>January 22, 2003, 11:15 EST</datetime></WeatherReading>

WMUR_TV_WeatherReading.rdf

60 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The rdf:Bag type (class)

• The rdf:Bag type is used to represent an unordered collection.

61 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #7

<?xml version="1.0"?><Meeting id="XML-Design-Patterns" xmlns="http://www.business.org"> <attendees> <name>John Smith</name> <name>Sally Jones</name> </attendees></Meeting>

Modify the following XML document so that it is also a valid RDF document:

DesignMeeting.xml

rdf:Bag makes it clear that this is an unorderedcollection of names.

<?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> <name>John Smith</name> <name>Sally Jones</name> </rdf:Bag> </attendees></Meeting>

DesignMeeting.rdf

62 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The rdf:Alt type (class)

• The rdf:Alt type is used to represent a set of alternate properties.

63 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #8<?xml version="1.0"?><Retailer id="BarnesAndNoble" xmlns="http://www.retailers.org"> <webLocation> <url>http://www.bn.com</url> <url>http://www.barnesandnoble.com</url> </webLocation></Retailer>

Modify the following XML document so that it is also a valid RDF document:

BarnesAndNoble.xml

rdf:Alt makes it clear that the urls listed arealternates, i.e., chooseone of them.

<?xml version="1.0"?><Retailer rdf:ID="BarnesAndNoble" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.retailers.org#"> <webLocation> <rdf:Alt> <url>http://www.bn.com</url> <url>http://www.barnesandnoble.com</url> </rdf:Alt> </webLocation></Retailer>

BarnesAndNoble.rdf

64 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

The rdf:Seq type (class)

• The rdf:Seq type is used to represent a sequence of properties.

65 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #9<?xml version="1.0"?><ToDoList id="MondayMeetings" xmlns="http://www.reminders.org"> <activities> <activity1>Meet with CEO at 10am</activity1> <activity2>Luncheon at The Eatery</activity2> <activity3>Flight at 3pm</activity3> </activities></ToDoList>

Modify the following XML document so that it is also a valid RDF document:

MyDaysActivities.xml

rdf:Seq makes it clear that the activities listed are to be done in thesequence listed.

<?xml version="1.0"?><ToDoList rdf:ID="MondayMeetings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.reminders.org#"> <activities> <rdf:Seq> <activity1>Meet with CEO at 10am</activity1> <activity2>Luncheon at The Eatery</activity2> <activity3>Flight at 3pm</activity3> </rdf:Seq> </activities></ToDoList>

MyDaysActivities.rdf

66 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:li Property

• The property, rdf:li ("list item"), is provided by RDF for use with either rdf:Bag, rdf:Alt, or rdf:Seq.

• The rdf:li property is provided for you to specify an item in a Bag/Alt/Seq.

• An RDF Parser will replace each rdf:li with rdf:_1, rdf:_2, rdf:_3, etc.

• The following slide recasts the previous examples using the rdf:li property.

67 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?xml version="1.0"?><ToDoList rdf:ID="MondayMeetings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.reminders.org#"> <activities> <rdf:Seq> <rdf:li>Meet with CEO at 10am</rdf:li> <rdf:li>Luncheon at The Eatery</rdf:li> <rdf:li>Flight at 3pm</rdf:li> </rdf:Seq> </activities></ToDoList>

MyDaysActivities.rdf

<?xml version="1.0"?><Retailer rdf:ID="BarnesAndNoble" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.retailers.org#"> <webLocation> <rdf:Alt> <rdf:li>http://www.bn.com</rdf:li> <rdf:li>http://www.barnesandnoble.com</rdf:li> </rdf:Alt> </webLocation></Retailer>

BarnesAndNoble.rdf

<?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>

DesignMeeting.rdf

68 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #10Modify the following XML document so that it is also a valid RDF document:

<?xml version="1.0"?><Catalogue xmlns="http://www.publishing.org#" xmlns:dc="http://pur1.org/metadata/dublin-core#"> <Book> <dc:Title>Lateral Thinking</dc:Title> <dc:Creator>Edward de Bono</dc:Creator> <dc:Date>1973</dc:Date> <ISBN>0-06-099325-2</ISBN> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> <Book> <dc:Title>Illusions: The Adventures of a Reluctant Messiah</dc:Title> <dc:Creator>Richard Bach</dc:Creator> <dc:Date>1977</dc:Date> <ISBN>0-440-34319-4</ISBN> <dc:Publisher>Dell Publishing Co.</dc:Publisher> </Book> <Book> <dc:Title>The First and Last Freedom</dc:Title> <dc:Creator>J. Krishnamurti</dc:Creator> <dc:Date>1954</dc:Date> <ISBN>0-06-064831-7</ISBN> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book></Catalogue>

Barnes_and_Noble _BookCatalogue.xml

Note: regrettably,the Dublin Core doesnot conform to theRDF naming conventions. Hence,you see propertieswith the first lettercapitalized.

69 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Things to note

1. The XML document uses two types (classes):

Catalogue Book

2. All type instances are anonymous. Consequently, we cannot benefit from others, and others cannot benefit from us. Where does it make sense to give the instance an identifier? - In general, the root element should have an identifier.

- There is lots of information about each book instance. Let's give each book instance an identifier (the ISBN).

70 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Modification 1: Identifiers added<?xml version="1.0"?><Catalogue id="BookCatalogue" xmlns="http://www.publishing.org#" xmlns:dc="http://pur1.org/metadata/dublin-core#"> <Book id="_0-06-099325-2"> <dc:Title>Lateral Thinking</dc:Title> <dc:Creator>Edward de Bono</dc:Creator> <dc:Date>1973</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> <Book id="_0-440-34319-4"> <dc:Title>Illusions: The Adventures of a Reluctant Messiah</dc:Title> <dc:Creator>Richard Bach</dc:Creator> <dc:Date>1977</dc:Date> <dc:Publisher>Dell Publishing Co.</dc:Publisher> </Book> <Book id="_0-06-064831-7"> <dc:Title>The First and Last Freedom</dc:Title> <dc:Creator>J. Krishnamurti</dc:Creator> <dc:Date>1954</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book></Catalogue>

Barnes_and_Noble _BookCatalogue,v2.xml

Notice that the ISBN elements were deleted and their values used as identifiers.

Why was an underscoreplaced in front of theISBN?Answer: The ID datatypedoes not allow an identifier to begin witha digit. So, we (arbitrarily) decided touse an underscore.

71 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Modification 2: Create a property for the Book type

Barnes_and_Noble _BookCatalogue,v3.xml

Types (classes) contain properties. We need to wrap the Book type within a property:

<?xml version="1.0"?><Catalogue id="BookCatalogue" xmlns="http://www.publishing.org#" xmlns:dc="http://pur1.org/metadata/dublin-core#"> <item> <Book id="_0-06-099325-2"> <dc:Title>Lateral Thinking</dc:Title> <dc:Creator>Edward de Bono</dc:Creator> <dc:Date>1973</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> </item> <item> <Book id="_0-440-34319-4"> <dc:Title>Illusions: The Adventures of a Reluctant Messiah</dc:Title> <dc:Creator>Richard Bach</dc:Creator> <dc:Date>1977</dc:Date> <dc:Publisher>Dell Publishing Co.</dc:Publisher> </Book> </item> <item> <Book id="_0-06-064831-7"> <dc:Title>The First and Last Freedom</dc:Title> <dc:Creator>J. Krishnamurti</dc:Creator> <dc:Date>1954</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> </item></Catalogue>

72 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

RDF Format!<?xml version="1.0"?><Catalogue rdf:ID="BookCatalogue" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.publishing.org#" xmlns:dc="http://pur1.org/metadata/dublin-core#" xml:base="http://www.bn.com"> <item> <Book rdf:ID="_0-06-099325-2" xml:base="http://www.publishing.org/book"> <dc:Title>Lateral Thinking</dc:Title> <dc:Creator>Edward de Bono</dc:Creator> <dc:Date>1973</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> </item> <item> <Book rdf:ID="_0-440-34319-4" xml:base="http://www.publishing.org/book"> <dc:Title>Illusions: The Adventures of a Reluctant Messiah</dc:Title> <dc:Creator>Richard Bach</dc:Creator> <dc:Date>1977</dc:Date> <dc:Publisher>Dell Publishing Co.</dc:Publisher> </Book> </item> ...</Catalogue>

Barnes_and_Noble_BookCatalogue.rdf

73 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Dublin Core (dc:)

• The Dublin Core is a standard set of properties:

Content IntellectualProperty

Instance

TitleSubjectDescriptionLanguageRelationCoverageSource

CreatorPublisherContributorRights

DateTypeFormatIdentifier

Note: many people use these properties in their HTML today. For example: <META NAME="DC.Creator" CONTENT="John Smith">

74 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

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.

• The following slide recasts the BookCatalogue example to use this list type.

75 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?xml version="1.0"?><Catalogue rdf:ID="BookCatalogue" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.publishing.org#" xmlns:dc="http://pur1.org/metadata/dublin-core#" xml:base="http://www.bn.com"> <books rdf:parseType="Collection"> <Book rdf:ID="_0-06-099325-2" xml:base="http://www.publishing.org/book"> <dc:Title>Lateral Thinking</dc:Title> <dc:Creator>Edward de Bono</dc:Creator> <dc:Date>1973</dc:Date> <dc:Publisher>Harper &amp; Row</dc:Publisher> </Book> <Book rdf:ID="_0-440-34319-4" xml:base="http://www.publishing.org/book"> <dc:Title>Illusions: The Adventures of a Reluctant Messiah</dc:Title> <dc:Creator>Richard Bach</dc:Creator> <dc:Date>1977</dc:Date> <dc:Publisher>Dell Publishing Co.</dc:Publisher> </Book> ... </books></Catalogue>

Barnes_and_Noble_BookCatalogue.rdf Do Lab4

76 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #11

<?xml version="1.0"?><Article rdf:ID="QuickBrownFox" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.publishing.org#"> <paragraph rdf:parseType="Literal"> The quick brown <bold>fox</bold> jumped over the lazy dog. An important person once said "<quote>Now is the time for all good men to come to the aid of their country</quote>" </paragraph></Article>

QuickBrownFox.rdf

rdf:parseType="Literal"indicates that the contentof paragraph is to be treated simply as literalXML, i.e., tools shouldn't tryto parse the content into resource/property/value triples.

<?xml version="1.0"?><Article id="QuickBrownFox" xmlns="http://www.publishing.org"> <paragraph> The quick brown <bold>fox</bold> jumped over the lazy dog. An important person once said "<quote>Now is the time for all good men to come to the aid of their country</quote>" </paragraph></Article>

Modify the following XML document so that it is also a valid RDF document:

QuickBrownFox.xml

The paragraph contains"mixed content".

77 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

rdf:parseType="Literal"

• In all of the previous examples the data was structured as resource/property/value triples.

• Sometimes it doesn't make sense to do such structuring– Example: with mixed content

• In those cases we can simply indicate "hey, the content of this property is okay. Treat it as a literal XML string."

78 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Dangers of rdf:parseType="Literal"

• The advantage of structuring your XML as resource/property/value triples is enhanced interoperability.

• When you use rdf:parseType="Literal" you lose the ability for a tool to instantly take advantage of the resource/property/value structure (since you are, by definition, saying that the data doesn't have this structure).

• Lesson Learned: use rdf:parseType="Literal" sparingly!

79 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example 12

<?xml version="1.0"?><River id="Yangtze" xmlns="http://www.geodesy.org/river" length="6300 kilometers" startingLocation="western China's Qinghai-Tibet Plateau" endingLocation="East China Sea"/>

<?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:r="http://www.geodesy.org/river#" r:length="6300 kilometers" r:startingLocation="western China's Qinghai-Tibet Plateau" r:endingLocation="East China Sea"/>

XML

RDF

Yangtze.xml

Yangtze.rdf

Modify the following XML document so that it is also a valid RDF document:

Note that attributes arebeing used, not childelements!

The RDF format allowsyou to use attributes aswell!

80 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Attributes

• Recall that at the very beginning of this tutorial we said that a resource has properties (attributes). Thus, a property can be represented either as a child element, or as an attribute. (Of course, a property can only be represented as an attribute if it has a literal value, not a structured value.)

81 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Equivalent!

<?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:r="http://www.geodesy.org/river#" r:length="6300 kilometers" r:startingLocation="western China's Qinghai-Tibet Plateau" r:endingLocation="East China Sea"/>

<?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>

Do Lab5

82 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Example #13

<?xml version="1.0"?><Resume xmlns="http://www.resume.org#"> <Person xmlns="http://www.person.org#"> <name>John Smith</name> <phone>555-1212</phone> <email>[email protected]</email> </Person> <experience> <Job> <startDate>1995-01-01</startDate> <endDate>1999-01-01</endDate> <title>researcher</title> <employer>Some Corp</employer> <employerHomepage>http://www.company.org</employerHomepage> <description>Cool stuff</description> </Job> </experience> <skills> <Skill name="Oracle" yrs="13"/> <Skill name="Java" yrs="3"/> </skills> <education> <Degree type="BS" school="RPI" year="1987"/> </education></Resume>

Modify the following XML document so that it is also a valid RDF document:

83 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

<?xml version="1.0"?><Resume rdf:ID="JSmith-2003" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.resume.org#" xml:base="http://www.jsmith.com/resume"> <about> <Person xmlns="http://www.person.org#"> <name>John Smith</name> <phone>555-1212</phone> <email>[email protected]</email> </Person> </about> <experience rdf:parseType="Collection"> <Job> <startDate>1995-01-01</startDate> <endDate>1999-01-01</endDate> <title>researcher</title> <employer> <Company xmlns="http://www.company.org#"> <name>Some Corp</name> <homepage>http://www.company.org</homepage> </Company> </employer> <description>Cool stuff</description> </Job> </experience>

<skills rdf:parseType="Collection"> <Skill> <name>Oracle</name> <yearsExperience>13</yearsExperience> </Skill> <Skill> <name>Java</name> <yearsExperience>3 </yearsExperience> </Skill> </skills> <education rdf:parseType="Collection"> <Degree xmlns="http://www.schools.com#"> <type>BS</type> <school>RPI</school> <graduationYear>1987</graduationYear> </Degree> </education></Resume>

84 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Conclusion

• In this tutorial we demonstrated that, with oftentimes slight modifications, "traditional XML" documents can be made RDF-compliant.

• We recommend using the RDF format for all your XML documents.

• We feel that the advantages accrued by formatting your XML far outweigh any possible disadvantages (having to structure your XML in a specific format and having to learn a new vocabulary)

85 Roger L. Costello, David B. Jacobs. © 2003 The MITRE Corporation.

Related Articles

http://www.xml.com/pub/a/2002/10/30/rdf-friendly.html

"Make Your XML RDF-Friendly" by Bob DuCharme, John Cowan


Recommended