-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a ObjectFieldLookup that facilitates lookup of fields for Retrie…
…vables that are in on 'object' relation to the core retrievable.
- Loading branch information
Ralph Gasser
committed
Apr 3, 2024
1 parent
e5718c6
commit 64fb907
Showing
5 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ivr/engine/query/transform/FieldLookup.kt → ...ine/query/transform/lookup/FieldLookup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ine/query/transform/FieldLookupFactory.kt → ...ry/transform/lookup/FieldLookupFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...gine-query/src/main/kotlin/org/vitrivr/engine/query/transform/lookup/ObjectFieldLookup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.vitrivr.engine.query.transform.lookup | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.toList | ||
import org.vitrivr.engine.core.database.descriptor.DescriptorReader | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Relationship | ||
import org.vitrivr.engine.core.model.retrievable.Retrieved | ||
import org.vitrivr.engine.core.model.retrievable.attributes.DescriptorAttribute | ||
import org.vitrivr.engine.core.model.retrievable.attributes.RelationshipAttribute | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.retrieve.Transformer | ||
|
||
/** | ||
* Appends [DescriptorAttribute] to a [Retrieved] in a specified object [Relationship] based on lookup values of a [Schema.Field], if available. | ||
* | ||
* @version 1.0.0 | ||
* @author Luca Rossetto | ||
* @author Ralph Gasser | ||
*/ | ||
class ObjectFieldLookup(override val input: Operator<Retrieved>, private val reader: DescriptorReader<*>, private val predicates: Set<String>) : Transformer { | ||
override fun toFlow(scope: CoroutineScope): Flow<Retrieved> = flow { | ||
/* Parse input IDs.*/ | ||
val inputRetrieved = input.toFlow(scope).toList() | ||
|
||
/* Fetch Retrievable entries that should be enriched. */ | ||
val enrich = inputRetrieved.mapNotNull { it.filteredAttribute(RelationshipAttribute::class.java) }.flatMap { r -> | ||
r.relationships.filter { this@ObjectFieldLookup.predicates.isEmpty() || it.pred in this@ObjectFieldLookup.predicates }.mapNotNull { it.obj.second } | ||
} | ||
val ids = enrich.map { it.id } | ||
val descriptors = if (ids.isNotEmpty()) { | ||
this@ObjectFieldLookup.reader.getAllBy(ids, "retrievableId").filter { it.retrievableId != null }.associateBy { it.retrievableId!! } | ||
} else { | ||
emptyMap() | ||
} | ||
|
||
/* Emit retrievable with added attribute. */ | ||
enrich.forEach { | ||
val descriptor = descriptors[it.id] | ||
if (descriptor != null) { | ||
it.addAttribute(DescriptorAttribute(descriptor)) | ||
} | ||
} | ||
|
||
/* Emit input. */ | ||
inputRetrieved.forEach { emit(it) } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ery/src/main/kotlin/org/vitrivr/engine/query/transform/lookup/ObjectFieldLookupFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.vitrivr.engine.query.transform.lookup | ||
|
||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Retrieved | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.retrieve.TransformerFactory | ||
|
||
|
||
/** | ||
* [TransformerFactory] for [ObjectFieldLookup]. | ||
* | ||
* @version 1.0.0 | ||
* @author Ralph Gasser | ||
*/ | ||
class ObjectFieldLookupFactory() : TransformerFactory { | ||
override fun newTransformer(input: Operator<Retrieved>, schema: Schema, properties: Map<String, String>): ObjectFieldLookup { | ||
val field = properties["field"] ?: throw IllegalArgumentException("Expected 'field' to be defined in properties") | ||
val predicates = properties["predicates"]?.split(",")?.toSet() ?: emptySet() | ||
val reader = (schema[field] ?: throw IllegalArgumentException("Field '$field' not defined in schema")).getReader() | ||
return ObjectFieldLookup(input, reader, predicates) | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...resources/META-INF/services/org.vitrivr.engine.core.operators.retrieve.TransformerFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.vitrivr.engine.query.transform.RelationExpanderFactory | ||
org.vitrivr.engine.query.transform.ScoreAggregatorFactory | ||
org.vitrivr.engine.query.transform.FieldLookupFactory | ||
org.vitrivr.engine.query.transform.lookup.FieldLookupFactory | ||
org.vitrivr.engine.query.transform.lookup.ObjectFieldLookupFactory |