Skip to content

Commit

Permalink
Minimal documentation added with example use.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrietteharmse committed Jul 24, 2023
1 parent b6dbb73 commit 157ab5a
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 11 deletions.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
`uml2semantics` is an application that allows you to convert a UML class diagram to an OWL 2 ontology. Translating a UML
class diagram to an OWL 2 ontology allows one to reason over the ontology and thereby discover possible
inconsistencies or unintended consequences. The UML to OWL translation we use is based on
[UML to OWL](https://henrietteharmse.com/uml-vs-owl/uml-class-diagram-to-owl-and-sroiq-reference/), which
provides the related Manchester syntax and SROIQ semantics.


# Project status
`uml2semantics` is in the very early stages of development and thus is missing many features. Currently it has support
for specifying classes and attributes/associations using TSV files.


# Assumption
This tool assumes that the UML class diagrams are conceptual models and as such they contain no implementation related
details like interfaces, access modifiers or operations.

# Downloading

# Quick Start
## Employer and Employee example
As a quick start here is a small UML class diagram that we will convert to OWL. We define a `Person` class
that has attributes `name`, `surname` and `dateOfBirth`. The types we use are `name` and `surname` is `xsd:string`
and for `dateOfBirth` we use `xsd:dateTime`. `Employee` and `Employer` extends `Person`. An employee has exactly 1
employer and an employer has 1 or more employees.

![Employer Example](./docs/SimpleEmployerExample.png)

## TSV representation
Classes and attributes are created using 2 separate TSV files. First create
the TSV file for your classes. It has the following format:


| Curie | Name | Definition | ParentNames |
|-------|----------|------------|-------------|
| | Person | | |
| | Employee | | Person |
| | Employer | | Person |

Here we only specify the name for each class, hence the reason we used the **Name** column to define our classes. Since
`Employee` and `Employer` both extend the `Person` class, we add `Person` to **ParentNames** column. Multiple parents are
separated by `|`. Curie refer to compact URI based on the [W3C CURIE syntax](https://www.w3.org/TR/2010/NOTE-curie-20101216/).

To specify attributes we use the following format.

| ClassName | Curie | Name | ClassOrPrimitive | MinMultiplicity | MaxMultiplicity | Definition |
|------------|-------|-------------|------------------|-----------------|-----------------|------------|
| Person | | name | xsd:string | | | |
| Person | | surname | xsd:string | | | |
| Person | | dateOfBirth | Person | xsd:dateTime | | |
| Employee | | employedBy | Employer | 1 | 1 | |
| Employer | | employes | Employee | 1 | * | |

**ClassName** refers to the classname for which we are defining the attributes. Attributes can also be defined using curies,
but we again only used names for now. The type of an attribute can be a primitive or a class. Currenlty XML primitive data
types used in [Protege Desktop](https://protege.stanford.edu/) as data types are supported. When no multiplicity is given,
[1..1] is assumed. `*` is to refer to infinite as per usual.

A Google spreadsheet for this UML class diagram can be found [here](https://docs.google.com/spreadsheets/d/1FXpbc52Ag24Htj3Qq36Z743QB5SzlShzjeg98uxd2Xo/edit?usp=sharing).
Save the classes and attributes tabs as TSV files.

## Run uml2semantics
Assuming you have download uml2semantics to a`$uml2semantics` directory and saved the .tsv files to this directory as well,
you can run it as follows:

``
java -jar uml2semantics.jar \
-c "$uml2semantics/Employer - Classes.tsv" \
-a "$uml2semantics/Employer - Attributes.tsv" \
-o "$uml2semantics/employer.owl" \
-p "emp:http://uml2semantics.org/examples/employer#" \
-i "http://uml2semantics.org/examples/employer/v.0.1"
org.uml2semantics.uml2owl
``

This will cause the ontology to be written out to `$uml2semantics/employer.owl`. An example of this file can be seen
[here](./examples/employer/employer.owl)
11 changes: 10 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@ lazy val root = (project in file("."))
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
"ch.qos.logback" % "logback-classic" % "1.3.5",
"com.lihaoyi" %% "sourcecode" % "0.3.0"
)
),
assembly / assemblyMergeStrategy := {

case PathList("module-info.class") => MergeStrategy.discard
case PathList("META-INF", "versions", xs@_, "module-info.class") => MergeStrategy.discard
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
},
assembly / assemblyJarName := "uml2semantics.jar"
)
Binary file added docs/SimpleEmployerExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/uml2semantics.qea
Binary file not shown.
Binary file added docs/uml2semantics.qea-journal
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/employer/Employer - Attributes.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ClassName Curie Name ClassOrPrimitiveType MinMultiplicity MaxMultiplicity Definition
Person name xsd:string
Person surname xsd:string
Person dateOfBirth xsd:dateTime
Employee employedBy Employer 1 1
Employer employes Employee 1 *
4 changes: 4 additions & 0 deletions examples/employer/Employer - Classes.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Curie Name Definition ParentNames
Person
Employee Person
Employer Person
172 changes: 172 additions & 0 deletions examples/employer/employer.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://uml2semantics.org/examples/employer/v.0.1#"
xml:base="http://uml2semantics.org/examples/employer/v.0.1"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://uml2semantics.org/examples/employer/v.0.1"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->





<!-- http://uml2semantics.org/examples/employer#Employee/employedBy -->


<owl:ObjectProperty rdf:about="http://uml2semantics.org/examples/employer#Employee/employedBy">
<rdfs:domain rdf:resource="http://uml2semantics.org/examples/employer#Employee"/>
<rdfs:range rdf:resource="http://uml2semantics.org/examples/employer#Employer"/>
<rdfs:label>employedBy</rdfs:label>
</owl:ObjectProperty>



<!-- http://uml2semantics.org/examples/employer#Employer/employes -->


<owl:ObjectProperty rdf:about="http://uml2semantics.org/examples/employer#Employer/employes">
<rdfs:domain rdf:resource="http://uml2semantics.org/examples/employer#Employer"/>
<rdfs:range rdf:resource="http://uml2semantics.org/examples/employer#Employee"/>
<rdfs:label>employes</rdfs:label>
</owl:ObjectProperty>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->





<!-- http://uml2semantics.org/examples/employer#Person/dateOfBirth -->


<owl:DatatypeProperty rdf:about="http://uml2semantics.org/examples/employer#Person/dateOfBirth">
<rdfs:domain rdf:resource="http://uml2semantics.org/examples/employer#Person"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
<rdfs:label>dateOfBirth</rdfs:label>
</owl:DatatypeProperty>



<!-- http://uml2semantics.org/examples/employer#Person/name -->


<owl:DatatypeProperty rdf:about="http://uml2semantics.org/examples/employer#Person/name">
<rdfs:domain rdf:resource="http://uml2semantics.org/examples/employer#Person"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:label>name</rdfs:label>
</owl:DatatypeProperty>



<!-- http://uml2semantics.org/examples/employer#Person/surname -->


<owl:DatatypeProperty rdf:about="http://uml2semantics.org/examples/employer#Person/surname">
<rdfs:domain rdf:resource="http://uml2semantics.org/examples/employer#Person"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:label>surname</rdfs:label>
</owl:DatatypeProperty>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->





<!-- http://uml2semantics.org/examples/employer#Employee -->


<owl:Class rdf:about="http://uml2semantics.org/examples/employer#Employee">
<rdfs:subClassOf rdf:resource="http://uml2semantics.org/examples/employer#Person"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://uml2semantics.org/examples/employer#Employee/employedBy"/>
<owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onClass rdf:resource="http://uml2semantics.org/examples/employer#Employer"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:label>Employee</rdfs:label>
</owl:Class>



<!-- http://uml2semantics.org/examples/employer#Employer -->


<owl:Class rdf:about="http://uml2semantics.org/examples/employer#Employer">
<rdfs:subClassOf rdf:resource="http://uml2semantics.org/examples/employer#Person"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://uml2semantics.org/examples/employer#Employer/employes"/>
<owl:minQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minQualifiedCardinality>
<owl:onClass rdf:resource="http://uml2semantics.org/examples/employer#Employee"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:label>Employer</rdfs:label>
</owl:Class>



<!-- http://uml2semantics.org/examples/employer#Person -->


<owl:Class rdf:about="http://uml2semantics.org/examples/employer#Person">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://uml2semantics.org/examples/employer#Person/dateOfBirth"/>
<owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://uml2semantics.org/examples/employer#Person/name"/>
<owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://uml2semantics.org/examples/employer#Person/surname"/>
<owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:label>Person</rdfs:label>
</owl:Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 0.1.0-SNAPSHOT) https://github.com/owlcs/owlapi/ -->


6 changes: 0 additions & 6 deletions sbt-run.txt

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/scala/org/uml2semantics/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import java.io.File

case class InputParameters(classesTsv: Option[File] = None,
attributesTsv: Option[File] = None,
associationsTsv: Option[File] = None,
associationsByRoleTsv: Option[File] = None,
enumerationsTsv: Option[File] = None,
// enumerationsTsv: Option[File] = None,
owlOntologyFile: Option[File] = None,
ontologyIRI: String = "https://uml2semantics.com/ontology",
ontologyPrefix: String = "uml2ont:https://uml2semantics.com/ontology/",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/test.owl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@



<!-- Generated by the OWL API (version 5.5.0.2023-01-14T12:41:38Z) https://github.com/owlcs/owlapi/ -->
<!-- Generated by the OWL API (version 0.1.0-SNAPSHOT) https://github.com/owlcs/owlapi/ -->


0 comments on commit 157ab5a

Please sign in to comment.