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 forma 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:Library rdf:type rdfs:Class .
 8
 9ex:Author rdf:type rdfs:Class .
10
11ex:Book rdf:type rdfs:Class .
12
13
14# Property definition
15ex:address rdf:type rdf:Property ;
16        rdfs:domain ex:Library ;
17        rdfs:range xsd:string .
18
19ex:name rdf:type rdf:Property ;
20        rdfs:domain ex:Library ;
21        rdfs:range xsd:string .
22
23ex:name rdf:type rdf:Property ;
24        rdfs:domain ex:Author ;
25        rdfs:range xsd:string .
26
27ex:email rdf:type rdf:Property ;
28        rdfs:domain ex:Author ;
29        rdfs:range xsd:string .
30
31ex:title rdf:type rdf:Property ;
32        rdfs:domain ex:Book ;
33        rdfs:range xsd:string .
34
35ex:pages rdf:type rdf:Property ;
36        rdfs:domain ex:Book ;
37        rdfs:range xsd:integer .
38
39ex:release rdf:type rdf:Property ;
40        rdfs:domain ex:Book ;
41        rdfs:range xsd:dateTime .
42
43
44# Relationship Definition
45ex:lib_book_assoc rdf:type rdf:Property ;
46    rdfs:domain ex:Book ;
47    rdfs:range ex:Library .
48     
49ex:book_author_assoc rdf:type rdf:Property ;
50    rdfs:domain ex:Author ;
51    rdfs:range ex:Book .
52
53# Enumeration definition