Modeling and using knowledge in RDF
Last verification: | 20180912 |
Tools required for this lab: | – |
Before the lab
Lab instructions
During this lab we will use Anything to Triples website. If it is down, there is also a possibility to download any23 service and run it on your own computer:
-
execute command to start server with any23 service:
[PATH-to-unpacked-archive]/apache-any23-service-1.1-server-embedded/bin/any23server
-
During this lab, you will serialize (using Turtle syntax) an RDF graph created before (The Bold and the Beautiful vs The Game of Thrones).
1 Modeling knowledge with RDF triples [20 minutes]
RDF is a data model for which several syntaxes have been developed.
RDF document is an RDF graph (describing some objects) serialized into chosen representation/syntax.
In this task, you will convert the graph representation into so called Turtle syntax.
Create a new document with a *.ttl
extension.
-
Define namespaces for your document URIs, e.g., a standard RDF namespace and one „your own” for this specific topic:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix bb: <http://yourname/b-and-b#>.
You can also use a base namespace:
@base <http://kkutt/b-and-b/> .
Write down ~14 selected triples from your graph. Make sure you include each of the following at least once:
resources,
datatype values.
Notes:
-
Validate your document using this tool (section „Convert copy&pasted document”):
if something is wrong, you can see details in report (in web browser), e.g.:
if code was successfully validated then you get an XML with a lot of empty tags and your Turtle code inside <data><![CDATA[ … ]]></data>
(indentation may be changed)
Include model (
.ttl
file) in the report archive.
2 RDF: Containers and Collections [10 minutes]
In RDF there are two ways to describe set or sequences of objects: Containters and Collections.
The container and collection are resources that contain things. The contained things are members.
RDF defines three types of containers:
rdf:Bag
,
rdf:Seq
,
rdf:Alt
,
and one type of collection:
While „a container only says that certain identified resources are members; it does not say that other members do not exist.” with a Collection we can describe groups containing only the specified members.
Read about them and then:
Describe shortly what is the difference between different types of containers.
Create a container in your database.
In your RDF file create also an
RDF Collection. For hint and examples see the
recommendation.
3 RDF: Datatypes [10 minutes]
Add the references to XML Schema datatypes to chosen information in your RDF file, e.g.:
# ...
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
# ...
# ...
<brooke-logan> <daughter-of> <beth-logian>;
<born> "1900-01-01"^^xsd:date;
<studied> "Chemistry"^^xsd:string;
# ...
Use at least 3 different datatypes!
4 RDF Visualization [3 minutes]
We are in the middle, so let's visualize our RDF files.
There are two ways to do this:
Using
Anything to Triples service convert your file to RDF/XML (
rdfxml
) format. Do not analyze resulting code. Simply copy it :)
Go to the
RDF Validator page and simply paste generated code into
Check by Direct Input
field. Select
Graph only
from dropdown list and click
Parse RDF
Use the
RDF Editor developed at AGH UST (by Artur Smaroń, EIS 2015-2016)
Analyze the results:
How containers are represented in the graph?
How collections are represented in the graph?
5 Semantic vocabularies: FOAF, Dublin Core and FHKB [10 minutes]
Semantic vocabularies are sets of predefined properties for describing some domains. Examples include:
-
Modify your RDF file to use the properties from FHKB, Dublin Core and FOAF vocabulary, e.g.:
# ...
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix fhkb: <http://www.example.com/genealogy.owl#> .
# ...
# ...
<brooke-logan> fhkb:isDaughterOf <beth-logian>;
<born> "1900-01-01"^^xsd:date;
<studied> "Chemistry"^^xsd:string;
foaf:name "Brooke Logan", "Brooke Forrester", "Brooke Chambers", "Brooke Jones", "Brooke Marone", "Brooke Spencer".
# ...
Hint: comprehensive list of
dcterms:
and
dc:
elements is
here („Section 2: Properties in the /terms/ namespace” =
dcterms:
, „Properties in the /elements/1.1/ namespace” =
dc:
)
6 RDF Schema: classes [10 minutes]
RDF Schema allows to organize objects into classes and define simple taxonomies.
Define classes of items in your database. Consider reusing the classes from dictionaries mentioned before, e.g.
@base <http://kkutt/got/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<Character> rdf:type rdfs:Class .
<Dwarf> rdf:type rdfs:Class ;
rdfs:subClassOf <Character> .
foaf:Person rdfs:subClassOf <Character> .
Add the rdf:type
statements to your RDF file, e.g.:
<brooke-logan> a foaf:Person .
<tyrion-lannister> rdf:type <Dwarf> .
Note that a
is an alias for rdf:type
so two statements:
<tyrion-lannister> rdf:type <Dwarf> .
<tyrion-lannister> a <Dwarf> .
are equivalent.
7 RDF Schema: properties [10 minutes]
RDF Schema also provides a way to define Properties as well as their domains and ranges.
In your file identify properties that are not defined in external dictionaries (e.g. Dublin Core), e.g. in this code:
<brooke-logan> fhkb:isDaughterOf <beth-logian>;
<born> "1900-01-01"^^xsd:date;
<studied> "Chemistry"^^xsd:string;
foaf:name "Brooke Logan", "Brooke Forrester", "Brooke Chambers", "Brooke Jones", "Brooke Marone", "Brooke Spencer".
<studied>
is not defined in external dictionary – it is defined in our own namespace.
Describe each such property using RDF Schema capabilities:
@base <http://kkutt/b-and-b/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<studied> rdf:type rdfs:Property ;
rdfs:domain foaf:person ;
rdfs:range rdfs:Literal.
You may find RDF Schema 1.1 recommendation useful.
8 RDF Schema: Non-modeling properties [3 minutes]
RDF Schema also provides some handful properties that are not used in inference process. These are:
rdfs:label
– used by convention to provide a human-readable name that is displayed by semantic web agents,
rdfs:seeAlso
– cross-referencing; provide links to supplementary information,
rdfs:isDefinedBy
– subPropertyOf rdfs:seeAlso; provides a link to the primary source of information,
rdfs:comment
– for everything you want :) .
Use each of them in your RDF file.
Include final RDF
Turtle file in the report archive.
Control questions
What container elements are available in RDF?
What is RDF Schema?
What are core RDF Schema Classes and properties?
How constraints on domain and range of properties are added?
If you want to know more
Reading:
Common vocabularies:
RDF serialization in XML:
Tools:
RDF Editor developed at AGH UST (by Artur Smaroń, EIS 2015-2016)
-
RDF Visualizers summary:
rdfviz (in Polish)
Articles:
Others: