Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon committed Aug 7, 2024
2 parents 8f76f8e + e6af159 commit 56444e9
Show file tree
Hide file tree
Showing 81 changed files with 1,677 additions and 162 deletions.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include 'vitrivr-engine-index'
include 'vitrivr-engine-query'
include 'vitrivr-engine-server'
include 'vitrivr-engine-module-cottontaildb'
include 'vitrivr-engine-module-jsonl'
include 'vitrivr-engine-module-pgvector'
include 'vitrivr-engine-module-features'
include 'vitrivr-engine-module-m3d'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.vitrivr.engine.core.features.fulltext
import org.vitrivr.engine.core.context.QueryContext
import org.vitrivr.engine.core.features.AbstractRetriever
import org.vitrivr.engine.core.model.content.element.ContentElement
import org.vitrivr.engine.core.model.descriptor.scalar.StringDescriptor
import org.vitrivr.engine.core.model.descriptor.scalar.TextDescriptor
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.query.fulltext.SimpleFulltextQuery

Expand All @@ -13,4 +13,4 @@ import org.vitrivr.engine.core.model.query.fulltext.SimpleFulltextQuery
* @author Ralph Gasser, Fynn Faber
* @version 1.2.0
*/
class FulltextRetriever<C: ContentElement<*>>(field: Schema.Field<C, StringDescriptor>, query: SimpleFulltextQuery, context: QueryContext) : AbstractRetriever<C, StringDescriptor>(field, query, context)
class FulltextRetriever<C: ContentElement<*>>(field: Schema.Field<C, TextDescriptor>, query: SimpleFulltextQuery, context: QueryContext) : AbstractRetriever<C, TextDescriptor>(field, query, context)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private fun convertType(directory: Directory, tagType: Int, type: Type): Value<*
Type.Short -> Value.Short(directory.getObject(tagType) as Short)
Type.String -> Value.String(directory.getString(tagType))
Type.Text -> Value.String(directory.getString(tagType))
Type.UUID -> Value.UUIDValue(UUID.fromString(directory.getString(tagType)))
is Type.BooleanVector -> throw IllegalArgumentException("Unsupported type: $type")
is Type.DoubleVector -> throw IllegalArgumentException("Unsupported type: $type")
is Type.FloatVector -> throw IllegalArgumentException("Unsupported type: $type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ interface ImageContent: ContentElement<BufferedImage> {
*
* @return [ByteBuffer] containing the audio in the WAVE format.
*/
fun toBytes(mimeType: MimeType = MimeType.PNG): ByteBuffer {
fun toBytes(mimeType: MimeType = MimeType.PNG): ByteArray {
require(mimeType.mediaType == MediaType.IMAGE) { "MimeType needs to be an image type" }
val out = ByteArrayOutputStream()
ImageIO.write(this.content, mimeType.fileExtension, out)
return ByteBuffer.wrap(out.toByteArray())
return out.toByteArray()
}

/**
Expand All @@ -47,8 +47,8 @@ interface ImageContent: ContentElement<BufferedImage> {
* @return Data URL
*/
fun toDataUrl(mimeType: MimeType = MimeType.PNG): String {
val buffer = this.toBytes(mimeType)
val base64 = Base64.getEncoder().encodeToString(buffer.array())
val array = this.toBytes(mimeType)
val base64 = Base64.getEncoder().encodeToString(array)
return "data:${mimeType.mimeType};base64,$base64"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.types.Type

/** The name of an attribute. */
Expand All @@ -12,4 +13,5 @@ typealias AttributeName = String
* @author Ralph Gasser
* @version 1.0.0
*/
@Serializable
data class Attribute(val name: AttributeName, val type: Type, val nullable: Boolean = false)
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.vitrivr.engine.core.model.descriptor

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.Persistable
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.retrievable.Retrievable
import org.vitrivr.engine.core.model.retrievable.RetrievableId
import org.vitrivr.engine.core.model.serializer.UUIDSerializer
import org.vitrivr.engine.core.model.types.Value
import java.util.*

/** A typealias to identify the [UUID] identifying a [Descriptor]. */
typealias DescriptorId = UUID
typealias DescriptorId = @Serializable(UUIDSerializer::class) UUID

/**
* A [Persistable] [Descriptor] that can be used to describe a [Retrievable].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.descriptor.Attribute
import org.vitrivr.engine.core.model.descriptor.DescriptorId
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor.Companion.VALUE_ATTRIBUTE_NAME
Expand All @@ -14,7 +15,6 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.0.0
*/

data class FloatDescriptor(
override var id: DescriptorId,
override var retrievableId: RetrievableId?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar


import org.vitrivr.engine.core.model.descriptor.Attribute
import org.vitrivr.engine.core.model.descriptor.DescriptorId
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor.Companion.VALUE_ATTRIBUTE_NAME
Expand All @@ -14,7 +15,6 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.0.0
*/

data class LongDescriptor(
override var id: DescriptorId,
override var retrievableId: RetrievableId?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.descriptor.AttributeName
import org.vitrivr.engine.core.model.descriptor.Descriptor
import org.vitrivr.engine.core.model.types.Value
Expand All @@ -10,6 +11,7 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.1.0
*/
@Serializable
sealed interface ScalarDescriptor<T : Value.ScalarValue<*>> : Descriptor {

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.vitrivr.engine.core.model.descriptor.scalar

import org.vitrivr.engine.core.model.descriptor.Attribute
import org.vitrivr.engine.core.model.descriptor.DescriptorId
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor.Companion.VALUE_ATTRIBUTE_NAME
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.retrievable.RetrievableId
import org.vitrivr.engine.core.model.types.Type
import org.vitrivr.engine.core.model.types.Value

/**
* A [ScalarDescriptor] using a [String] value.
*
* Compared to [StringDescriptor]s, [TextDescriptor]s are typically longer and can be used to store larger
* amounts of text. Certain databases use different storage mechanisms for [StringDescriptor]s and [TextDescriptor]s.
*
* @author Ralph Gasser
* @version 1.0.0
*/
data class TextDescriptor(
override var id: DescriptorId,
override var retrievableId: RetrievableId?,
override val value: Value.Text,
override val field: Schema.Field<*, TextDescriptor>? = null
) : ScalarDescriptor<Value.Text> {
companion object {
private val SCHEMA = listOf(Attribute(VALUE_ATTRIBUTE_NAME, Type.Text))
}

/**
* Returns the [Attribute] [List ]of this [StringDescriptor].
*
* @return [List] of [Attribute]
*/
override fun layout(): List<Attribute> = SCHEMA
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,135 @@
package org.vitrivr.engine.core.model.query.basics

import org.vitrivr.engine.core.model.query.bool.SimpleBooleanQuery
import org.vitrivr.engine.core.model.types.Value
import java.util.*

/**
* Enumeration of comparison operators used by the [SimpleBooleanQuery].
*
* @author Ralph Gasser
* @author Loris Sauter
* @version 1.1.0
* @author Luca Rossetto
* @version 1.2.0
*/
enum class ComparisonOperator(val value: String) {
EQ("=="),
NEQ("!="),
LE("<"),
GR(">"),
LEQ("<="),
GEQ(">="),
LIKE("~=");

companion object{
EQ("==") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean = v1.value == v2.value
},
NEQ("!=") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean = v1.value != v2.value
},
LE("<") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean =
when (v1) {
is Value.String -> v1.value < (v2.value as String)
is Value.Boolean -> v1.value < (v2.value as Boolean)
is Value.Byte -> v1.value < (v2.value as Byte)
is Value.DateTime -> v1.value < (v2.value as Date)
is Value.Double -> v1.value < (v2.value as Double)
is Value.Float -> v1.value < (v2.value as Float)
is Value.Int -> v1.value < (v2.value as Int)
is Value.Long -> v1.value < (v2.value as Long)
is Value.Short -> v1.value < (v2.value as Short)
is Value.Text -> v1.value < (v2.value as String)
is Value.UUIDValue -> v1.value < (v2.value as UUID)
is Value.BooleanVector,
is Value.DoubleVector,
is Value.FloatVector,
is Value.IntVector,
is Value.LongVector -> false
}

},
GR(">") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean =
when (v1) {
is Value.String -> v1.value > (v2.value as String)
is Value.Boolean -> v1.value > (v2.value as Boolean)
is Value.Byte -> v1.value > (v2.value as Byte)
is Value.DateTime -> v1.value > (v2.value as Date)
is Value.Double -> v1.value > (v2.value as Double)
is Value.Float -> v1.value > (v2.value as Float)
is Value.Int -> v1.value > (v2.value as Int)
is Value.Long -> v1.value > (v2.value as Long)
is Value.Short -> v1.value > (v2.value as Short)
is Value.Text -> v1.value > (v2.value as String)
is Value.UUIDValue -> v1.value > (v2.value as UUID)
is Value.BooleanVector,
is Value.DoubleVector,
is Value.FloatVector,
is Value.IntVector,
is Value.LongVector -> false
}

},
LEQ("<=") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean =
when (v1) {
is Value.String -> v1.value <= (v2.value as String)
is Value.Boolean -> v1.value <= (v2.value as Boolean)
is Value.Byte -> v1.value <= (v2.value as Byte)
is Value.DateTime -> v1.value <= (v2.value as Date)
is Value.Double -> v1.value <= (v2.value as Double)
is Value.Float -> v1.value <= (v2.value as Float)
is Value.Int -> v1.value <= (v2.value as Int)
is Value.Long -> v1.value <= (v2.value as Long)
is Value.Short -> v1.value <= (v2.value as Short)
is Value.Text -> v1.value <= (v2.value as String)
is Value.UUIDValue -> v1.value <= (v2.value as UUID)
is Value.BooleanVector,
is Value.DoubleVector,
is Value.FloatVector,
is Value.IntVector,
is Value.LongVector -> false
}

},
GEQ(">=") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean =
when (v1) {
is Value.String -> v1.value >= (v2.value as String)
is Value.Boolean -> v1.value >= (v2.value as Boolean)
is Value.Byte -> v1.value >= (v2.value as Byte)
is Value.DateTime -> v1.value >= (v2.value as Date)
is Value.Double -> v1.value >= (v2.value as Double)
is Value.Float -> v1.value >= (v2.value as Float)
is Value.Int -> v1.value >= (v2.value as Int)
is Value.Long -> v1.value >= (v2.value as Long)
is Value.Short -> v1.value >= (v2.value as Short)
is Value.Text -> v1.value >= (v2.value as String)
is Value.UUIDValue -> v1.value <= (v2.value as UUID)
is Value.BooleanVector,
is Value.DoubleVector,
is Value.FloatVector,
is Value.IntVector,
is Value.LongVector -> false
}

},
LIKE("~=") {
override fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean =
when (v1) {
is Value.String,
is Value.Text -> {
(v1.value as String).replace("\\", "\\\\").replace("[", "\\[").replace("]", "\\]")
.replace("*", "\\*").replace("%", "*").toRegex().matches(v2.value as String)
}

else -> false
}

};

companion object {
/**
* Resolves a [ComparisonOperator] from the given [String].
*
* @param str The [String] which should be one of the [ComparisonOperator]
* @throws IllegalArgumentException In case the given string is not one of the defined ones.
*/
fun fromString(str: String):ComparisonOperator{
return when(str.trim()){
fun fromString(str: String): ComparisonOperator {
return when (str.trim()) {
EQ.value -> EQ
NEQ.value -> NEQ
LE.value -> LE
Expand All @@ -38,4 +141,7 @@ enum class ComparisonOperator(val value: String) {
}
}
}

abstract fun <T> compare(v1: Value<T>, v2: Value<*>): Boolean

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import org.vitrivr.engine.core.model.types.Value
* A [SimpleFulltextQuery] that uses a [Value.String] to execute fulltext search on the underlying field.
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
data class SimpleFulltextQuery(
/** The [Value] being used for the query. */
val value: Value.String,
val value: Value.Text,

/**
* The name of the attribute that should be compared.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.vitrivr.engine.core.model.retrievable

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.Persistable
import org.vitrivr.engine.core.model.content.element.ContentElement
import org.vitrivr.engine.core.model.descriptor.Descriptor
import org.vitrivr.engine.core.model.relationship.Relationship
import org.vitrivr.engine.core.model.retrievable.attributes.RetrievableAttribute
import org.vitrivr.engine.core.model.serializer.UUIDSerializer
import java.util.*
import java.util.function.Predicate

/** A typealias to identify the [UUID] identifying a [Retrievable]. */
typealias RetrievableId = UUID
typealias RetrievableId = @Serializable(UUIDSerializer::class) UUID

/**
* A [Persistable] and [Retrievable] unit of information stored by vitrivr.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.vitrivr.engine.core.model.serializer

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.util.*

object DateSerializer: KSerializer<Date> {
override val descriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Date) = encoder.encodeLong(value.time)
override fun deserialize(decoder: Decoder): Date = Date(decoder.decodeLong())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.vitrivr.engine.core.model.serializer

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.vitrivr.engine.core.model.types.Value
import java.util.*

object DateTimeSerializer: KSerializer<Value.DateTime> {
override val descriptor = PrimitiveSerialDescriptor("DateTime", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Value.DateTime) = encoder.encodeLong(value.value.time)
override fun deserialize(decoder: Decoder): Value.DateTime = Value.DateTime(Date(decoder.decodeLong()))
}
Loading

0 comments on commit 56444e9

Please sign in to comment.