Skip to content

Commit

Permalink
revert possibly problematic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Dec 22, 2024
1 parent 4b67814 commit 271bad2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -266,7 +266,7 @@ object OntologyHelpers {

val maybePropertyAndSubproperty: Option[(SmartIri, SmartIri)] = OntologyHelpers.findPropertyAndSubproperty(
propertyIris = allPropertyIrisForCardinalitiesInClass,
superPropertyLookup = superPropertyLookup,
subPropertyOfRelations = allSubPropertyOfRelations,
)

maybePropertyAndSubproperty match {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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) },
),
Expand Down Expand Up @@ -1079,7 +1079,7 @@ object OntologyHelpers {

_ <- findPropertyAndSubproperty(
propertyIris = cardinalitiesForClassWithInheritance.keySet,
superPropertyLookup = cacheData.getSuperPropertiesOf,
subPropertyOfRelations = cacheData.subPropertyOfRelations,
) match {
case Some((basePropertyIri, propertyIri)) =>
Validation.fail(
Expand Down Expand Up @@ -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] = {
Expand All @@ -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)) =>
Expand Down Expand Up @@ -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
Expand All @@ -1390,7 +1390,7 @@ object OntologyHelpers {
acc ++ inheritCardinalitiesInLoadedClass(
classIri = baseClass,
directSubClassOfRelations = directSubClassOfRelations,
superPropertyLookup = superPropertyLookup,
allSubPropertyOfRelations = allSubPropertyOfRelations,
directClassCardinalities = directClassCardinalities,
)
}
Expand All @@ -1405,7 +1405,7 @@ object OntologyHelpers {
classIri = classIri,
thisClassCardinalities = thisClassCardinalities,
inheritableCardinalities = cardinalitiesAvailableToInherit,
superPropertyLookup = superPropertyLookup,
allSubPropertyOfRelations = allSubPropertyOfRelations,
errorSchema = InternalSchema,
(msg: String) => throw InconsistentRepositoryDataException(msg),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ final case class OntologyCacheLive(triplestore: TriplestoreService, cacheDataRef
OntologyHelpers.inheritCardinalitiesInLoadedClass(
classIri = resourceClassIri,
directSubClassOfRelations = directSubClassOfRelations,
superPropertyLookup = allSubPropertyOfRelations.get,
allSubPropertyOfRelations = allSubPropertyOfRelations,
directClassCardinalities = directClassCardinalities,
)

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 271bad2

Please sign in to comment.