Modeling with RDF and RDFS
- Last verification: 20220909
- Tools required for this lab:
- Any RDF validator/converter that supports Turtle notation. I suggest one of the following three:
- RDFShape – a lightweight online service for RDF validation, visualization and conversion
- Apache Any23 (Anything to Triples) – online service with better error messages during file validation (but unfortunately it is often down)
- Apache Any23 (offline) – if both online services are down, this solution is a backup (see details below, in the info box)
To launch Apache Any23 service on your own computer:
- Download Apache Any23 Service (Standalone server embedded) 1.1 and unpack the zip somewhere
- You can also download the latest version directly from https://any23.apache.org/download.html
- Start any23 service with the command:
./[PATH-to-unpacked-archive]/apache-any23-service-1.1-server-embedded/bin/any23server
- Note: use the
any23server.bat
file if you are using Windows - Change
"$REPO"
into%REPO%
twice (line #79 inany23server.bat
file) ifError: Unable to access jarfile $REPO/jetty-runner-8.1.4.v20120524.jar.
message appears
- After a few seconds, any23 service will be available at http://localhost:8080/apache-any23-service/
Prepare yourself for the lab
- RDF Primer: general ideas about RDF; we will use only Turtle syntax so you can simply omit sections 5.2-5.4
Lab instructions
1. Modeling knowledge with RDF triples [30 minutes]
RDF is a data model for which several syntaxes have been developed (see Section 5 in RDF Primer).
RDF document is an RDF graph (describing some objects) serialized into chosen representation/syntax.
During the previous lab, you created an RDF model/graph on a topic of your choice (The Bold and the Beautiful / The Game of Thrones / other).
During this lab, we will serialize it with the Turtle syntax (an RDF document will be created) and then extend it with some RDF Schema (RDFS) extras.
Let's start!
- Create a new document with a
*.ttl
extension. - Create a document preamble:
- Define prefixes for namespaces used. You can start with a standard RDF namespace and one “your own” dedicated for this graph:
@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://yourname/b-and-b/> .
- Write down ~15 selected triples from your graph. Make sure you include both resources (with URIs) and literals.
- Use the RDF Turtle for reference.
- Comments in Turtle begins with
#
symbol.
- Validate your document using the selected validation service:
- [preffered] If you use RDFShape:
- go to the Data analysis (RDF → Analysis & Visualization):
- Paste your document in Text tab
- Format: Turtle
- Inference: NONE
- Click “Analyze”:
- If everything is OK, you will see Well formed RDF message and summary of the document; you can also see the visualization under Visualizations tab
- Most errors are flagged when you type in the editor. You can also see the report after clicking “Analyze”: you should expand the Error response from data/info box to see the details
- If you use Apache any23 service (online/offline):
- Go to the “Convert copy&pasted document” section:
- input format: Turtle (text/turtle)
- output format: turtle
- validation: validate
- report: checked
- annotate: unchecked
- Paste your code and click “Convert” button:
- 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)
2. RDF: Containers and Collections [15 minutes]
In the RDF there are two ways to describe a set or a sequence of objects:
- Collections (
rdf:List
).
Important difference (see RDF 1.1 Semantics):
There is no way in RDF to assert that a container contains only a fixed number of members. This is a reflection of the fact that it is always consistent to add a triple to a graph asserting a membership property of any container. And finally, there is no built-in assumption that an RDF container has only finitely many members. […]
Collections differ from containers […] in having an explicit terminator, allowing applications to determine the exact set of items in the collection.
- Create a container in your RDF document.
- Create also a collection.
- For hint and examples, see the recommendation (there is a compact notation for lists in Turtle!).
3. RDF: Datatypes [15 minutes]
RDF allows the types of literals to be defined explicitely, making them easier to process later. The basic types are defined in the W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes recommendation.
- Familiarize yourself with the primitive datatypes (a hierarchy in Section 3 may be useful).
- Add the XSD datatypes to chosen information in your RDF document
- Use at least 4 different datatypes!
- E.g.:
# ... @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . # ... # ... <brooke-logan> <daughter-of> <beth-logan>; <born> "1900-01-01"^^xsd:date; <studied> "Chemistry"^^xsd:string; # ...
4. RDF Visualization [10 minutes]
We are in the middle, so let's visualize our RDF files.
- Do you remember to use the validator regularly during the lab to verify the correctness of your RDF document?
- Generate the visualization of your RDF document (NOTE: The file must not contain errors to be able to generate a visualization!):
- If you use RDFShape:
- Simply go to the Data analysis, click Analyze and then go to the Visualizations/DOT tab. You can download the image using dedicated button.
- If you use Apache any23, you should follow the following procedure:
- Convert your file to RDF/XML (
rdfxml
) format - Simply copy the code of the generated RDF/XML document
- Go to the RDF Validator page and simply paste generated code into
Check by Direct Input
field. SelectGraph only
from dropdown list and clickParse RDF
.
- Analyze the results:
- How are containers represented in the graph?
- How are collections represented in the graph?
- How are the datatypes presented?
- Does the visualization as a whole mirror your earlier hand-drawn graph?
5. Semantic vocabularies: FOAF, Dublin Core and FHKB [30 minutes]
Semantic vocabularies are sets of predefined properties for describing some domains. Examples include:
- FOAF for describing people, their activities and relations (seen in previous lab)
- Dublin Core for describing digital/physical “media” resources (books, movies, webpages, …)
- DCMI Metadata Terms – definitions of all terms. Prefixes:
@prefix dc: <http://purl.org/dc/elements/1.1/> . # Sect 3 in the document @prefix dcterms: <http://purl.org/dc/terms/> . # Sect 2 in the document
- SIOC for describing online communities and social data (posts, forums, users)
- SIOC: Content Exchange and Semantic Interoperability Between Social Networks – introductory paper
- FKHB for describing family relations (in genealogy)
- FKHB.ttl – file with all the definitions
- Semantic Web Technologies on an Example of Family Trees – a blog entry about the FKHB in use
- Take a look at all above-mentioned dictionaries. How they are structured? What concepts and relations are available?
- Modify your RDF document using the properties from these dictionaries, 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". # ...
6. RDF Schema: classes [15 minutes]
RDF Schema allows to organize objects into classes and define simple taxonomies.
- Define classes of items in your database.
- You may find RDF Schema 1.1 recommendation useful.
- Consider reusing the classes from dictionaries mentioned before.
- Example:
@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 forrdf:type
so two statements:<tyrion-lannister> rdf:type <Dwarf> .
<tyrion-lannister> a <Dwarf> .
are equivalent.
7. RDF Schema: properties [15 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), as 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.
- You may find RDF Schema 1.1 recommendation useful.
- Example:
@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.
8. RDF Schema: Non-modeling properties [10 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.
- Check if your Turtle file passes validation!
- Save the file in a safe place – we will process it during the next lab!
Learn more!
Reading:
- RDFS enables simple reasoning: Patterns of RDFS entailment
Common vocabularies:
Tools:
- RDFShape – RDF conversion, RDF/SPARQL/ShEx/SHACL playground
- RDF Editor developed at AGH UST (by Artur Smaroń, EIS 2015-2016)
Others: