Skip to content

Commit

Permalink
make entity definition map a lookup function
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Dec 22, 2024
1 parent c322879 commit 287600d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ final case class InferenceOptimizationService(
* if so, all ontologies defined by the project to which the data belongs, will be included in the results.
*
* @param entity an RDF entity.
* @param map a map of entity IRIs to the IRIs of the ontology where they are defined.
* @param lookup a function optionally defining the ontology in an entity is defined.
* @return a sequence of ontology IRIs which relate to the input RDF entity.
*/
private def resolveEntity(entity: Entity, map: Map[SmartIri, SmartIri]): Task[Seq[SmartIri]] =
private def resolveEntity(entity: Entity, lookup: SmartIri => Option[SmartIri]): Task[Seq[SmartIri]] =
entity match {
case IriRef(iri, _) =>
val internal = iri.toOntologySchema(InternalSchema)
val maybeOntoIri = map.get(internal)
val maybeOntoIri = lookup(internal)
maybeOntoIri match {
// if the map contains an ontology IRI corresponding to the entity IRI, then this can be returned
case Some(iri) => ZIO.succeed(Seq(iri))
Expand Down Expand Up @@ -105,10 +105,8 @@ final case class InferenceOptimizationService(

for {
ontoCache <- ontologyCache.getCacheData
// from the cache, get the map from entity to the ontology where the entity is defined
entityMap = ontoCache.entityDefinedInOntology
// resolve all entities from the WHERE clause to the ontology where they are defined
relevantOntologies <- ZIO.foreach(entities)(resolveEntity(_, entityMap))
relevantOntologies <- ZIO.foreach(entities)(resolveEntity(_, ontoCache.entityDefinedInOntology))
relevantOntologiesSet = relevantOntologies.flatten.toSet
relevantOntologiesMaybe =
relevantOntologiesSet match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class OntologyCacheData(
superPropertyOfRelations: Map[SmartIri, Set[SmartIri]],
classDefinedInOntology: Map[SmartIri, SmartIri],
propertyDefinedInOntology: Map[SmartIri, SmartIri],
entityDefinedInOntology: Map[SmartIri, SmartIri],
private val entityDefinedInOntology: Map[SmartIri, SmartIri],
private val standoffProperties: Set[SmartIri],
) {
lazy val allPropertyDefs: Map[SmartIri, PropertyInfoContentV2] = ontologies.values
Expand All @@ -43,6 +43,8 @@ case class OntologyCacheData(

def getAllStandoffPropertyEntities: Map[SmartIri, ReadPropertyInfoV2] =
ontologies.values.flatMap(_.properties.view.filterKeys(standoffProperties)).toMap

def entityDefinedInOntology(propertyIri: SmartIri): Option[SmartIri] = entityDefinedInOntology.get(propertyIri)
}
object OntologyCacheData {
val Empty = OntologyCacheData(
Expand Down

0 comments on commit 287600d

Please sign in to comment.