To jest stara wersja strony!


Modeling and using knowledge in RDF

Last verification: 20171001
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:

  • download Apache Any23 Service (Standalone server embedded) 1.1 file from https://any23.apache.org/download.html (mirror: apache-any23-service-1.1-server-embedded.tar.gz) and unpack the zip somewhere
  • execute command to start server with any23 service:
    [PATH-to-unpacked-archive]/apache-any23-service-1.1-server-embedded/bin/any23server 
    • Note: use the any23server.bat file if you are using Windows OS
    • Change "$REPO" into %REPO% twice (line #79 in any23server.bat file) if Error: Unable to access jarfile $REPO/jetty-runner-8.1.4.v20120524.jar. message appears
  • after few seconds any23 service will appear on http://localhost:8080/apache-any23-service/ address :)

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.

  1. Create a new document with a *.ttl extension.
  2. Create a document describing the graph created during the previous lab. Use the RDF Turtle for reference.
    1. 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/> .
    2. Write down ~14 selected triples from your graph. Make sure you include each of the following at least once:
      1. resources,
      2. datatype values.
    3. Notes:
      • Comments in Turtle begins with # symbol.
      • In RDF we are describing something (a subject) and giving it a unique ID, e.g.: <http://kkutt/b-and-b/brooke-logan>. To make notation more compact, we can use prefixes and/or base namespace.
      • 8-) To separate statements we can use dot (.), semicolon (;) and comma (,). What is the difference between them?
    4. Go to the Anything to Triples webpage:
      • Validate your document using this tool (section „Convert copy&pasted document”):
        • 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)
    5. 8-) 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:

  • rdf:List.

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:

  1. 8-) Describe shortly what is the difference between different types of containers.
  2. Create a container in your database.
  3. 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 [10 minutes]

We are in the middle, so let's visualize our RDF files.

  1. There are two ways to do this:
    1. 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
    2. Use the RDF Editor developed at AGH UST (by Artur Smaroń, EIS 2015-2016)
  2. Analyze the results:
    1. 8-) How containers are represented in the graph?
    2. 8-) 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:

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

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

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

  2. 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 [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. 8-) 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

Introduction. Modeling knowledge with Resource Description Framework (RDF)

Last verification: 20190930
Tools required for this lab: Pens and paper

Before the lab

Reading:

Lab instructions

1 Images annotation [5 minutes]
  1. Enter URL for some image you like
  2. Select some regions on the picture and add descriptions for them
  3. Generate file using „Show JSON-LD” button
  4. Analyse the file. How regions' information is represented? Copy the source into the report 8-).
2 FOAF [10 minutes]
  1. Create your FOAF file with: foaf-o-matic
  2. Save your FOAF file. Put it in the report 8-).
  3. Publish your file so that it can be referenced with URL. Put the URL into the report 8-)
  4. Visualize your FOAF file with FOAF.Vix. Simply put the URL as an uri argument to the FOAF.Vix, e.g.: http://foaf-visualizer.gnu.org.ua/?nocache=1&uri=http://krzysztof.kutt.pl/foaf.rdf
  5. Add more friends using their FOAF files. Visualize again.
3 Linked Open Data [15 minutes]
  1. Analyze the clickable LOD diagram, choose 5 datasets and in a few words describe them in the report (what information do they contain?) 8-)
