RDF elementary guide part 2: Creating Ontologies and Knowledge Graphs with RDF-Schema

The Resource Description Framework (RDF) is an open standard by W3C to describe concepts and resources digitally with semantic meaning. Data described in RDF format can be exchanged and reused with retained conceptual understanding of concepts between businesses, industries and countries. This is the second article in a series that introduce the basics of describing digital resources with semantic meaning. The model in the article interlink resource descriptions from Wikidata (Wikipedia) to relate to equivalent concepts to create context. The previous article describe how classes and properties are defined with RDF-Schema (RDFS).

Prefix, relative and absolute paths

The turtle format uses prefix to abbreviate IRI addresses which make the syntax easier to read and are defined in the beginning of the file. Prefixes represents IRI paths to terminologies and classification systems (taxonomies) used in the model. The prefix in the model refers to external resources.

@base <https://www.clearbyte.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix wd: <http://www.wikidata.org/entity/> .

To create relative paths to resources declared in the model, the notation @base is used. The declaration below shows the relative path to the Guernica resource.

<Guernica> a <Painting> ;
    rdfs:label "Guernica" .

Resources declared within <> are assigned the address declared with @base. This makes it easy to change address if need be. The path to the resource above becomes https://www.clearbyte.org/Guernica. If @base and @prefix are left blank, the resources in the model will get the same address as the server where the RDF resources are published. It is possible to omit the prefix name which makes the syntax shorter but more difficult to read.

@prefix : <http://clearbyte.org/> .

:Guernica a :Painting ;
    rdfs:label "Guernica" .

Semantic model

The model below describes concepts concerning artists and paintings. All resources are described through statements which consist of subject, predicate and object (explained in the previous article). Subjects (Artist and Painting) are assigned attributes by declaring predicate and object in pairs. Artist has attributes for label (rdfs: label) and description (rdfs: comment) with @en notation to indicate that the language of the description is in English.

# Class definition

<Artist> a rdfs:Class ;
    rdfs:label "Artist" ;
    rdfs:comment "Creator of art artifacts"@en ;
    rdfs:seeAlso wd:Q483501 ;
    rdfs:seeAlso foaf:Person .

<Painting> a rdfs:Class ;
    rdfs:label "Painting";
    rdfs:comment "Art artifact on canvas"@en ;
    rdfs:seeAlso wd:Q3305213 ;
    rdfs:seeAlso schema:Painting .

Objects may consist of text strings, numeric values, or other resources with their own attributes declared in another statement. When the object uses a subject from another statement, resources are linked together and form the basis of a graph. For example, the object wd: Q483501 is a statement defined by Wikidata. The model uses the predicate rdfs: seeAlso to link and associate Artist in the model with Wikidata description of the concept. The association with the Wikidata definition of Artist (Q483501) and FOAF (friend-of-a-friend) description of Person shows how resources are interlinked with external once to create context and conceptual understanding.

To create instances of classes, a unique IRI is needed for the resource. It is not possible to declare other subjects as <VanGogh> in the same model because the path will not be unique.

<VanGogh> a <Artist> ;
    rdfs:label "VanGogh" ;
    foaf:firstName "Vincent" ;
    foaf:surname "van Gogh";
    rdfs:seeAlso wd:Q5582 ;
    <creatorOf> <starryNight>, <sunflowers>, <potatoEaters>, <sundayEindhoven>, <minersInTheSnow> .

<StarryNight> a <Painting> ;            
    rdfs:label "StarryNight" ;
    <paintingTechnique> <oil> .

If there are already classes and properties defined in standards or commonly used taxonomies, it is advantageous to use these, for example by using Person from FOAF. This will interlink models and simplifies queries on data that use common descriptions of resources. In some cases, it may be justified to create your own definitions of resources if the naming convention is differs from existing models. As in the case of Wikidata, which uses its own set of codes to identify resources, Q5582 for VanGogh and Q3305213 for Painting. Therefore, the predicate rdfs: seeAlso is used to link equivalent resources when the same naming convention is not used.

<Painting#Guernica> a <Painting> ;
    rdfs:label "Guernica";
    rdfs:seeAlso wd:Q175036 ;
    <createBy> <Picasso> ;
    <paintingTechnique> <oil> .

It is possible to use IRI / URI fragments in the path to subordinate resources in relation to each other. By using # fragments, one resource can be subordinated to another. The resource above gets the path https://www.clearbyte.org/Painting#Guernica, which indicates that Guernica is subordinate to the painting resource. Note that fragments are part of the IRI / URI protocol standard on which the RDF framework is based.

The model declares new properties <creatorOf> and <createdBy>. To declare properties, the RDFS predicate rdfs: Property is used. The definition of properties adds semantic significance to how subjects and objects are interlinked. The observant noted earlier that it is possible to list several objects to one predicate by declaring that VanGogh is the <creatorOf> several paintings.

<creatorOf> a rdfs:Property ;
    rdfs:domain <Artist> ;
    rdfs:range <Painting> .

<createdBy> a rdfs:Property ;
    rdfs:domain <Painting> ;
    rdfs:range <Artist> .

The image below shows the link between subject and object, where the properties-predicate are depicted as arrows. The direction of the arrows is determined by domain and range. The createdBy property belongs to the Painting (StarryNight) class and is applied to instances of the Artist (VanGogh) class. Depending on the visualization tool of RDF graphs, the user can choose classes and properties to display.

Knowledge graph and semantic model of artists, paintings and painting techniques

The graph in the image is a simple knowledge graph that uses properties to describe the semantic relationship between classes. The RDF framework offers more features and possibilities for more detailed definitions of knowledge graphs with semantic meaning, which will be explained in later articles.