-
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.
- Loading branch information
Showing
5 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
.../kotlin/org/vitrivr/engine/core/model/retrievable/decorators/RetrievableWithProperties.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,14 @@ | ||
package org.vitrivr.engine.core.model.retrievable.decorators | ||
|
||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
|
||
/** | ||
* A [Retrievable] with arbitrary Properties | ||
* | ||
* @version 1.0.0 | ||
*/ | ||
interface RetrievableWithProperties : Retrievable { | ||
|
||
val properties: Map<String, String> | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.vitrivr.engine.query.transform | ||
|
||
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.retrievable.Retrieved | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.retrieve.Transformer | ||
|
||
/** | ||
* Appends stringified key-value pairs to a [Retrieved] based on the values of a [Field], if available | ||
*/ | ||
class FieldLookup( | ||
override val input: Operator<Retrieved>, | ||
private val reader: DescriptorReader<*>, | ||
private val keys: Collection<String> | ||
|
||
) : Transformer<Retrieved, Retrieved.RetrievedWithProperties> { | ||
override fun toFlow(scope: CoroutineScope): Flow<Retrieved.RetrievedWithProperties> = flow { | ||
|
||
val inputRetrieved = input.toFlow(scope).toList() | ||
|
||
val ids = inputRetrieved.map { it.id }.toSet() | ||
|
||
if (ids.isEmpty()) { | ||
return@flow | ||
} | ||
|
||
val descriptors = reader.getAll(ids).filter { it.retrievableId != null }.associateBy { it.retrievableId!! } | ||
|
||
inputRetrieved.forEach { | ||
|
||
val withProperties = Retrieved.PlusProperties(it) | ||
|
||
val descriptor = descriptors[it.id] | ||
|
||
if (descriptor != null) { | ||
val values = descriptor.values().toMap() | ||
keys.forEach { key -> | ||
(withProperties.properties as MutableMap)[key] = values[key].toString() | ||
} | ||
} | ||
|
||
emit(withProperties) | ||
|
||
} | ||
|
||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.vitrivr.engine.query.transform | ||
|
||
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 | ||
|
||
class FieldLookupFactory( | ||
|
||
) : TransformerFactory<Retrieved, Retrieved.RetrievedWithProperties> { | ||
override fun newTransformer( | ||
input: Operator<Retrieved>, | ||
schema: Schema, | ||
properties: Map<String, String> | ||
): FieldLookup { | ||
|
||
val keys = properties["keys"]?.split(",")?.map { s -> s.trim() } ?: emptyList() | ||
val field = properties["field"] ?: throw IllegalArgumentException("expected 'field' to be defined in properties") | ||
val reader = (schema[field] ?: throw IllegalArgumentException("Field '$field' not defined in schema")).getReader() | ||
|
||
return FieldLookup( | ||
input, reader, keys | ||
) | ||
} | ||
} |
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,2 +1,3 @@ | ||
org.vitrivr.engine.query.transform.RelationExpanderFactory | ||
org.vitrivr.engine.query.transform.ScoreAggregatorFactory | ||
org.vitrivr.engine.query.transform.ScoreAggregatorFactory | ||
org.vitrivr.engine.query.transform.FieldLookupFactory |