Commit 2ac0b587 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Added facet values for places

parent ca893d37
......@@ -20,16 +20,18 @@ 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.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.model.FacettedContainer
import org.memobase.model.LanguageContainer
import org.memobase.model.NameContainer
import org.memobase.model.SearchDoc
import org.memobase.rdf.NS
......@@ -50,6 +52,9 @@ class SearchDocTransform {
val contributorPersonBuilder = PersonContainerBuilder("", record, KEYS.contributor, input)
val creatorPersonBuilder = PersonContainerBuilder("", record, KEYS.creator, input)
val placesRelatedBuilder = FacettedContainerBuilder("spatial", record, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placeCapturedBuilder = FacettedContainerBuilder("P60556", record, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placeFacetBuilder = PlaceFacetBuilder()
for (item in input.values) {
......@@ -60,7 +65,9 @@ class SearchDocTransform {
producersPersonBuilder,
contributorPersonBuilder,
creatorPersonBuilder,
placeFacetBuilder
placeFacetBuilder,
placeCapturedBuilder,
placesRelatedBuilder
)) {
if (builder.filter(item)) {
builder.append(item)
......@@ -78,8 +85,6 @@ class SearchDocTransform {
val datesCreated = Filter.entitiesByProperty("created", record, input)
val datesIssued = Filter.entitiesByProperty("issued", record, input)
val temporal = Filter.entitiesByProperty("temporal", record, input)
val placesRelated = Filter.entitiesByProperty("spatial", record, input)
val placeCaptured = Filter.entitiesByProperty("P60556", record, input)
val genre = Filter.entitiesByProperty("hasGenre", record, input)
val subjects = Filter.entitiesByProperty("hasSubject", record, input)
......@@ -118,12 +123,12 @@ class SearchDocTransform {
abstract = Extract.languageContainer("abstract", record["abstract"]),
id = id,
institution = listOf(
NameContainer(
FacettedContainer(
LanguageContainer(emptyList(), emptyList(), emptyList(), emptyList()),
listOf(record["heldBy"] as String)
)
),
recordSet = NameContainer(
recordSet = FacettedContainer(
LanguageContainer(emptyList(), emptyList(), emptyList(), emptyList()),
listOf(record["isPartOf"] as String)
),
......@@ -134,8 +139,8 @@ class SearchDocTransform {
temporal = Extract.extractDate(temporal),
dateCreated = Extract.extractDate(datesCreated),
dateIssued = Extract.extractDate(datesIssued),
placeCapture = Extract.extractPlaces(placeCaptured),
placeRelated = Extract.extractPlaces(placesRelated),
placeCapture = placeCapturedBuilder.build(),
placeRelated = placesRelatedBuilder.build(),
placeFacet = placeFacetBuilder.build(),
rightsHolder = Extract.typedEntityByType(recordRules, "type", "holder", "name"),
memoriavClaim = record["P60451"] != null,
......
/*
* search-doc-service
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase.builders
import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import org.memobase.KEYS
import org.memobase.helpers.Extract
import org.memobase.model.FacettedContainer
import org.memobase.rdf.NS
class FacettedContainerBuilder(
private val sourceProperty: String,
private val sourceResource: JsonObject,
private val targetType: String,
private val nameProperty: String,
private val facetFunction: (jsonObject: JsonObject) -> List<String>
) : IFieldBuilder {
private val containers = mutableListOf<FacettedContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
if (jsonObject[KEYS.atType] != NS.rico + targetType) return false
return sourceResource[sourceProperty].let {
when (it) {
is String -> it == jsonObject[KEYS.entityId] as String
is JsonObject -> it[KEYS.entityId] as String == jsonObject[KEYS.entityId] as String
is JsonArray<*> -> {
it.any { child ->
when (child) {
is String -> child == jsonObject[KEYS.entityId] as String
is JsonObject -> child[KEYS.entityId] as String == jsonObject[KEYS.entityId] as String
else -> false
}
}
}
else -> false
}
}
}
override fun append(jsonObject: JsonObject): String {
containers.add(
FacettedContainer(
Extract.languageContainer("", jsonObject[nameProperty])
.reduce { acc, languageContainer -> acc.merge(languageContainer) },
facet = facetFunction(jsonObject)
)
)
return ""
}
override fun build(): List<FacettedContainer> {
return containers
}
}
......@@ -37,7 +37,7 @@ class PersonContainerBuilder(
private val containers = mutableListOf<PersonContainer>()
override fun filter(jsonObject: JsonObject): Boolean {
if (sourceResource[KEYS.atType] != NS.rico + KEYS.Person) return false
if (jsonObject[KEYS.atType] != NS.rico + KEYS.Person) return false
return if (creationRelationType != null) {
jsonObject[KEYS.agentIsTargetOfCreationRelation].let {
if (it != null)
......
......@@ -19,17 +19,17 @@
package org.memobase.helpers
import com.beust.klaxon.JsonObject
import org.memobase.model.NameContainer
import org.memobase.model.FacettedContainer
object CarrierType {
fun extract(items: List<JsonObject>): List<NameContainer> {
fun extract(items: List<JsonObject>): List<FacettedContainer> {
return items.map {
Extract.listOfStrings(it["sameAs"]).let { value ->
val name = Extract.languageContainer("carrierType", it["name"]).reduce { acc, languageContainer -> acc.merge(languageContainer) }
if (value.isEmpty()) {
NameContainer(name, emptyList())
FacettedContainer(name, emptyList())
} else {
NameContainer(name, value)
FacettedContainer(name, value)
}
}
}
......
......@@ -21,10 +21,10 @@ package org.memobase.helpers
import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.model.CreatorNameContainer
import org.memobase.model.DateContainer
import org.memobase.model.FacettedContainer
import org.memobase.model.LanguageContainer
import org.memobase.model.NameContainer
import org.memobase.model.RelationNameContainer
import org.memobase.rdf.NS
object Extract {
......@@ -123,13 +123,13 @@ object Extract {
}
}
fun facetEntity(entities: List<JsonObject>, property: String): List<NameContainer> {
fun facetEntity(entities: List<JsonObject>, property: String): List<FacettedContainer> {
return entities.mapNotNull {
val lang = languageContainer(it["@id"] as String, it[property])
if (lang.isEmpty()) {
null
} else {
NameContainer(lang.first(), lang.first().toList())
FacettedContainer(lang.first(), lang.first().toList())
}
}
}
......@@ -151,7 +151,7 @@ object Extract {
input: Map<String, JsonObject>,
creationRelationTypeParam: String,
agentTypeParam: String
): List<CreatorNameContainer> {
): List<RelationNameContainer> {
return creationRelations.mapNotNull { creationRelation ->
val creationRelationType = creationRelation["type"] as String
if (creationRelationTypeParam != creationRelationType) return@mapNotNull null
......@@ -167,7 +167,7 @@ object Extract {
log.error("Agent/Person/CorporateBody without rico:name found: ${agent["@id"]}.")
null
} else {
return@mapNotNull CreatorNameContainer(
return@mapNotNull RelationNameContainer(
agentName.reduce { acc, languageContainer -> acc.merge(languageContainer) },
if (name.isNotEmpty()) name.reduce { acc, languageContainer -> acc.merge(languageContainer) }
else LanguageContainer(emptyList(), emptyList(), emptyList(), listOf("Unknown")))
......
......@@ -21,7 +21,7 @@ package org.memobase.model
import com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude(JsonInclude.Include.NON_NULL)
data class NameContainer(
data class FacettedContainer(
val name: LanguageContainer,
val facet: List<String>
)
......@@ -21,7 +21,7 @@ package org.memobase.model
import com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude(JsonInclude.Include.NON_NULL)
data class CreatorNameContainer(
data class RelationNameContainer(
val name: LanguageContainer,
val relation: LanguageContainer
)
......@@ -40,11 +40,11 @@ data class SearchDoc(
val sameAs: List<String>,
// Concepts
val genre: List<NameContainer>,
val keywords: List<NameContainer>,
val genre: List<FacettedContainer>,
val keywords: List<FacettedContainer>,
val languageContent: List<LanguageContainer>,
val languageCaption: List<LanguageContainer>,
val language: List<NameContainer>,
val language: List<FacettedContainer>,
// Agents
val personSubject: List<PersonContainer>,
......@@ -55,20 +55,20 @@ data class SearchDoc(
val personsFacet: List<String>,
val corporateBodySubject: List<LanguageContainer>,
val corporateBodyCreator: List<CreatorNameContainer>,
val corporateBodyContributor: List<CreatorNameContainer>,
val corporateBodyCreator: List<RelationNameContainer>,
val corporateBodyContributor: List<RelationNameContainer>,
val corporateBodyPublisher: List<LanguageContainer>,
val corporateBodyProducer: List<LanguageContainer>,
val agentSubject: List<LanguageContainer>,
val agentCreator: List<CreatorNameContainer>,
val agentContributor: List<CreatorNameContainer>,
val agentCreator: List<RelationNameContainer>,
val agentContributor: List<RelationNameContainer>,
val agentPublisher: List<LanguageContainer>,
val agentProducer: List<LanguageContainer>,
// Places
val placeRelated: List<LanguageContainer>,
val placeCapture: List<LanguageContainer>,
val placeRelated: List<FacettedContainer>,
val placeCapture: List<FacettedContainer>,
val placeFacet: List<String>,
// Dates
......@@ -76,8 +76,8 @@ data class SearchDoc(
val dateCreated: List<DateContainer>,
val dateIssued: List<DateContainer>,
val institution: List<NameContainer>,
val recordSet: NameContainer,
val institution: List<FacettedContainer>,
val recordSet: FacettedContainer,
val memoriavClaim: Boolean,
......@@ -100,7 +100,7 @@ data class SearchDoc(
val colourPhysical: List<LanguageContainer>,
val usageConditionsPhysical: List<LanguageContainer>,
val physicalObjectNote: List<LanguageContainer>,
val format: List<NameContainer>,
val format: List<FacettedContainer>,
// Combined
val access: List<String>
......
{"title":[{"de":[],"fr":[],"it":[],"un":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"]}],"type":"Foto","sourceID":"216133","id":"https://memobase.ch/record/Burgerbib-Krebser-216133","descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Bundesplatz / Büren-Besitzung<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=216133"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Transport, Verkehr"]},"facet":["Transport, Verkehr"]}],"personsFacet":["0~A~#","1~A~Anonym~#","0~F~#","1~F~Familie Krebser~#"],"placeRelated":[{"de":[],"fr":[],"it":[],"un":["Käfiggässchen"]}],"placeFacet":["0~K~#","1~K~Käfiggässchen~#"],"dateCreated":[{"date":"1900/1909","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/institution/Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/recordSet/Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 13/2"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 85 mm","Höhe: 100 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}]}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"]}],"type":"Foto","sourceID":"216133","id":"https://memobase.ch/record/Burgerbib-Krebser-216133","descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Bundesplatz / Büren-Besitzung<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=216133"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Transport, Verkehr"]},"facet":["Transport, Verkehr"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Anonym"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"facet":["0~A~#","1~A~Anonym~#"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"facet":["0~F~#","1~F~Familie Krebser~#"]}],"personsFacet":["0~A~#","1~A~Anonym~#","0~F~#","1~F~Familie Krebser~#"],"placeRelated":[{"name":{"de":[],"fr":[],"it":[],"un":["Käfiggässchen"]},"facet":["0~K~#","1~K~Käfiggässchen~#"]}],"placeFacet":["0~K~#","1~K~Käfiggässchen~#"],"dateCreated":[{"date":"1900/1909","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/institution/Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/recordSet/Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 13/2"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 85 mm","Höhe: 100 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}]}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Anonym -- Armut"]}],"type":"Foto","sourceID":"208576","id":"https://memobase.ch/record/Burgerbib-Krebser-208576","abstract":[{"de":[],"fr":[],"it":[],"un":["Bildeintrag: auf der Verpackung: 49543<br>"]}],"descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Negativnummer<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=208576"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Armut"]},"facet":["Armut"]}],"personsFacet":["0~F~#","1~F~Familie Krebser~#","0~M~#","1~M~Moeglé, Jean~#"],"dateCreated":[{"date":"20. Jh.","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/institution/Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/recordSet/Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 64/21"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 165 mm","Höhe: 120 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}]}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Anonym -- Armut"]}],"type":"Foto","sourceID":"208576","id":"https://memobase.ch/record/Burgerbib-Krebser-208576","abstract":[{"de":[],"fr":[],"it":[],"un":["Bildeintrag: auf der Verpackung: 49543<br>"]}],"descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Negativnummer<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=208576"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Armut"]},"facet":["Armut"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Moeglé, Jean"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"facet":["0~M~#","1~M~Moeglé, Jean~#"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"facet":["0~F~#","1~F~Familie Krebser~#"]}],"personsFacet":["0~F~#","1~F~Familie Krebser~#","0~M~#","1~M~Moeglé, Jean~#"],"dateCreated":[{"date":"20. Jh.","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/institution/Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["https://memobase.ch/recordSet/Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 64/21"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 165 mm","Höhe: 120 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}]}
\ No newline at end of file
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