courses:semint:lab_rdf

  • 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:

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!

  1. Create a new document with a *.ttl extension.
  2. 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/> .
  3. 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.
  4. 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 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)

2. RDF: Containers and Collections [15 minutes]

In the RDF there are two ways to describe a set or a sequence of objects:

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.
  1. Create a container in your RDF document.
  2. 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.

  1. Familiarize yourself with the primitive datatypes (a hierarchy in Section 3 may be useful).
  2. 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.

  1. Do you remember to use the validator regularly during the lab to verify the correctness of your RDF document?
  2. 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:
      1. 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:
      1. Convert your file to RDF/XML (rdfxml) format
      2. Simply copy the code of the generated RDF/XML document
      3. 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.
  3. Analyze the results:
    1. How are containers represented in the graph?
    2. How are collections represented in the graph?
    3. How are the datatypes presented?
    4. 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:

  1. Take a look at all above-mentioned dictionaries. How they are structured? What concepts and relations are available?
  2. 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.

  1. 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> .
  2. 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 [15 minutes]

RDF Schema also provides a way to define Properties as well as their domains and ranges.

  1. 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.

  2. 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 :-) .
  1. Use each of them in your RDF file.
  2. Check if your Turtle file passes validation!
  3. Save the file in a safe place – we will process it during the next lab!

Reading:

Common vocabularies:

Tools:

Others:

  • courses/semint/lab_rdf.txt
  • Last modified: 2 years ago
  • by kkt