Commit 24d05d5c authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Implement date containers

parent dc714882
Pipeline #13758 passed with stages
in 6 minutes and 21 seconds
......@@ -42,6 +42,14 @@ object KEYS {
const val Place = "Place"
const val Title = "Title"
// Dates
const val DateSet = "DateSet"
const val DateRange = "DateRange"
const val SingleDate = "SingleDate"
const val issued = "issued"
const val created = "created"
const val temporal = "temporal"
const val Instantiation = "Instantiation"
const val Record = "Record"
......
......@@ -20,17 +20,8 @@ package org.memobase
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.builders.FacettedContainerBuilder
import org.memobase.builders.IFieldBuilder
import org.memobase.builders.PersonContainerBuilder
import org.memobase.builders.PersonFacetBuilder
import org.memobase.builders.PlaceFacetBuilder
import org.memobase.builders.SuggestContainerBuilder
import org.memobase.helpers.CarrierType
import org.memobase.helpers.Extract
import org.memobase.helpers.FacetBuildHelpers
import org.memobase.helpers.Filter
import org.memobase.helpers.ReuseStatementMap
import org.memobase.builders.*
import org.memobase.helpers.*
import org.memobase.model.FacettedContainer
import org.memobase.model.LanguageContainer
import org.memobase.model.SearchDoc
......@@ -51,6 +42,9 @@ class SearchDocTransform {
val producerIds = Extract.identifiers(record[KEYS.producer])
val spatialIds = Extract.identifiers(record[KEYS.spatial])
val placeOfCaptureIds = Extract.identifiers(record[KEYS.placeOfCapture])
val dateCreatedIds = Extract.identifiers(record[KEYS.created])
val dateIssuedIds = Extract.identifiers(record[KEYS.issued])
val temporalIds = Extract.identifiers(record[KEYS.temporal])
val personFacetBuilder = PersonFacetBuilder()
val subjectPersonBuilder = PersonContainerBuilder(hasSubjectIds, null, input)
......@@ -65,6 +59,10 @@ class SearchDocTransform {
val placeFacetBuilder = PlaceFacetBuilder()
val dateCreatedBuilder = DateContainerBuilder(dateCreatedIds)
val dateIssuedBuilder = DateContainerBuilder(dateIssuedIds)
val temporalBuilder = DateContainerBuilder(temporalIds)
val suggestContainerBuilder = SuggestContainerBuilder(hasSubjectIds)
for (item in input.values) {
......@@ -78,6 +76,9 @@ class SearchDocTransform {
placeFacetBuilder,
placeCapturedBuilder,
placesRelatedBuilder,
dateCreatedBuilder,
dateIssuedBuilder,
temporalBuilder,
suggestContainerBuilder
)) {
if (builder.filter(item)) {
......@@ -93,10 +94,6 @@ class SearchDocTransform {
val recordLanguages = Filter.entitiesByProperty("hasLanguage", record, input)
val recordRules = Filter.entitiesByProperty("regulatedBy", record, input)
val datesCreated = Filter.entitiesByProperty("created", record, input)
val datesIssued = Filter.entitiesByProperty("issued", record, input)
val temporal = Filter.entitiesByProperty("temporal", record, input)
val genre = Filter.entitiesByProperty("hasGenre", record, input)
val subjects = Filter.entitiesByProperty("hasSubject", record, input)
......@@ -147,9 +144,9 @@ class SearchDocTransform {
scopeAndContent = Extract.languageContainer("scopeAndContent", record["scopeAndContent"]),
relatedMaterial = Extract.languageContainer("relation", record["relation"]),
source = Extract.languageContainer("source", record["source"]),
temporal = Extract.extractDate(temporal),
dateCreated = Extract.extractDate(datesCreated),
dateIssued = Extract.extractDate(datesIssued),
temporal = temporalBuilder.build(),
dateCreated = dateCreatedBuilder.build(),
dateIssued = dateIssuedBuilder.build(),
placeCapture = placeCapturedBuilder.build(),
placeRelated = placesRelatedBuilder.build(),
placeFacet = placeFacetBuilder.build(),
......
package org.memobase.builders
import com.beust.klaxon.JsonObject
import org.memobase.KEYS
import org.memobase.helpers.DateFacetBuildHelpers
import org.memobase.model.DateContainer
import org.memobase.rdf.NS
class DateContainerBuilder(private val containedIds: List<String>) : IFieldBuilder {
private val dateContainers = mutableListOf<DateContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
return if (containedIds.contains(jsonObject[KEYS.entityId]))
listOf(NS.rico + KEYS.DateRange, NS.rico + KEYS.SingleDate).contains(jsonObject[KEYS.atType])
else
false
}
override fun append(jsonObject: JsonObject): String {
val isNormalized = jsonObject.containsKey("normalizedDateValue")
val date = if (isNormalized) {
jsonObject["normalizedDateValue"] as String
} else {
jsonObject["expressedDate"] as String
}
val sort = if (isNormalized) {
date
} else {
null
}
val qualifier = jsonObject["dateQualifier"] as String?
val certainty = jsonObject["certainty"] as String?
val facetList = when (jsonObject["@type"] as String) {
NS.rico + "SingleDate" ->
if (isNormalized)
DateFacetBuildHelpers.buildFromNormalizedSingleDate(date)
else emptyList()
NS.rico + "DateRange" ->
if (isNormalized)
DateFacetBuildHelpers.buildFromNormalizedDateRange(date)
else emptyList()
else -> emptyList()
}
dateContainers.add(
DateContainer(
date = date,
sort = sort,
qualifier = qualifier,
certainty = certainty,
facet = facetList
)
)
return "Transformed date to date container."
}
override fun build(): List<DateContainer> {
return dateContainers
}
}
\ No newline at end of file
......@@ -29,8 +29,7 @@ class PersonContainerBuilder(
private val identifiers: List<String>,
private val creationRelationType: String?,
private val inputMap: Map<String, JsonObject>
) :
IFieldBuilder {
) : IFieldBuilder {
private val containers = mutableListOf<PersonContainer>()
......
......@@ -18,7 +18,7 @@
package org.memobase.helpers
object DateFacetBuilder {
object DateFacetBuildHelpers {
private const val separator = "~"
private const val terminator = "#"
......
......@@ -82,36 +82,6 @@ object Extract {
}
}
fun extractDate(entities: List<JsonObject>): List<DateContainer> {
return entities.map { entity ->
val isNormalized = entity.containsKey("normalizedDateValue")
val date = if (isNormalized) {
entity["normalizedDateValue"] as String
} else {
entity["expressedDate"] as String
}
val qualifier = entity["dateQualifier"] as String?
val certainty = entity["certainty"] as String?
val facetList = when (entity["@type"] as String) {
NS.rico + "SingleDate" ->
if (isNormalized)
DateFacetBuilder.buildFromNormalizedSingleDate(date)
else emptyList()
NS.rico + "DateRange" ->
if (isNormalized)
DateFacetBuilder.buildFromNormalizedDateRange(date)
else emptyList()
else -> emptyList()
}
DateContainer(
date = date,
qualifier = qualifier,
certainty = certainty,
facet = facetList
)
}
}
fun typedEntityByType(
entities: List<JsonObject>,
field: String,
......
......@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude(JsonInclude.Include.NON_NULL)
data class DateContainer(
val date: String,
val sort: String?,
val certainty: String?,
val qualifier: String?,
val facet: List<String>
......
......@@ -28,7 +28,7 @@ import org.junit.jupiter.api.assertAll
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.memobase.builders.PersonFacetBuilder
import org.memobase.helpers.DateFacetBuilder
import org.memobase.helpers.DateFacetBuildHelpers
import org.memobase.params.PersonFacetBuilderParams
import org.memobase.params.TestDate
import org.memobase.rdf.NS
......@@ -130,9 +130,9 @@ class TestFacetBuilders {
fun `test date facet`(date: TestDate) {
val result = when (date.type) {
"single" ->
DateFacetBuilder.buildFromNormalizedSingleDate(date.date)
DateFacetBuildHelpers.buildFromNormalizedSingleDate(date.date)
"range" ->
DateFacetBuilder.buildFromNormalizedDateRange(date.date)
DateFacetBuildHelpers.buildFromNormalizedDateRange(date.date)
else ->
emptyList()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment