Skip to content

Commit

Permalink
Still testing
Browse files Browse the repository at this point in the history
  • Loading branch information
henrietteharmse committed Nov 13, 2023
1 parent 0ce01b9 commit fd7ee38
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<!-- org.uml2semantics.TSVReader.scala -->
<logger name="parseClasses" level="error" />
<logger name="parseAttributes" level="error" />
<logger name="parseEnumerations" level="trace" />
<logger name="parseEnumerationValues" level="trace" />

<!-- org.uml2semantics.model.UMLClassDiagram.scala -->
<logger name="org.uml2semantics.model.UMLClassCurie" level="error" />
Expand All @@ -24,8 +26,10 @@
<logger name="org.uml2semantics.model.UMLMultiplicity" level="error" />
<logger name="org.uml2semantics.model.UMLClassIdentity" level="error" />
<logger name="org.uml2semantics.model.UMLClassAttributeType" level="error" />
<logger name="org.uml2semantics.model.UMLEnumeration" level="trace" />
<logger name="org.uml2semantics.model.UMLClassDiagram" level="error" />


<!-- org.uml2semantics.model.XMLDataType.scala -->
<logger name="org.uml2semantics.model.SupportedDataType" level="error" />

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/org/uml2semantics/model/UMLClassDiagram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ case class UMLClassAttribute(attributeIdentity: UMLClassAttributeIdentity,

case class UMLEnumerationDefinition(definition: String = "")

case class UMLEnumeration(enumeratonIdentity: UMLEnumerationIdentity,
case class UMLEnumeration(enumerationIdentity: UMLEnumerationIdentity,
definition: UMLEnumerationDefinition = UMLEnumerationDefinition())
extends UMLClassDiagramElement

Expand All @@ -613,6 +613,7 @@ object UMLEnumeration:
mutable.HashMap[UMLEnumerationIdentity, mutable.Set[UMLEnumerationValueIdentity]]()

def cache(enumerationIdentity: UMLEnumerationIdentity, enumerationValueIdentity: UMLEnumerationValueIdentity): UMLEnumerationIRI =
logger.debug(s"enumerationIdentity=$enumerationIdentity, enumerationValueIdentity=$enumerationValueIdentity ${Code.source}")
val enumerationValues: mutable.Set[UMLEnumerationValueIdentity] =
enumerationsWithEnumerationValues.getOrElse(enumerationIdentity, mutable.HashSet[UMLEnumerationValueIdentity]())
enumerationValues += enumerationValueIdentity
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/uml2semantics/owl/UML2OWLWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class UML2OWLWriter(val umlClassDiagram: UMLClassDiagram):
private def createAndAnnotateOWLClass(umlEnumeration: UMLEnumeration,
errorMessages: mutable.Seq[String]): OWLClass =
logger.debug(s"createAndAnnotateOWLEnumeration: umlEnumeration=$umlEnumeration, errorMessages=$errorMessages ${Code.source}")
val owlClass = dataFactory.getOWLClass(umlEnumeration.enumeratonIdentity.enumerationIRI.iri)
val owlClass = dataFactory.getOWLClass(umlEnumeration.enumerationIdentity.enumerationIRI.iri)
if manager.addAxiom(ontology, dataFactory.getOWLSubClassOfAxiom(owlClass, dataFactory.getOWLThing)) != SUCCESSFULLY then
errorMessages :+ s"Could not add axiom ${owlClass.getIRI} subClassOf owl:Thing"
createDefinitionAnnotation(owlClass, umlEnumeration.definition.definition, errorMessages)
createLabelAnnotation(owlClass, umlEnumeration.enumeratonIdentity.enumerationLabel, errorMessages)
createLabelAnnotation(owlClass, umlEnumeration.enumerationIdentity.enumerationLabel, errorMessages)
owlClass

/**
Expand Down Expand Up @@ -377,7 +377,7 @@ class UML2OWLWriter(val umlClassDiagram: UMLClassDiagram):
val owlClass = createAndAnnotateOWLClass(umlEnumeration, errorMessages)
if manager.addAxiom(ontology, dataFactory.getOWLSubClassOfAxiom(owlClass, dataFactory.getOWLThing)) != SUCCESSFULLY then
errorMessages :+ s"Could not add axiom ${owlClass.getIRI} subClassOf owl:Thing"
val umlEnumerationValueIdentitiesOption = UMLEnumeration.find(umlEnumeration.enumeratonIdentity)
val umlEnumerationValueIdentitiesOption = UMLEnumeration.find(umlEnumeration.enumerationIdentity)
if umlEnumerationValueIdentitiesOption.isDefined then
val individuals: mutable.Set[OWLIndividual] = new mutable.HashSet[OWLIndividual]()
umlEnumerationValueIdentitiesOption.get.foreach(v => {
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/org/uml2semantics/reader/TSVReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum EnumerationValuesHeader:

def parseClasses(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace): UMLClasses =
import ClassesHeader.*
val logger = Logger("TsvReader: parseClasses")
val logger = Logger("parseClasses")
logger.info("Start")
implicit object TsvFormat extends TSVFormat {}

Expand Down Expand Up @@ -108,7 +108,7 @@ end parseAttributes

def parseEnumerations(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace): UMLEnumerations =
import EnumerationsHeader.*
val logger = Logger("TsvReader: parseEnumerations")
val logger = Logger("parseEnumerations")
logger.info("Start")
implicit object TsvFormat extends TSVFormat {}

Expand Down Expand Up @@ -139,18 +139,18 @@ def parseEnumerations(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespac
reader.close()

val umlEnumerationByNamedElement = umlEnumerations.map(
umlEnumeration => (umlEnumeration.enumeratonIdentity.enumerationNamedElement, umlEnumeration)).toMap
umlEnumeration => (umlEnumeration.enumerationIdentity.enumerationNamedElement, umlEnumeration)).toMap
logger.trace(s"umlEnumerationByNamedElement = $umlEnumerationByNamedElement")
logger.info("Done")
UMLEnumerations(umlEnumerationByNamedElement)
end parseEnumerations

def parseEnumerationValues(maybeTsvFile: Option[File], ontologyPrefix: PrefixNamespace): UMLEnumerationValues =
import EnumerationValuesHeader.*
val logger = Logger("TsvReader: parseEnumerationValues")
val logger = Logger("parseEnumerationValues")
implicit object TsvFormat extends TSVFormat {}

if maybeTsvFile.isDefined then
if maybeTsvFile.isDefined then {
val reader = CSVReader.open(maybeTsvFile.get)
val umlEnumerationValues = mutable.Set[UMLEnumerationValue]()

Expand All @@ -160,30 +160,32 @@ def parseEnumerationValues(maybeTsvFile: Option[File], ontologyPrefix: PrefixNam

val enumerationIdentityOption = UMLEnumerationIdentity.findEnumerationNamedElement(
m(EnumerationValuesHeader.EnumerationName.toString))
logger.trace(s"enumerationNamedElement = $enumerationIdentityOption")
logger.trace(s"--------------- enumerationIdentityOption = $enumerationIdentityOption")
if enumerationIdentityOption.isDefined then
val enumerationIdentity = enumerationIdentityOption.get
val curieOption: Option[Curie] = if m(Curie.toString).contains(":") then
Some(org.uml2semantics.model.Curie(m(Curie.toString)))
else
None

val enumerationValueIdentity = UMLEnumerationValueIdentity(enumerationIdentity.enumerationNamedElement,
UMLEnumerationValueName(m(Name.toString)),
UMLEnumerationValueCurie(curieOption),
ontologyPrefix
)
logger.trace(s"enumerationValueIdentity = $enumerationValueIdentity")
val umlEnumerationValue = UMLEnumerationValue(enumerationValueIdentity,
UMLEnumerationValueDefinition(m(Definition.toString))
)
logger.trace(s"About to cache enumerationIdentity=$enumerationIdentity and enumerationValueIdentity=$enumerationValueIdentity")
UMLEnumeration.cache(enumerationIdentity, enumerationValueIdentity)
umlEnumerationValues += umlEnumerationValue
})
})
reader.close()
val umlEnumerationValuesById = umlEnumerationValues.map(umlEnumerationValue => (umlEnumerationValue.valueIdentity.valueNamedElement, umlEnumerationValue)).toMap
logger.trace(s"umlEnumerationValuesById = $umlEnumerationValuesById")
logger.info("Done")
UMLEnumerationValues(umlEnumerationValuesById)
}
else
UMLEnumerationValues(scala.collection.immutable.HashMap[UMLEnumerationValueNamedElement, UMLEnumerationValue]())
end parseEnumerationValues
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
emp:SalarySchedule emp:Daily Employee gets paid at the end of each day
SalarySchedule Weekly Employee gets paid at the end of each week on a Friday
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 fd7ee38

Please sign in to comment.