From 0d83b4f524153447d72e91fba12a1bbf480089d5 Mon Sep 17 00:00:00 2001 From: henrietteharmse Date: Wed, 22 Nov 2023 20:11:04 +0000 Subject: [PATCH] Update docs and minor refactor --- README.md | 39 ++++++++++++++----- .../org/uml2semantics/reader/TSVReader.scala | 14 +++---- src/test/resources/Employer - Attributes.tsv | 2 +- .../Employer - EnumerationNamedValues.tsv | 2 +- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index bbf82bf..4f67805 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/src/main/scala/org/uml2semantics/reader/TSVReader.scala b/src/main/scala/org/uml2semantics/reader/TSVReader.scala index dfc9227..2fe7f60 100644 --- a/src/main/scala/org/uml2semantics/reader/TSVReader.scala +++ b/src/main/scala/org/uml2semantics/reader/TSVReader.scala @@ -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.* @@ -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 @@ -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)) ) @@ -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 diff --git a/src/test/resources/Employer - Attributes.tsv b/src/test/resources/Employer - Attributes.tsv index 5e71708..7c01724 100644 --- a/src/test/resources/Employer - Attributes.tsv +++ b/src/test/resources/Employer - Attributes.tsv @@ -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 diff --git a/src/test/resources/Employer - EnumerationNamedValues.tsv b/src/test/resources/Employer - EnumerationNamedValues.tsv index 1e4834f..486d5d3 100644 --- a/src/test/resources/Employer - EnumerationNamedValues.tsv +++ b/src/test/resources/Employer - EnumerationNamedValues.tsv @@ -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 \ No newline at end of file