4 RDF model (and Mona Lisa) [15 minutes]
  • RDF model is a directed graph built from Statements a.k.a. triples
  • Each Statement consists of: subject, predicate and object
    • Subject can be an URI or an empty node
    • Predicate can be an URI
    • Object can be an URI, an empty node or a literal
  1. Let's consider a simple knowledge graph (taken from RDF 1.1 Primer):
  2. It is very informal and vague… So we can make it more concrete using URIs for every element in the graph. Note that we are using existing vocabularies: FOAF (foaf:) and Dublin Core (dcterms:).
  3. Every arrow represents now a simple RDF Statement (RDF triple) so we can write it down using Turtle notation:
    example.ttl
    BASE   <http://example.org/>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX schema: <http://schema.org/>
    PREFIX dcterms: <http://purl.org/dc/terms/>
    PREFIX wd: <http://www.wikidata.org/entity/>
     
    <bob#me>
        a foaf:Person ;
        foaf:knows <alice#me> ;
        schema:birthDate "1990-07-04"^^xsd:date ;
        foaf:topic_interest wd:Q12418 .
     
    wd:Q12418
        dcterms:title "Mona Lisa" ;
        dcterms:creator <http://dbpedia.org/resource/Leonardo_da_Vinci> .
     
    <http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>
        dcterms:subject wd:Q12418 .
  4. If you then visualize this code using simple RDF visualization you will get graph like that (you can click on graph to enlarge it):
    • 8-) Why is the node for „http://example.org/bob#meoval and the node for „Mona Lisa” rectangular? What's the difference between these two resources?
5 RDF model (and Friend-of-a-Friend) [5 minutes]

In this section we will convert FOAF files from previous lab to Turtle notation. Do you have your FOAF file? ;)

  1. Go to the Anything to Triples webpage and in section „Convert document at URI”:
  2. You will get an XML with a lot of empty tags and Turtle code inside <data><![CDATA[ … ]]></data>
  3. Analyze returned model. Especially look at last five statements:
    <http://hkrzysztof.kutt.pl/foaf.rdf#me> foaf:knows _:node1a07qklgvx22181 .
    
    _:node1a07qklgvx22181 a foaf:Person ;
    	foaf:name "Weronika T. Adrian" ;
    	foaf:mbox_sha1sum "fdaa9a764e8c1a218e814a043995d41a3f248ddd" ;
    	rdfs:seeAlso <http://home.agh.edu.pl/wta/foaf.rdf> .
    • 8-) What's the meaning of the _:node1a07qklgvx22181 object (numbers may differ in your results)?
  4. Convert your own FOAF file generated during previos lab into Turtle notation and compare both versions:
    • 8-) Which notation you find more clear and easier to understand? RDF/XML or Turtle?
    • 8-) Include your converted FOAF file in the report archive.
6 Modeling knowledge with RDF graphs [25 minutes]

RDF is a data model based on principle of representing relational information as labeled directed graphs.

  1. In this task you will represent a piece of knowledge with use of the RDF graphs. Firstly, select one of the topics (we will use this topic on subsequent labs):
    1. The Bold and the Beautiful – you can use a The_Bold_and_the_Beautiful#Premise section on wikipedia (or the polish one)
    2. The Game of Thrones – you can use a A_Song_of_Ice_and_Fire#Plot_synopsis section on wikipedia
  2. Read the selected fragment and extract as much information as you can.
  3. Draw a graph (yes, with a pen and paper) representing the relations you identified in the fragment. Of course, „there's more than one way to do it”.
    1. Draw regular resources (i.e. representing persons, places etc.) as oval nodes. Draw datatype values (e.g. dates, numbers representing age etc.) as rectangular nodes.
    2. You don't need to write long URIs, simply identify the resources with names and surnames etc.
  4. 8-) Put the sketch (a scan/picture) of the graph in your report.

We will use it on the next lab! :-)

Control questions

  • How one can add semantic annotation to a web page?
  • What are:
    • resources,
    • properties,
    • statemets.
  • What does RDF use to identify resources?
  • What are the required elements of RDF file?
  • What are namespaces, how are they defined and what are they used for?

Report

  1. Answer the questions marked 8-) in this lab.
  2. (Optionally) Add extra feedback section in the report to earn extra credit.

If you want to know more

2017/10/08 17:24
pl/dydaktyka/semweb/lab-rdfmodel2.1507476433.txt.gz · ostatnio zmienione: 2019/06/27 15:55 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0