Skip to content

Commit

Permalink
Merge pull request #7 from henrietteharmse/enumerations
Browse files Browse the repository at this point in the history
Update docs and minor refactor
  • Loading branch information
henrietteharmse authored Nov 22, 2023
2 parents 81e2ca4 + 0d83b4f commit c839316
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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
UML class diagram information can be specified using TSV files. First create
the TSV file for your classes. It has the following format:


Expand All @@ -41,17 +41,38 @@ Here we only specify the name for each class, hence the reason we used the **Nam
`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/).

If you want to make use of enumerations, specify them next. The format is as follows:

| Curie | Name | Definition |
|--------------------|-----------------|-----------------------------------|
| emp:SalarySchedule | PaymentSchedule | Defines the frequency of payments |

Again you can specify a curie and/or a name to refer to your enumeration. In this case we assume there
is a difference between the purl and the label of this concept. Definition allows you to describe this
enumeration.

The values that an enumeration exists of, are specified in a different TSV with the following format:

| Enumeration | Curie | Name | Definition |
|----------------------|--------------|------|--------------------------------------------------------|
| emp:SalarySchedule | emp:Daily | | Employee gets paid at the end of each day |
| PaymentSchedule | Weekly | | Employee gets paid at the end of each week on a Friday |
| emp:SalarySchedule | emp:Monthly | | Employee gets paid at the last day of the month |

** Enumeration ** refers the name or curie of an enumeration. Each value of an enumeration can have a curie and/or a name
and a definition.

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 | xsd:dateTime | | | |
| Employee | | employedBy | Employer | 1 | 1 | |
| Employer | | employes | Employee | 1 | * | |
| Class | Curie | Name | ClassOrPrimitive | MinMultiplicity | MaxMultiplicity | Definition |
|----------|-------|-------------|------------------|-----------------|-----------------|------------|
| Person | | name | xsd:string | | | |
| Person | | surname | xsd:string | | | |
| Person | | dateOfBirth | 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,
**Class** refers to the class 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.
Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/org/uml2semantics/reader/TSVReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ enum ClassesHeader:
case Name, Curie, Definition, ParentNames

enum ClassAttributesHeader:
case ClassName, Curie, Name, ClassOrPrimitiveType, MinMultiplicity, MaxMultiplicity, Definition
case Class, Curie, Name, ClassEnumOrPrimitiveType, MinMultiplicity, MaxMultiplicity, Definition

enum EnumerationsHeader:
case Name, Curie, Definition

enum EnumerationValuesHeader:
case EnumerationName, Name, Curie, Definition
case Enumeration, Name, Curie, Definition

def parseClasses(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace): UMLClasses =
import ClassesHeader.*
Expand Down Expand Up @@ -78,11 +78,11 @@ def parseAttributes(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace)
reader.allWithHeaders().foreach(m => {
logger.trace(s"m = $m")

val classNamedElement = UMLClassIdentity.findClassNamedElement(m(ClassAttributesHeader.ClassName.toString))
val enumerationNamedElement = UMLEnumerationIdentity.findEnumerationNamedElement(m(ClassAttributesHeader.ClassName.toString))
val classNamedElement = UMLClassIdentity.findClassNamedElement(m(ClassAttributesHeader.Class.toString))
val enumerationNamedElement = UMLEnumerationIdentity.findEnumerationNamedElement(m(ClassAttributesHeader.Class.toString))
logger.trace(s"classNamedElement = $classNamedElement")
if classNamedElement.isDefined || enumerationNamedElement.isDefined then
logger.trace(s"mClassOrPrimitiveType.toString = {${m(ClassOrPrimitiveType.toString)}}")
logger.trace(s"mClassOrPrimitiveType.toString = {${m(ClassEnumOrPrimitiveType.toString)}}")
val curieOption: Option[Curie] = if m(Curie.toString).contains(":") then
Some(org.uml2semantics.model.Curie(m(Curie.toString)))
else
Expand All @@ -93,7 +93,7 @@ def parseAttributes(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace)
UMLClassAttributeCurie(curieOption),
ontologyPrefix
),
UMLClassAttributeType(m(ClassOrPrimitiveType.toString)),
UMLClassAttributeType(m(ClassEnumOrPrimitiveType.toString)),
UMLMultiplicity(UMLCardinality(m(MinMultiplicity.toString)), UMLCardinality(m(MaxMultiplicity.toString))),
UMLClassAttributeDefinition(m(Definition.toString))
)
Expand Down Expand Up @@ -160,7 +160,7 @@ def parseEnumerationValues(maybeTsvFile: Option[File], ontologyPrefix: PrefixNam
logger.trace(s"m = $m")

val enumerationIdentityOption = UMLEnumerationIdentity.findEnumerationNamedElement(
m(EnumerationValuesHeader.EnumerationName.toString))
m(EnumerationValuesHeader.Enumeration.toString))
logger.trace(s"--------------- enumerationIdentityOption = $enumerationIdentityOption")
if enumerationIdentityOption.isDefined then
val enumerationIdentity = enumerationIdentityOption.get
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/Employer - Attributes.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ClassName Curie Name ClassOrPrimitiveType MinMultiplicity MaxMultiplicity Definition
Class Curie Name ClassEnumOrPrimitiveType MinMultiplicity MaxMultiplicity Definition
Person name xsd:string
Person surname xsd:string
Person dateOfBirth xsd:dateTime
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/Employer - EnumerationNamedValues.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EnumerationName Curie Name Definition
Enumeration Curie Name Definition
emp:SalarySchedule emp:Daily Employee gets paid at the end of each day
PaymentSchedule Weekly Employee gets paid at the end of each week on a Friday
emp:SalarySchedule emp:Monthly Employee gets paid at the last day of the month

0 comments on commit c839316

Please sign in to comment.