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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@prefix ex: <http://example.org/vocab#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# Class definition
ex:Author rdf:type rdfs:Class ;
          rdfs:label "Author" .
ex:Book rdf:type rdfs:Class ;
          rdfs:label "Book" .
ex:Library rdf:type rdfs:Class ;
          rdfs:label "Library" .

# Property definition
ex:email rdf:type rdf:Property ;
        rdfs:domain ex:Author ;
        rdfs:range xsd:string ;
        rdfs:label "email" .
ex:name rdf:type rdf:Property ;
        rdfs:domain ex:Author ;
        rdfs:range xsd:string ;
        rdfs:label "name" .
ex:title rdf:type rdf:Property ;
        rdfs:domain ex:Book ;
        rdfs:range xsd:string ;
        rdfs:label "title" .
ex:release rdf:type rdf:Property ;
        rdfs:domain ex:Book ;
        rdfs:range xsd:date ;
        rdfs:label "release" .
ex:pages rdf:type rdf:Property ;
        rdfs:domain ex:Book ;
        rdfs:range xsd:integer ;
        rdfs:label "pages" .
ex:address rdf:type rdf:Property ;
        rdfs:domain ex:Library ;
        rdfs:range xsd:string ;
        rdfs:label "address" .
ex:name rdf:type rdf:Property ;
        rdfs:domain ex:Library ;
        rdfs:range xsd:string ;
        rdfs:label "name" .

# Relationship Definition
ex:writtenBy rdf:type rdf:Property ;
    rdfs:domain ex:Book ;
    rdfs:range ex:Author ;
    rdfs:label "writtenBy" .
ex:locatedIn rdf:type rdf:Property ;
    rdfs:domain ex:Book ;
    rdfs:range ex:Library ;
    rdfs:label "locatedIn" .

# Enumeration definition