Skip to content

Use SHACL shape as input for code generation #34

Description

@lecoqlibre

Currently we are generating source code from a UML model. This solution is costly to maintain and not user friendly. It needs to be done using a graphical tool that is hard to install and debug (Eclipse + Acceleo). The learning curve of Acceleo is high. Plus we are mainly using this solution to generate accessors and mutators (getters, setters, adders and removers).

For all these reasons I would like to propose to replace the UML model by SHACL shapes. SHACL Shapes Constraint Language is a language for validating RDF graphs against a set of conditions. I did some tests writing a simple generator in TypeScript and it worked well. Below is an example of an Enterprise shape in Turtle that allowed me to generate source code:

@prefix : <#>.
@prefix dfc: <https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#>.
@prefix sh: <http://www.w3.org/ns/shacl#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. 

:EnterpriseShape a sh:NodeShape;
    sh:targetClass dfc:Enterprise;
    sh:closed false;

    sh:property [
	sh:path dfc:name;
        sh:message "The name of the enterprise.";
        sh:datatype xsd:string;
        sh:maxCount 1;
	];

    sh:property [
	sh:path dfc:description;
        sh:message "The description of the enterprise.";
        sh:datatype xsd:string;
	];

    sh:property [
	sh:path dfc:date;
        sh:message "The date of the enterprise.";
        sh:datatype xsd:dateTime;
    ];

    sh:property [
	sh:path dfc:hasAddress;
        sh:message "The different addresses of the enterprise.";
        sh:datatype dfc:Address;
    ];

    sh:property [
	sh:path dfc:hasPhoneNumber;
        sh:message "The different phone numbers of the enterprise.";
        sh:datatype dfc:PhoneNumber;
   ];

    sh:property [
	sh:path dfc:hasSocialMedia;
        sh:message "The different social medias of the enterprise.";
        sh:datatype dfc:SocialMedia;
	];

    sh:property [
	sh:path dfc:logo;
        sh:message "The different logos of the enterprise.";
        sh:datatype xsd:anyURI;
	];

    sh:property [
	sh:path dfc:orders;
        sh:message "The different orders ordered by the enterprise.";
        sh:datatype dfc:Order;
	];

    sh:property [
	sh:path dfc:requests;
        sh:message "To be defined.";
        sh:datatype dfc:FunctionalProduct;
	];

    sh:property [
	sh:path dfc:owns;
        sh:message "To be defined.";
        sh:datatype dfc:PhysicalProduct;
	];

    sh:property [
	sh:path dfc:email;
        sh:message "To be defined.";
        sh:datatype xsd:string;
	];

    sh:property [
	sh:path dfc:websitePage;
        sh:message "To be defined.";
        sh:datatype xsd:anyURI;
	];

    sh:property [
	sh:path dfc:VATnumber;
        sh:message "To be defined.";
        sh:datatype xsd:string;
        sh:maxCount 1;
	];

    sh:property [
	sh:path dfc:defines;
        sh:message "To be defined.";
        sh:datatype dfc:CustomerCategory;
	];

    sh:property [
	sh:path dfc:hasMainContact;
        sh:message "To be defined.";
        sh:datatype dfc:Person;
        sh:maxCount 1;
	];

    sh:property [
	sh:path dfc:supplies;
        sh:message "To be defined.";
        sh:datatype dfc:SuppliedProduct;
	];

    sh:property [
	sh:path dfc:manages;
        sh:message "To be defined.";
        sh:datatype dfc:CatalogItem;
	];

    sh:property [
	sh:path dfc:proposes;
        sh:message "To be defined.";
        sh:datatype dfc:TechnicalProduct;
	];

    sh:property [
	sh:path dfc:transforms;
        sh:message "To be defined.";
        sh:datatype dfc:AsPlannedLocalTransformation;
	];

    sh:property [
	sh:path dfc:maintains;
        sh:message "To be defined.";
        sh:datatype dfc:Catalog;
	];

    sh:property [
	sh:path dfc:affiliates;
        sh:message "To be defined.";
        sh:datatype dfc:Person;
	];

    sh:property [
	sh:path dfc:coordinatedBy;
        sh:message "To be defined.";
        sh:datatype dfc:Coordination;
	].

As you see it is very simple to use and it's just RDF! We would also use shapes to do data validation.

It is not possible to generate source code from an ontology itself as an ontology is wide more open and some constraints may not be expressed.

Metadata

Metadata

Labels

enhancementNew feature or request

Fields

No fields configured for Feature.

Projects

Status
Icebox ❄

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions