-
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.
Additional content aggregation logic
- Loading branch information
Showing
2 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ine-index/src/main/kotlin/org/vitrivr/engine/index/aggregators/CenterContentAggregator.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,46 @@ | ||
package org.vitrivr.engine.index.aggregators | ||
|
||
import org.vitrivr.engine.core.context.IndexContext | ||
import org.vitrivr.engine.core.model.content.element.AudioContent | ||
import org.vitrivr.engine.core.model.content.element.ContentElement | ||
import org.vitrivr.engine.core.model.content.element.ImageContent | ||
import org.vitrivr.engine.core.model.content.element.TextContent | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.ingest.Aggregator | ||
import org.vitrivr.engine.core.operators.ingest.AggregatorFactory | ||
import org.vitrivr.engine.core.operators.ingest.Segmenter | ||
|
||
/** | ||
* A [Aggregator] that returns the middle [ContentElement] of each type. | ||
* | ||
* @version 1.0.0 | ||
*/ | ||
class CenterContentAggregator : AggregatorFactory { | ||
|
||
/** | ||
* Returns an [CenterContentAggregator.Instance]. | ||
* | ||
* @param input The [Segmenter] to use as input. | ||
* @param context The [IndexContext] to use. | ||
* @param parameters Optional set of parameters. | ||
* @return [AllContentAggregator.Instance] | ||
*/ | ||
override fun newOperator(input: Segmenter, context: IndexContext, parameters: Map<String, String>): Aggregator = Instance(input, context) | ||
|
||
/** | ||
* The [Instance] returns by the [AggregatorFactory] | ||
*/ | ||
private class Instance(override val input: Operator<Retrievable>, context: IndexContext) : AbstractAggregator(input, context) { | ||
override fun aggregate(content: List<ContentElement<*>>): List<ContentElement<*>> { | ||
val imageContent = content.filterIsInstance<ImageContent>() | ||
val audioContent = content.filterIsInstance<AudioContent>() | ||
val textContent = content.filterIsInstance<TextContent>() | ||
return listOfNotNull( | ||
imageContent.let { if (it.isNotEmpty()) it[it.size / 2] else null }, | ||
audioContent.let { if (it.isNotEmpty()) it[it.size / 2] else null }, | ||
textContent.let { if (it.isNotEmpty()) it[it.size / 2] else null } | ||
) | ||
} | ||
} | ||
} |
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