dice-group / dice-group/OntologyClassGenerator
Implement ontology class generation
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Goal
Given the ontology of a vocabulary (in RDFS or OWL), the library should generate a Java class, enabling the usage of `Resource` and `Property` instances of the vocabularies classes and properties in Java.
### Input
* Location/path of the ontology file
* Namespace of the vocabulary
* Package and class name of the class to generate
* Output directory in which the directories for the package name of the class as well as the java file itself should be generated
### Output
* The generated Java class (as `.java` file containing the source code of the generated class). All these classes should follow the same template.
```java
package package-name;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
/**
* Javadoc comment describing the vocabulary. Should also contain
* a) the date/time at which it has been generated and b) the
* hint that changing this class does not make sense since it has been
* generated.
*/
public class ClassName {
/**
* The namespace of the vocabulary.
*/
protected static final String namespace = "http://example.org/vocab#";
/**
* returns the URI for this schema
*
* @return the URI for this schema
*/
public static String getURI() {
return namespace;
}
protected static final Resource resource(String local) {
return ResourceFactory.createResource(uri + local);
}
protected static final Property property(String local) {
return ResourceFactory.createProperty(uri, local);
}
// Resources sorted alphabetically
public static final Resource A = resource("A");
public static final Resource B = resource("B");
public static final Resource C = resource("C");
// Properties sorted alphabetically
public static final Property a = property("a");
public static final Property b = property("b");
public static final Property c = property("c");
}
```
## Extensions
* Add the generation of Javadoc comments based on the `rdfs:label` and `rdfs:comment` values in the ontology file
* Add a documentation how the class can be used in a Maven build process to generate a Java class automatically
* Add a default configuration which
* goes through certain directories of a project, e.g., `src/main/resources` and automatically generates ontology classes for ontologies found in this directory (and sub-directories).
* defines the class name based on the ontology file name and the package based on the path at which the ontology file has been found, e.g., `src/main/resources/org/example/Example.ttl` would lead to `src/main/java/org/example/Example.java`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.