Slides of the tutorial given in Trento, Italy, on the 14th of December, 2005, as part of the 2nd Italian Semantic Web Workshop on Semantic Web Applications and Perspectives (SWAP2005), held at the University of Trento on the 14-15-16 December, 2005.
These slides are in XHTML. A printable version in PDF is also available.
Introduction
<foo:creator>
same as
<bar:author>
?Basic RDF
<rdf:Description rdf:about="http://.../membership.svg#FullSlide> <axsvg:graphicsType>Chart</axsvg:graphicsType> <axsvg:labelledBy rdf:resource="http://...#BottomLegend/> <axsvg:chartType>Line</axsvg:chartType> </rdf:Description>
«Element for #FullSlide»
«Element for labelledBy»
«Element for #BottomLegend»
«/Element for labelledBy»
«/Element for #FullSlide»
«Element for #FullSlide»
«Element for graphicsType»
Chart
«/Element for graphicsType»
«/Element for #FullSlide»
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="#FullSlide">
«Element for labelledBy»
<rdf:Description rdf:about="#BottomLegend"/>
«/Element for labelledBy»
</rdf:Description>
<rdf:RDF>
<rdf:RDF
xmlns:axsvg="http://svg.example.org#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy>
<rdf:Description rdf:about="#BottomLegend"/>
</axsvg:labelledBy>
</rdf:Description>
<rdf:RDF>
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy>
<rdf:Description rdf:about="#BottomLegend"/>
</axsvg:labelledBy>
</rdf:Description>
<rdf:Description rdf:about="#FullSlide">
<axsvg:graphicsType>
Chart
</axsvg:graphicsType>
</rdf:Description>
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy>
<rdf:Description rdf:about="#BottomLegend"/>
</axsvg:labelledBy>
<axsvg:graphicsType>
Chart
</axsvg:graphicsType>
</rdf:Description>
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy>
<rdf:Description rdf:about="#BottomLegend"/>
</axsvg:labelledBy>
</rdf:Description>
<rdf:Description rdf:about="#BottomLegend">
<axsvg:isAnchor>True</axsvg:isAnchor>
</rdf:Description>
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy>
<rdf:Description rdf:about="#BottomLegend">
<axsvg:isAnchor>True</axsvg:isAnchor>
</rdf:Description>
</axsvg:labelledBy>
</rdf:Description>
<property>
<rdf:Description rdf:about="URI"/>
</property>
<property rdf:resource="URI"/>
<rdf:Description rdf:about="#FullSlide">
<axsvg:labelledBy rdf:resource="#BottomLegend"/>
</rdf:Description>
In Python syntax:
# import the libraries
from rdflib.Graph import Graph
from rdflib.URIRef import URIRef
# resource for a specific URI:
subject = URIRef("URI_of_Subject")
# create the graph
# (or "triple store, model, ...)
graph = Graph()
# parse an RDF file and store it in the graph
graph.parse("membership.rdf")
# do something with (p,o) pairs
for (p,o) in graph.predicate_objects(subject) :
do_something(p,o)
The tool:
graph.add((s,p,o))
rdf:ID
<rdf:Description rdf:about="#FullSlide">
<axsvg:isA>
<rdf:Description rdf:about="#Thing"/>
</axsvg:isA>
</rdf:Description>
<rdf:Description rdf:ID="Thing">
<axsvg:consistsOf rdf:resource="#Axes"/>
<axsvg:consistsOf rdf:resource="#Legend"/>
<axsvg:consistsOf rdf:resource="#Datalines"/>
</rdf:Description>
id
in HTML, SVG, …<rdf:Description rdf:about="#FullSlide">
<axsvg:isA>
<rdf:Description rdf:nodeID="A234"/>
</axsvg:isA>
</rdf:Description>
<rdf:Description rdf:nodeID="A234">
<axsvg:consistsOf rdf:resource="#Axes"/>
…
</rdf:Description>
rdf:ID
, but…A234
is invisible from outside the file
nodeID
internally<rdf:Description rdf:about="#FullSlide">
<axsvg:isA>
<rdf:Description>
<axsvg:consistsOf rdf:resource="#Axes"/>
…
</rdf:Description>
</axsvg:isA>
</rdf:Description>
Description
may be omitted):<rdf:Description rdf:about="#FullSlide">
<axsvg:isA rdf:parseType="resource">
<axsvg:consistsOf rdf:resource="#Axes"/>
…
</axsvg:isA>
</rdf:Description>
RDF Vocabulary Description Language
(a.k.a. RDFS)
Chart
, labelledBy
, isAnchor
,
...chartType
, graphicsType
, ...rdfs:Resource
, rdfs:Class
as
nodes; rdf:type
, rdfs:subClassOf
as
propertiesaxsvg-schema.rdf
(“application’s data
types”):<rdf:Description rdf:ID="SVGEntity">
<rdf:type rdf:resource=
"http://www.w3.org/2000/01/rdf-schema#Class"/>
</rdf:Description>
<rdf:Description rdf:about="#Datalines">
<rdf:type rdf:resource="axsvg-schema.rdf#SVGEntity"/>
</rdf:Description>
<rdf:Description rdf:about="http://...">
<rdf:type rdf:resource="http://..../something#ClassName>
...
</rdf:Description>
<yourNameSpace:ClassName rdf:about="http://...">
...
</yourNameSpace:ClassName>
axsvg-schema.rdf
(remember the simplification
rule):<rdfs:Class rdf:ID="SVGEntity">
...
</rdfs:Class>
<rdf:RDF xmlns:axsvg="axsvg-schema.rdf#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<axsvg:SVGEntity rdf:about="#Datalines">
...
</axsvg:SVGEntity>
rdf:type
is just a property…(#AnimatedLines rdf:type
#SVGEntity)
If:
uuu rdfs:subClassOf xxx .
vvv rdf:type uuu .
Then add:
vvv rdf:type xxx .
rdf:Property
)
(P rdfs:range C)
means:
P
is a propertyC
is a class instanceP
, the “object” must be an
individual in C
P
, object
C
, and property rdfs:range
Same example in XML/RDF:
<rdfs:Property rdf:ID="chartType">
<rdf:domain rdf:resource="#SVGEntity"/>
<rdf:range rdf:resource="http://...#Literal"/>
</rdfs:Property>
xml:lang
)<rdf:Description rdf:about="#Datalines">
<axsvg:isAnchor
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">
false
</axsvg:isAnchor>
</rdf:Description/>
<rdf:Description rdf:about="#Path">
<axsvg:algorithmUsed rdf:parseType="Literal"
<math xmlns="...">
<apply>
<laplacian/>
<ci>f</ci>
</apply>
</math>
</axsvg:algorithmUsed>
</rdf:Description/>
Some Predefined Classes (Collections, Containers)
<rdf:Description rdf:about="#FullSlide">
<axsvg:consistsOf rdf:parseType="Collection">
<rdf:Description rdf:about="#Axes"/>
<rdf:Description rdf:about="#Legend"/>
<rdf:Description rdf:about="#Datalines"/>
</axsvg:consistsOf>
</rdf:Description>
<rdf:Description rdf:about="#FullSlide">
<axsvg:consistsOf rdf:parseType="Collection">
<rdf:Description rdf:about="#Axes"/>
<rdf:Description rdf:about="#Legend"/>
<rdf:Description rdf:about="#Datalines"/>
</axsvg:consistsOf>
</rdf:Description>
Seq
rdf:_1
, rdf:_2
, …<rdf:Description rdf:about="#FullSlide">
<axsvg:consistsOf>
<rdf:Description>
<rdf:type rdf:resource="http:...rdf-syntax-ns#Seq>
<rdf:_1 rdf:resource="#Axes>
...
</rdf:Description>
</axsvg:consistsOf >
</rdf:Description/>
<rdf:Description rdf:about="#FullSlide">
<axsvg:consistsOf>
<rdf:Seq>
<rdf:li rdf:resource="#Axes>
...
</rdf:Seq>
</axsvg:consistsOf >
</rdf:Description/>
rdf:Bag
rdf:Alt
rdf:parseType
instead of
rdf:first
, rdf:rest
, …rdf:Seq
does not appear directly; instead, a (possibly
blank) node with a rdf:type
propertyRDF(S) in Practice
application/rdf+xml
.rdf
rdf:about
as a URI for external resources
<svg ...>
...
<metadata>
<rdf:RDF xmlns:rdf="http://../rdf-syntax-ns#">
...
</rdf:RDF>
</metadata>
...
</svg>
link/meta
in the header (using conventions instead of
namespaces in metas<html xmlns="http://www.w3.org/1999/"> <head profile="http://www.w3.org/2003/g/data-view"> <title>Some Document</title> <link rel="transformation" href= href="http://…/dc-extract.xsl" /> <meta name="DC.Subject" content="Some subject"/> ... </head> ... </html>
dc-extract.xsl
<rdf:Description rdf:about=""> <dc:subject>Some subject</dc:subject> </rdf:Description>
dc-extract.xsl
, with a definition
of the corresponding meta-s, class id-s, etclink
and meta
elements (e.g.,
meta elements may have children, thereby adding more complex
data)<span property="dc:date">March 23, 2004</span> <span property="dc:title">Rollers hit casino for £1.3m</span> By <span property="dc:creator">Steve Bird</span> …
<rdf:Description rdf:about=""> <dc:date>March 23, 2004</dc:date> <dc:title>Rollers hit casino for £1.3m</dc:title> <dc:creator>Steve Bird</dc:creator> </rdf:Description>
@prefix axsvg: <http://svg.example.org#>. @prefix : <http://this.file.uri>. @prefix xsd: <http://www.w3.org/2001/XMLSchema#> :FullSlide axsvg:labelledBy :bottomLegend; axsvg:isA [ axsvg:consistsOf :Axes, :Legend, :Datalines. ]. :bottomLegend axsvg:isAnchor "True"^^xsd:boolean.
RDF Data Access, a.k.a. Query (SPARQL)
# do something with (p,o) pairs
for (p,o) in graph.predicate_objects(subject) :
do_something(p,o)
(a,b)
pair of
resources, for which there is an x
such that (x
parent a)
and (b brother x)
holds” (ie, return
the uncles)# do something with (p,o) pairs
for (p,o) in graph.predicate_objects(subject) :
do_something(p,o)
(subject,p,o)
is a pattern for what we are
looking for
p
and o
as “unknowns”SELECT ?p ?o
WHERE {subject ?p ?o}
WHERE
define the graph pattern, with
?p
and ?o
“unbound” symbolsp,o
pairsSELECT ?cat ?val #note: not ?x!
WHERE { ?x rdf:value ?val. ?x category ?cat }
[["Total Members",100],["Total
Members",200],…,["Full Members",10],…]
SELECT ?cat ?val
WHERE { ?x rdf:value ?val. ?x category ?cat. FILTER(?val>=200). }
[["Total Members",200],…,]
SELECT ?cat ?val ?uri
WHERE { ?x rdf:value ?val. ?x category ?cat.
?al contains ?x. ?al linkTo ?uri }
[["Total
Members",100,Resource(http://...)],…,]
SELECT ?cat ?val ?uri
WHERE { ?x rdf:value ?val. ?x category ?cat.
OPTIONAL ?al contains ?x. ?al linkTo ?uri }
["Total Members", 100,
http://...],…,
["Full Members",20, ],…,
GET /qps?query-lang=http…&graph-id=http://my.example/3.rdf
&query=SELECT+:…+WHERE:+…:HTTP/1.1
User-Agent: my-sparql-client/0.0
Host: my.example
200 OK HTTP/1.1
Server: my-sparql-server/0.0
Content-Type: application/xml
<?xml version="1.0" encoding="UTF-8"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#>
<head>
<variable name="a/>
...
</head>
<results>
<result ordered="false" distinct="false">
<binding name="a"><uri>http:…</uri></binding>
...
</result>
<result> ... </result>
</results>
</sparql>
Programming Practice
# import the libraries
from rdflib.Graph import Graph
from rdflib.URIRef import URIRef
# resource for a specific URI:
subject = URIRef("URI_of_Subject")
# create the graph
graph = Graph()
# parse an RDF file and store it in the triple store
graph.parse("membership.rdf")
# do something with (p,o) pairs
for (p,o) in graph.predicate_objects(subject) :
do_something(p,o)
# add a triple to the triple store
graph.add((subject,pred,object))
# remove it
graph.remove_triples((subject,pred,object))
# save it in a file in RDF/XML
graph.serialize("filename.rdf")
from rdflib.sparql import SPARQLGraph, GraphPattern
p = GraphPattern([("?x",RDF.type,"?val"),("?x",category,"?cat")])
select = ("?cat","?val")
sparqlGraph = SPARQLGraph(graph)
results = sparqlGraph.query(select,p)
// create a model (a.k.a. Graph in python)
Model model=new ModelMem();
Resource subject=model.createResource("URI_of_Subject")
// 'in' refers to the input file
model.read(new InputStreamReader(in));
StmtIterator iter=model.listStatements(subject,null,null);
while(iter.hasNext()) {
st = iter.next();
p = st.getProperty();
o = st.getObject();
do_something(p,o);
}
Seq
,
Alt
, etc. to Java constructsOntologies (OWL)
“defines the concepts and relationships used to describe and represent an area of knowledge”
Class
and
Thing
to differentiate the classes from
individualsChartType
enumeration…<rdf:Property rdf:ID="chartType">
<rdf:range>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<owl:Thing rdf:ID="Bar"/>
<owl:Thing rdf:ID="Pie"/>
<owl:Thing rdf:ID="Radar"/>
…
</owl:oneOf>
</owl:Class>
</rdf:range>
</rdf:Property>
<owl:Class rdf:ID="AnimationEntity">
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#animate"/>
<owl:Class rdf:about="#animateMotion"/>
<owl:Class rdf:about="#animateColor"/>
…
</owl:unionOf>
</owl:Class>
complementOf
,
intersectionOf
owl:Restriction
defines a blank node with restrictions
<owl:Class rdf:ID="Delphin">
<rdfs:subClassOf rdf:resorce="#Mammal"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#livingIn"/>
<owl:allValuesFrom rdf:resource="#UnionOfSeaAnAmazonas">
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
allValuesFrom
could be replaced by:
someValuesFrom
cardinality
, minCardinality
,
maxCardinality
<owl:Class rdf:ID="SVGFigure">
. . .
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#shape"/>
<owl:cardinality rdf:datatype=".../nonNegativeInteger">
1
</owl:cardinality>
</owl:Restriction>
</rdfs:subClassOf>
. . .
</owl:Class>
<owl:ObjectProperty rdf:ID="ChartType">
<rdf:type rdf:resource="...../#FunctionalProperty"/>
</owl:ObjectProperty>
InverseFunctionalProperty
TransitiveProperty
, SymmetricProperty
DatatypeProperty
can be restricted (using XML
Schema)owl:equivalentClass
: two classes have the same
individualsowl:disjointWith
: no individuals in commonowl:equivalentProperty
: equivalent in terms of
classesowl:inverseOf
: inverse relationshipowl:sameAs
: two URI refer to the same individual
(e.g., concept)owl:differentFrom
: negation of
owl:sameAs
<owl:Class rdf:ID="SVGFigure_Chart">
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty rdf:about="#chartType"/>
<owl:cardinality
rdf:dataype="...#nonNegativeInteger">
1
</owl:cardinality>
</owl:Restriction>
</owl:equivalentClass>
</owl:Class>
owl:Ontology
with special properties:
owl:imports
, owl:versionInfo
,
owl:priorVersion
owl:backwardCompatibleWith
,
owl:incompatibleWith
rdfs:label
, rdfs:comment
can also be
usedowl:DeprecatedClass
,
owl:DeprecatedProperty
typesowl:Class
is equivalent to rdfs:Class
owl:Thing
is equivalent to
rdfs:Resource
Class
can also be an individual (it is possible to
talk about class of classes, etc.)rdf:type
to be functional…)<owl:Class rdf:ID="A"> <owl:equivalentClass> <owl:Restriction> <owl:onProperty rdf:resource=".../22-rdf-syntax-ns#type"/> <owl:allValueFrom rdf:about="#B"/> </owl:Restriction> </owl:equivalentClass> </owl:Class> <owl:class rdf:ID="B"> <owl:complementOf rdf:parseType="Collection"> <owl:Class rdf:about="#A"/> </owl:complementOf> </owl:class>
<owl:Thing rdf:ID="C"> <rdf:type rdf:resource="#A"/> </owl:Thing>
C
is of type A
then it must be of
the complement type, i.e., not of A
…Goal: maximal subset of OWL Full against which current research can assure that a decidable reasoning procedure is realizable
Class
, Thing
, ObjectProperty
,
DatatypePropery
are strictly separated : a class
cannot be an individual of another class
owl:Thing
(except, e.g., for rdf:type
)owl:Class
and rdfs:Class
in
definitions (essentially: use OWL concepts only!)rdf:type
)owl:Thing
-s)Class(animate)
Class(animateMotion)
Class(animationEntity) { complete
unionOf(animate animateMotion …)
)
Simple Knowledge Organisation System (SKOS)
(from the RDF Semantics Glossary)
Illustrates “broader” and “narrower”
(From MortenF’s weblog categories. Note that the categorization is arbitrary!)
(from UK Archival Thesaurus)
Concept
,
ConceptScheme
,
…
)prefLabel
, altLabel
,
prefSymbol
, altSymbol
…)definition
, scopeNote
,
changeNote
,
…
)broader
, narrower
,
related
)subject
, isSubjectOf
,
…
)Collection
, OrderedCollection
,
…
)subjectIndicator
)What is Coming?
Available Documents, Tools
SDO_RDF_MATCH
table function (usable from SQL) to query
triplets
Some Application Examples