Skip to content

Commit

Permalink
Fixed some compilation errors
Browse files Browse the repository at this point in the history
still some issues with FES-based feautres
  • Loading branch information
lucaro committed Aug 21, 2024
1 parent 9a57907 commit 4e6ad96
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DescriptorAuthorAttribute() : MergingRetrievableAttribute {
return this
}

fun add(descriptor: Descriptor, author: String) = add(descriptor.id, author)
fun add(descriptor: Descriptor<*>, author: String) = add(descriptor.id, author)

@Synchronized
fun getAuthor(id: DescriptorId): String? = idToAuthorMap[id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class VectorDescriptorAggregator : TransformerFactory {

enum class AggregationStrategy {
FIRST {
override fun aggregate(collection: Collection<VectorDescriptor<*>>): VectorDescriptor<*> =
override fun aggregate(collection: Collection<VectorDescriptor<*, *>>): VectorDescriptor<*, *> =
collection.first()
},
MEAN {
override fun aggregate(collection: Collection<VectorDescriptor<*>>): VectorDescriptor<*> {
override fun aggregate(collection: Collection<VectorDescriptor<*, *>>): VectorDescriptor<*, *> {

val vec = FloatArray(collection.first().vector.size)

Expand Down Expand Up @@ -74,7 +74,7 @@ class VectorDescriptorAggregator : TransformerFactory {
}
};

abstract fun aggregate(collection: Collection<VectorDescriptor<*>>): VectorDescriptor<*>
abstract fun aggregate(collection: Collection<VectorDescriptor<*, *>>): VectorDescriptor<*, *>

}

Expand Down Expand Up @@ -103,7 +103,7 @@ class VectorDescriptorAggregator : TransformerFactory {
ingested.filteredAttribute(DescriptorAuthorAttribute::class.java)?.getDescriptorIds(authorName)
?: emptySet()
val descriptors =
ingested.descriptors.filter { it.id in descriptorIds }.filterIsInstance<VectorDescriptor<*>>()
ingested.descriptors.filter { it.id in descriptorIds }.filterIsInstance<VectorDescriptor<*, *>>()

if (descriptors.isEmpty()) {
return@map ingested //nothing to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import org.vitrivr.engine.core.operators.retrieve.Retriever
import java.util.*
import kotlin.reflect.KClass

class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor<*>> {

override val contentClasses: Set<KClass<out ContentElement<*>>> = emptySet() //no content is processed
override val descriptorClass: KClass<Descriptor> = Descriptor::class
override val descriptorClass: KClass<Descriptor<*>> = Descriptor::class

companion object {
const val TYPE_PARAMETER_NAME = "type"
Expand All @@ -52,7 +52,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
// }
// }

override fun prototype(field: Schema.Field<*, *>): Descriptor {
override fun prototype(field: Schema.Field<*, *>): Descriptor<*> {
val descriptorType = DescriptorType.valueOf(
field.parameters[TYPE_PARAMETER_NAME]
?: throw IllegalArgumentException("'$TYPE_PARAMETER_NAME' is not defined")
Expand Down Expand Up @@ -91,20 +91,20 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}

override fun newExtractor(
field: Schema.Field<ContentElement<*>, Descriptor>,
field: Schema.Field<ContentElement<*>, Descriptor<*>>,
input: Operator<Retrievable>,
context: IndexContext
): Extractor<ContentElement<*>, Descriptor> {
): Extractor<ContentElement<*>, Descriptor<*>> {
val authorName = field.parameters[AUTHORNAME_PARAMETER_NAME]
?: throw IllegalArgumentException("'$AUTHORNAME_PARAMETER_NAME' is not defined")
return Mapper(input, field, authorName)
}

inner class Mapper(
override val input: Operator<out Retrievable>,
override val field: Schema.Field<ContentElement<*>, Descriptor>,
override val field: Schema.Field<ContentElement<*>, Descriptor<*>>,
private val authorName: String
) : Extractor<ContentElement<*>, Descriptor> {
) : Extractor<ContentElement<*>, Descriptor<*>> {
override val analyser = this@DescriptorFieldMapper
override val name = field.fieldName
override val persisting = true
Expand Down Expand Up @@ -149,7 +149,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {

}

private fun toFloatDescriptor(descriptor: Descriptor): FloatDescriptor {
private fun toFloatDescriptor(descriptor: Descriptor<*>): FloatDescriptor {
field as Schema.Field<*, FloatDescriptor>
return when(descriptor) {
is FloatDescriptor -> descriptor.copy(field = field)
Expand All @@ -160,7 +160,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}
}

private fun toDoubleDescriptor(descriptor: Descriptor): DoubleDescriptor {
private fun toDoubleDescriptor(descriptor: Descriptor<*>): DoubleDescriptor {
field as Schema.Field<*, DoubleDescriptor>
return when(descriptor) {
is FloatDescriptor -> DoubleDescriptor(descriptor.id, descriptor.retrievableId, Value.Double(descriptor.value.value.toDouble()), field)
Expand All @@ -171,7 +171,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}
}

private fun toIntDescriptor(descriptor: Descriptor): IntDescriptor {
private fun toIntDescriptor(descriptor: Descriptor<*>): IntDescriptor {
field as Schema.Field<*, IntDescriptor>
return when(descriptor) {
is FloatDescriptor -> IntDescriptor(descriptor.id, descriptor.retrievableId, Value.Int(descriptor.value.value.toInt()), field)
Expand All @@ -182,7 +182,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}
}

private fun toFloatVectorDescriptor(descriptor: Descriptor): FloatVectorDescriptor {
private fun toFloatVectorDescriptor(descriptor: Descriptor<*>): FloatVectorDescriptor {
field as Schema.Field<*, FloatVectorDescriptor>
return when(descriptor) {
is FloatVectorDescriptor -> descriptor.copy(field = field)
Expand All @@ -193,7 +193,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}
}

private fun toDoubleVectorDescriptor(descriptor: Descriptor): DoubleVectorDescriptor {
private fun toDoubleVectorDescriptor(descriptor: Descriptor<*>): DoubleVectorDescriptor {
field as Schema.Field<*, DoubleVectorDescriptor>
return when(descriptor) {
is FloatVectorDescriptor -> DoubleVectorDescriptor(descriptor.id, descriptor.retrievableId, Value.DoubleVector(DoubleArray(descriptor.vector.size){descriptor.vector.value[it].toDouble()}), field)
Expand All @@ -204,7 +204,7 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
}
}

private fun toIntVectorDescriptor(descriptor: Descriptor): IntVectorDescriptor {
private fun toIntVectorDescriptor(descriptor: Descriptor<*>): IntVectorDescriptor {
field as Schema.Field<*, IntVectorDescriptor>
return when(descriptor) {
is FloatVectorDescriptor -> IntVectorDescriptor(descriptor.id, descriptor.retrievableId, Value.IntVector(IntArray(descriptor.vector.size){descriptor.vector.value[it].toInt()}), field)
Expand All @@ -222,31 +222,31 @@ class DescriptorFieldMapper : Analyser<ContentElement<*>, Descriptor> {
name: String,
input: Operator<Retrievable>,
context: IndexContext
): Extractor<ContentElement<*>, Descriptor> {
): Extractor<ContentElement<*>, Descriptor<*>> {
throw UnsupportedOperationException("DescriptorPersister required backing field")
}

override fun newRetrieverForQuery(
field: Schema.Field<ContentElement<*>, Descriptor>,
field: Schema.Field<ContentElement<*>, Descriptor<*>>,
query: Query,
context: QueryContext
): Retriever<ContentElement<*>, Descriptor> {
): Retriever<ContentElement<*>, Descriptor<*>> {
throw UnsupportedOperationException("DescriptorPersister does not support retrieval")
}

override fun newRetrieverForContent(
field: Schema.Field<ContentElement<*>, Descriptor>,
field: Schema.Field<ContentElement<*>, Descriptor<*>>,
content: Collection<ContentElement<*>>,
context: QueryContext
): Retriever<ContentElement<*>, Descriptor> {
): Retriever<ContentElement<*>, Descriptor<*>> {
throw UnsupportedOperationException("DescriptorPersister does not support retrieval")
}

override fun newRetrieverForDescriptors(
field: Schema.Field<ContentElement<*>, Descriptor>,
descriptors: Collection<Descriptor>,
field: Schema.Field<ContentElement<*>, Descriptor<*>>,
descriptors: Collection<Descriptor<*>>,
context: QueryContext
): Retriever<ContentElement<*>, Descriptor> {
): Retriever<ContentElement<*>, Descriptor<*>> {
throw UnsupportedOperationException("DescriptorPersister does not support retrieval")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DescriptorDistanceSegmenter : TransformerFactory {
private val atMost: Float
) : Transformer {

private fun compare(comparisonAnchor: Value.Vector<*>, descriptor: VectorDescriptor<*>): Boolean {
private fun compare(comparisonAnchor: Value.Vector<*>, descriptor: VectorDescriptor<*, *>): Boolean {
val dist = when (comparisonAnchor) {
is Value.FloatVector -> {
distance(comparisonAnchor, (descriptor as FloatVectorDescriptor).vector)
Expand Down Expand Up @@ -73,7 +73,7 @@ class DescriptorDistanceSegmenter : TransformerFactory {
ingested.filteredAttribute(DescriptorAuthorAttribute::class.java)?.getDescriptorIds(authorName)
?: emptySet()
val descriptors =
ingested.descriptors.filter { it.id in descriptorIds }.filterIsInstance<VectorDescriptor<*>>()
ingested.descriptors.filter { it.id in descriptorIds }.filterIsInstance<VectorDescriptor<*, *>>()
if (descriptors.isEmpty()) {
return@collect
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ 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.descriptor.scalar.TextDescriptor
import org.vitrivr.engine.core.model.metamodel.Analyser
import org.vitrivr.engine.core.model.metamodel.Analyser.Companion.merge
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.query.Query
import org.vitrivr.engine.core.model.query.fulltext.SimpleFulltextQuery
import org.vitrivr.engine.core.model.retrievable.Retrievable
import org.vitrivr.engine.core.model.types.Value
import org.vitrivr.engine.core.operators.Operator
import org.vitrivr.engine.core.operators.ingest.Extractor
import org.vitrivr.engine.core.operators.retrieve.Retriever
import java.util.*

Expand Down Expand Up @@ -49,7 +51,7 @@ class ImageCaption : ExternalFesAnalyser<ContentElement<*>, TextDescriptor>() {
* @param context The [IndexContext] to use with the [ImageCaptionExtractor].
* @return [ImageCaptionExtractor]
*/
override fun newExtractor(name: String, input: Operator<Retrievable>, context: IndexContext) = ImageCaptionExtractor(input, name, this, context.local[name] ?: emptyMap())
override fun newExtractor(name: String, input: Operator<Retrievable>, context: IndexContext) = TODO("type mismatch") // = ImageCaptionExtractor(input, name, this, emptyMap())

/**
* Generates and returns a new [ImageCaptionExtractor] instance for this [ImageCaption].
Expand All @@ -59,7 +61,7 @@ class ImageCaption : ExternalFesAnalyser<ContentElement<*>, TextDescriptor>() {
* @param context The [IndexContext] to use with the [ImageCaptionExtractor].
* @return [ImageCaptionExtractor]
*/
override fun newExtractor(field: Schema.Field<ContentElement<*>, TextDescriptor>, input: Operator<Retrievable>, context: IndexContext) = ImageCaptionExtractor(input, field, this, merge(field, context))
override fun newExtractor(field: Schema.Field<ContentElement<*>, TextDescriptor>, input: Operator<Retrievable>, context: IndexContext) = TODO("type mismatch") //ImageCaptionExtractor(input, field, this, merge(field, context) )

/**
* Generates and returns a new [FulltextRetriever] instance for this [ExternalFesAnalyser].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ImageCaptionExtractor : FesExtractor<ImageContent, TextDescriptor> {
parameters: Map<String, String>
) : super(input, name, analyser, parameters)


/** The [ImageCaptioningApi] used to perform extraction with. */
private val captioningApi by lazy { ImageCaptioningApi(this.host, this.model, this.timeoutMs, this.pollingIntervalMs, this.retries) }

Expand Down

0 comments on commit 4e6ad96

Please sign in to comment.