RDF Generator

This code generator produces the vocabulary specification (in RDF turtle format) that represent the entities and relationships of a Structural model.

Let’s generate the code for the vocabulary of our Structural model example structural model example. You should create a RDFGenerator object, provide the Structural model, and use the generate method as follows:

from besser.generators.rdf import RDFGenerator

generator: RDFGenerator = RDFGenerator(model=library_model)
generator.generate()

The vocabulary.ttl file with the vocabulary specification in turtle format will be generated in the <<current_directory>>/output folder and it will look as follows.

 1@prefix ex: <http://example.org/vocab#> .
 2@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 3@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 4@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
 5
 6# Class definition
 7ex:Author rdf:type rdfs:Class ;
 8          rdfs:label "Author" .
 9ex:Book rdf:type rdfs:Class ;
10          rdfs:label "Book" .
11ex:Library rdf:type rdfs:Class ;
12          rdfs:label "Library" .
13
14# Property definition
15ex:email rdf:type rdf:Property ;
16        rdfs:domain ex:Author ;
17        rdfs:range xsd:string ;
18        rdfs:label "email" .
19ex:name rdf:type rdf:Property ;
20        rdfs:domain ex:Author ;
21        rdfs:range xsd:string ;
22        rdfs:label "name" .
23ex:title rdf:type rdf:Property ;
24        rdfs:domain ex:Book ;
25        rdfs:range xsd:string ;
26        rdfs:label "title" .
27ex:release rdf:type rdf:Property ;
28        rdfs:domain ex:Book ;
29        rdfs:range xsd:date ;
30        rdfs:label "release" .
31ex:pages rdf:type rdf:Property ;
32        rdfs:domain ex:Book ;
33        rdfs:range xsd:integer ;
34        rdfs:label "pages" .
35ex:address rdf:type rdf:Property ;
36        rdfs:domain ex:Library ;
37        rdfs:range xsd:string ;
38        rdfs:label "address" .
39ex:name rdf:type rdf:Property ;
40        rdfs:domain ex:Library ;
41        rdfs:range xsd:string ;
42        rdfs:label "name" .
43
44# Relationship Definition
45ex:writtenBy rdf:type rdf:Property ;
46    rdfs:domain ex:Book ;
47    rdfs:range ex:Author ;
48    rdfs:label "writtenBy" .
49ex:locatedIn rdf:type rdf:Property ;
50    rdfs:domain ex:Book ;
51    rdfs:range ex:Library ;
52    rdfs:label "locatedIn" .
53
54# Enumeration definition