Topik 3 RDF-
Topik 3 RDF-
edited by
RDF Semantics Pat Hayes
Encryption
SPARQL
Signature
(queries) RDF Schema
RDF
XML + Namespaces
URI Unicode
A family of data formats
• RDF/XML is the normative (standard) syntax
– Supported by almost all tools
• RDF/N3 (Notation3) is also widely used
– Non-XML syntax
– Variable tool support
– Primarily designed to be easy to write on whiteboards
• Other XML and non-XML syntaxes exist:
– Turtle, NTriples, TriX etc
RDF Requirements
RDF requirements
• A means for identifying objects and vocabulary terms (URIs)
• A means for distinguishing between terms from different
vocabularies (XML namespaces and qualified names)
• A means for serialising triples (XML)
URIs and URIrefs
Standard identifiers for the ontology
Uniform Resource Identifiers are defined by RFC2396
– http://example.org/
– urn:isbn:0198537379
– mailto:nmg@ecs.soton.ac.uk
• URI references (URIrefs) are URIs with optional fragment
identifiers
– http://example.org/index.html#Introduction
– http://www.w3.org/1999/02/22-rdf-syntax-ns#type
XML namespaces and qualified names
• RDF uses XML namespaces to refer to elements of domain
vocabularies
xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-
ns#”
namespace abbreviation namespace URI prefix
• Namespaces used to abbreviate URIrefs to qualified names
(QNames)
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
becomes
rdf:type
• QNames cannot be used in attribute values in RDF/XML
– Use the URIref instead
RDF/XML
RDF/XML
RDF/XML is an XML-based format for expressing a collection
of RDF triples (an RDF graph)
• Can be parsed by an XML parser to give an XML data model
(Document Object Model, XML Infoset)
• Can be parsed by an RDF parser to give an RDF data model
(an RDF graph)
The anatomy of an RDF/XML file
XML declaration
RDF
Other
Tripledocument
namespace
subject
predicate
object
namespace element
declaration
declarations
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”>
<rdf:Description rdf:about=“http://www.sciam.com/”>
<dc:title>
<dc:title>Scientific American</dc:title>
</dc:title>
</rdf:Description>
</rdf:RDF>
http://purl.org/dc/elements/1.1/title
The anatomy of an RDF/XML file
• Resource-valued predicates use the rdf:resource attribute
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator rdf:resource=“mailto:john@example.org”/>
</rdf:Description>
</rdf:RDF>
http://www.example.org/ mailto:john@example.org
http://purl.org/dc/elements/1.1/creator
The anatomy of an RDF/XML file
• We can have multiple rdf:Description elements within an
rdf:RDF element
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:title>Example Inc. Homepage</dc:title>
</rdf:Description>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator rdf:resource=“mailto:john@example.org”/>
</rdf:Description>
</rdf:RDF>
http://purl.org/dc/elements/1.1/creator
mailto:john@example.org
http://www.example.org/
http://purl.org/dc/elements/1.1/creator
mailto:john@example.org
http://www.example.org/
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:ex=“http://example.org/ontology#”>
<ex:Website rdf:about=“http://www.example.org/”/>
</rdf:RDF>
rdf:type
http://www.example.org/ ex:Website
RDF/XML striped syntax
• Consider the following graph:
http://www.example.org/
http://purl.org/dc/elements/1.1/creator
mailto:john@example.org
http://example.org/ontology#name
John Smith
RDF/XML striped syntax
• Graph could be serialised using two rdf:Description elements
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator rdf:resource=“mailto:john@example.org”/>
</rdf:Description>
<rdf:Description rdf:about=“mailto:john@example.org”>
<ex:name>John Smith</ex:name>
</rdf:Description>
</rdf:RDF>
RDF/XML striped syntax
• Alternatively, the second statement could be inserted within
the predicate element of the first
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator>
<rdf:Description rdf:about=“mailto:john@example.org”>
<ex:name>John Smith</ex:name>
</rdf:Description>
</dc:creator>
</rdf:Description>
</rdf:RDF>
RDF/XML striped syntax
• The syntax is striped because property and class elements
are nested alternately
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator>
<rdf:Description rdf:about=“mailto:john@example.org”>
<ex:name>John Smith</ex:name>
</rdf:Description>
</dc:creator>
</rdf:Description>
</rdf:RDF>
Class membership
• An object’s membership of a class is indicated using the
rdf:type property
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<rdf:type rdf:resource=“http://example.org/ontology#Website”/>
</rdf:Description>
</rdf:RDF>
rdf:type
http://www.example.org/ ex:Website
Common RDF/XML idioms
• XML entities are defined for the XML namespace URI prefixes
<?xml version=“1.0”?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf ‘http://www.w3.org/1999/02/22-rdf-syntax-ns#’>
<!ENTITY dc ‘http://purl.org/dc/elements/1.1/’>
<!ENTITY ex ‘http://example.org/ontology#’>
]>
<rdf:RDF xmlns:rdf=“&rdf;”
xmlns:dc=“&dc;”
xmlns:ex=“&ex;”>
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”>
<rdf:Description rdf:about=“”>
<dc:creator rdf:resource=“mailto:nmg@ecs.soton.ac.uk”/>
</rdf:Description>
</rdf:RDF>
Blank nodes (bNodes)
• Sometimes we have resources which we do not wish to
identify with a URI
• These are blank nodes or anonymous resources
http://www.example.org/
http://purl.org/dc/elements/1.1/creator
http://example.org/ontology#name
John Smith
Blank nodes (bNodes)
• The striped syntax simplifies the RDF/XML serialisation –
remove the rdf:about attribute
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator>
<rdf:Description>
<ex:name>John Smith</ex:name>
</rdf:Description>
</dc:creator>
</rdf:Description>
</rdf:RDF>
Blank nodes (bNodes)
• The striped syntax is not sufficient to represent all graphs
containing blank nodes unambiguously
dc:creator
http://www.example.org/
John Smith
ex:name
http://test.example.org/
dc:creator
Blank nodes (bNodes)
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator>
<rdf:Description>
<ex:name>John Smith</ex:name>
</rdf:Description>
</dc:creator>
</rdf:Description>
<rdf:Description rdf:about=“http://test.example.org/”>
<dc:creator>
<rdf:Description>
<ex:name>John Smith</ex:name>
</rdf:Description>
</dc:creator>
</rdf:Description>
</rdf:RDF>
Blank nodes and node IDs
• Ambiguities resulting from blank nodes are resolved by using
node IDs
• Node IDs are identifiers which are local to a given
serialisation of an RDF graph
– Node IDs may not be referred to from outside the scope of the
defining graph
• Node IDs are not guaranteed to remain unchanged when an
RDF file is parsed and serialised
– The identifier strings may change
– but
– The graph structure will remain unchanged
Blank nodes and node IDs
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:creator rdf:nodeID=“foo23”/>
</rdf:Description>
<rdf:Description rdf:about=“http://test.example.org/”>
<dc:creator rdf:nodeID=“foo23”/>
</rdf:Description>
<rdf:Description rdf:nodeID=“foo23”>
<ex:name>John Smith</ex:name>
</rdf:Description>
</rdf:RDF>
rdf:about versus rdf:ID
• So far, we have used the rdf:about attribute to specify the subjects of triples
<rdf:Description rdf:about=“http://www.example.org/”>
<dc:date
rdf:datatype=“http://www.w3.org/2001/XMLSchema#date”>2003-05-23</dc:date>
</rdf:Description>
Multilingual support
• In addition to typed literals, RDF also provides support for language
annotations on literals
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:dc=“http://purl.org/dc/elements/1.1/”>
<rdf:Description rdf:about=“http://www.example.org/foreword”>
<dc:title xml:lang=“en”>Foreword</dc:title>
<dc:title xml:lang=“fr”>Avant-propos</dc:title>
</rdf:Description>
</rdf:RDF>
rdf:Bag
mailto:john@example.org
rdf:type rdf:_1
rdf:_2
http://www.example.org/ mailto:bill@example.org
ex:members
rdf:_3
mailto:sally@example.org
Containers
• Three types of container are available in RDF
– rdf:Bag – an unordered group, possibly with duplicates
– rdf:Seq – an ordered group
– rdf:Alt – a group of alternatives (translations, media types, etc)
Containers
• Special syntax for expressing collections
– rdf:li is a convenience element which is replaced with ordinal
elements by RDF parsers
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<ex:members>
<rdf:Bag>
<rdf:li rdf:resource=“mailto:john@example.org”/>
<rdf:li rdf:resource=“mailto:bill@example.org”/>
<rdf:li rdf:resource=“mailto:sally@example.org”/>
</rdf:Bag>
</ex:members>
</rdf:Description>
</rdf:RDF>
Collections
• Collections are a different way of expressing ordered groups
in RDF
– Containers are mutable – a third party could add new members to a
container
– Collections are immutable – cannot be altered without rendering the
collection ill-formed
rdf:Lis
t
ex:members rdf:type
rdf:first
http://www.example.org/ mailto:john@example.org
rdf:rest
rdf:first
mailto:bill@example.org
rdf:rest
rdf:first
mailto:sally@example.org
rdf:rest
rdf:nil
Collections
• As before, special syntax for expressing collections
– rdf:parseType indicates special parse rules for an element
<?xml version=“1.0”?>
<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:ex=“http://example.org/ontology#”>
<rdf:Description rdf:about=“http://www.example.org/”>
<ex:members rdf:parseType=“Collection”>
<rdf:Description rdf:about=“mailto:john@example.org”/>
<rdf:Description rdf:about=“mailto:bill@example.org”/>
<rdf:Description rdf:about=“mailto:sally@example.org”/>
</ex:members>
</rdf:Description>
</rdf:RDF>
The RDF/N3 family
The anatomy of an NTriples file
<http://www.sciam.com/>
<http://purl.org/dc/elements/1.1/title> “Scientific American” .
http://purl.org/dc/elements/1.1/title
The anatomy of an Turtle/N3 file
<http://www.example.org>
<http://purl.org/dc/elements/1.1/creator> <mailto:john@example.org> ;
<http://purl.org/dc/elements/1.1/title> “Example Inc. Homepage” .
http://purl.org/dc/elements/1.1/creator
mailto:john@example.org
http://www.example.org/
• Or with nodeIDs: