diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala index 20594995d5..b113491121 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala @@ -176,7 +176,7 @@ object OntologyHelpers { directClassCardinalities: Map[SmartIri, Map[SmartIri, KnoraCardinalityInfo]], classCardinalitiesWithInheritance: Map[SmartIri, Map[SmartIri, KnoraCardinalityInfo]], allSubClassOfRelations: Map[SmartIri, Seq[SmartIri]], - superPropertyLookup: SmartIri => Option[Set[SmartIri]], + allSubPropertyOfRelations: Map[SmartIri, Set[SmartIri]], allPropertyDefs: Map[SmartIri, PropertyInfoContentV2], allKnoraResourceProps: Set[SmartIri], allLinkProps: Set[SmartIri], @@ -266,7 +266,7 @@ object OntologyHelpers { val maybePropertyAndSubproperty: Option[(SmartIri, SmartIri)] = OntologyHelpers.findPropertyAndSubproperty( propertyIris = allPropertyIrisForCardinalitiesInClass, - superPropertyLookup = superPropertyLookup, + subPropertyOfRelations = allSubPropertyOfRelations, ) maybePropertyAndSubproperty match { @@ -875,11 +875,11 @@ object OntologyHelpers { */ private def findPropertyAndSubproperty( propertyIris: Set[SmartIri], - superPropertyLookup: SmartIri => Option[Set[SmartIri]], + subPropertyOfRelations: Map[SmartIri, Set[SmartIri]], ): Option[(SmartIri, SmartIri)] = propertyIris.flatMap { propertyIri => val maybeBasePropertyIri: Option[SmartIri] = (propertyIris - propertyIri).find { otherPropertyIri => - superPropertyLookup(propertyIri).exists { (baseProperties: Set[SmartIri]) => + subPropertyOfRelations.get(propertyIri).exists { (baseProperties: Set[SmartIri]) => baseProperties.contains(otherPropertyIri) } } @@ -1038,7 +1038,7 @@ object OntologyHelpers { classIri = internalClassDef.classIri, thisClassCardinalities = classDefWithAddedLinkValueProps.directCardinalities, inheritableCardinalities = cardinalitiesAvailableToInherit, - superPropertyLookup = cacheData.getSuperPropertiesOf, + allSubPropertyOfRelations = cacheData.subPropertyOfRelations, errorSchema = ApiV2Complex, errorFun = { msg => throw BadRequestException(msg) }, ), @@ -1079,7 +1079,7 @@ object OntologyHelpers { _ <- findPropertyAndSubproperty( propertyIris = cardinalitiesForClassWithInheritance.keySet, - superPropertyLookup = cacheData.getSuperPropertiesOf, + subPropertyOfRelations = cacheData.subPropertyOfRelations, ) match { case Some((basePropertyIri, propertyIri)) => Validation.fail( @@ -1158,7 +1158,7 @@ object OntologyHelpers { classIri: SmartIri, thisClassCardinalities: Map[SmartIri, KnoraCardinalityInfo], inheritableCardinalities: Map[SmartIri, KnoraCardinalityInfo], - superPropertyLookup: SmartIri => Option[Set[SmartIri]], + allSubPropertyOfRelations: Map[SmartIri, Set[SmartIri]], errorSchema: OntologySchema, errorFun: String => Nothing, ): Map[SmartIri, KnoraCardinalityInfo] = { @@ -1169,7 +1169,7 @@ object OntologyHelpers { // If the class has a cardinality for a non-Knora property like rdfs:label (which can happen only // if it's a built-in class), we won't have any information about the base properties of that property. val basePropsOfThisClassProp: Set[SmartIri] = - superPropertyLookup(thisClassProp).getOrElse(Set.empty[SmartIri]) + allSubPropertyOfRelations.getOrElse(thisClassProp, Set.empty[SmartIri]) val overriddenBaseProps: Set[SmartIri] = inheritableCardinalities.foldLeft(Set.empty[SmartIri]) { case (acc, (baseClassProp, baseClassCardinality)) => @@ -1377,7 +1377,7 @@ object OntologyHelpers { def inheritCardinalitiesInLoadedClass( classIri: SmartIri, directSubClassOfRelations: Map[SmartIri, Set[SmartIri]], - superPropertyLookup: SmartIri => Option[Set[SmartIri]], + allSubPropertyOfRelations: Map[SmartIri, Set[SmartIri]], directClassCardinalities: Map[SmartIri, Map[SmartIri, KnoraCardinalityInfo]], ): Map[SmartIri, KnoraCardinalityInfo] = { // Recursively get properties that are available to inherit from base classes. If we have no information about @@ -1390,7 +1390,7 @@ object OntologyHelpers { acc ++ inheritCardinalitiesInLoadedClass( classIri = baseClass, directSubClassOfRelations = directSubClassOfRelations, - superPropertyLookup = superPropertyLookup, + allSubPropertyOfRelations = allSubPropertyOfRelations, directClassCardinalities = directClassCardinalities, ) } @@ -1405,7 +1405,7 @@ object OntologyHelpers { classIri = classIri, thisClassCardinalities = thisClassCardinalities, inheritableCardinalities = cardinalitiesAvailableToInherit, - superPropertyLookup = superPropertyLookup, + allSubPropertyOfRelations = allSubPropertyOfRelations, errorSchema = InternalSchema, (msg: String) => throw InconsistentRepositoryDataException(msg), ) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala index 09b9652e66..fe07f20839 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/model/OntologyCacheData.scala @@ -24,9 +24,9 @@ import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV */ case class OntologyCacheData( ontologies: Map[SmartIri, ReadOntologyV2], + subPropertyOfRelations: Map[SmartIri, Set[SmartIri]], private val classToSuperClassLookup: Map[SmartIri, Seq[SmartIri]], private val classToSubclassLookup: Map[SmartIri, Set[SmartIri]], - private val subPropertyOfRelations: Map[SmartIri, Set[SmartIri]], private val superPropertyOfRelations: Map[SmartIri, Set[SmartIri]], private val classDefinedInOntology: Map[SmartIri, SmartIri], private val propertyDefinedInOntology: Map[SmartIri, SmartIri], diff --git a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala index 0344377792..48ffc0ce3e 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/ontology/repo/service/OntologyCache.scala @@ -679,7 +679,7 @@ final case class OntologyCacheLive(triplestore: TriplestoreService, cacheDataRef OntologyHelpers.inheritCardinalitiesInLoadedClass( classIri = resourceClassIri, directSubClassOfRelations = directSubClassOfRelations, - superPropertyLookup = allSubPropertyOfRelations.get, + allSubPropertyOfRelations = allSubPropertyOfRelations, directClassCardinalities = directClassCardinalities, ) @@ -692,7 +692,7 @@ final case class OntologyCacheLive(triplestore: TriplestoreService, cacheDataRef directClassCardinalities = directClassCardinalities, classCardinalitiesWithInheritance = classCardinalitiesWithInheritance, allSubClassOfRelations = allSubClassOfRelations, - superPropertyLookup = allSubPropertyOfRelations.get, + allSubPropertyOfRelations = allSubPropertyOfRelations, allPropertyDefs = allPropertyDefs, allKnoraResourceProps = allKnoraResourceProps, allLinkProps = allLinkProps, @@ -914,7 +914,7 @@ final case class OntologyCacheLive(triplestore: TriplestoreService, cacheDataRef classIri = directSubClassIri, thisClassCardinalities = directSubClass.entityInfoContent.directCardinalities, inheritableCardinalities = inheritableCardinalities, - superPropertyLookup = cacheData.getSuperPropertiesOf, + allSubPropertyOfRelations = cacheData.subPropertyOfRelations, errorSchema = ApiV2Complex, errorFun = { (msg: String) => throw BadRequestException(msg)