RDF

From XennisWiki
Jump to: navigation, search

The Resource Description Framework (RDF) is a family of World Wide Web Consortium (W3C) specifications originally designed as a metadata data model. It has come to be used as a general method for conceptual description or modeling of information that is implemented in web resources, using a variety of syntax notations and data serialization formats. (Wikipedia)

Basics with Turtle as syntax

Simple example

The following code shows a short RDF example. It uses Turtle as RDF serialisation, that means to express the data.

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix fam: <http://example.org/family#> .
@prefix sim: <http://example.org/simpsons#> .

# Define simpsons
sim:Homer rdf:type foaf:Person ;
   foaf:name "Homer Simpson" ;
   foaf:age "36"^^xsd:integer ; .
   
sim:Marge rdf:type foaf:Person ;
   foaf:name "Marge Simpson" ;
   foaf:age "34"^^xsd:integer ; .

sim:Maggie rdf:type foaf:Person ;
   foaf:name "Maggie Simpson" ;
   foaf:age "1"^^xsd:integer ;
   fam:hasParent sim:Marge ;
   fam:hasParent sim:Homer ; .

sim:Abraham rdf:type foaf:Person ; .
   
# Define "Maggie has the grandfather Abraham"
sim:Maggie fam:hasParent _:parentsMaggie .
_:parentsMaggie fam:hasFather sim:Abraham .

Prefix and base

Define prefixes and a base

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://example.com/> .
@base <http://example.com/> .

# Example usage
:Person a rdfs:Class .

Blank nodes

Using blank nodes

# Option 1
sim:Maggie fam:hasParent _:parentMaggie .
_:parentMaggie fam:hasFather sim:Abraham .
# Option 2
sim:Maggie fam:hasParent [
   fam:hasFather sim:Abraham
] .

RDFS Define model

Example of defining a model using rdfs:Class, rdfs:subClassOf, rdfs:subPropertyOf, rdfs:domain and rdfs:range

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://example.com/> .
@base <http://example.com/> .

# Define model
:Person a rdfs:Class .
:Man a rdfs:Class ;
	rdfs:subClassOf :Person .
:Parent a rdfs:Class ;
	rdfs:subClassOf :Person .
:Father a rdfs:Class ;
	rdfs:subClassOf :Parent , :Man .
:hasParent a rdf:Property ;
	rdfs:domain :Person ;
	rdfs:range :Parent .
:hasFather a rdf:Property ;
	rdfs:range :Father ;
	rdfs:subPropertyOf :hasParent .

# Example usage
:Ann a :Person ;
	:hasFather :Carl .
:Carl a :Man .

Tools

Validator

Namespace lookup for RDF

See also

External links