Commit 9f04798e authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Implements rule mapper for all record resources.

parent 76b29c7f
Pipeline #8737 failed with stages
in 4 minutes and 36 seconds
......@@ -31,6 +31,7 @@ interface IResource {
fun addPlace(type: String, properties: List<Pair<String, Literal>>)
fun addDate(property: String, value: String)
fun addCreationRelation(type: String, agentType: String, properties: List<Pair<String, Literal>>)
fun addRule(type: String, value: List<Literal>)
fun langLiteral(text: String, language: String): Literal
fun literal(text: String): Literal
}
\ No newline at end of file
......@@ -132,8 +132,19 @@ abstract class RecordResource(institutionId: String) : IResource {
resource.addProperty(RICO.recordResourceOrInstantiationIsSourceOfCreationRelation, relation)
}
override fun langLiteral(text: String, language: String): Literal = model.createLiteral(text, language)
override fun literal(text: String): Literal = model.createLiteral(text)
override fun addRule(type: String, value: List<Literal>) {
val blank = model.createResource()
blank.addProperty(RDF.type, RICO.Rule)
blank.addProperty(RICO.type, literal(type))
value.forEach {
blank.addProperty(RICO.title, it)
}
blank.addProperty(RICO.isRuleAssociatedWith, resource)
resource.addProperty(RICO.isAssociatedWithRule, blank)
}
override fun langLiteral(text: String, language: String): Literal = model.createLiteral(text.trim(), language)
override fun literal(text: String): Literal = model.createLiteral(text.trim())
protected fun uri(ns: String, name: String): String = ns + name
......
......@@ -43,6 +43,12 @@ object KEYS {
const val rights = "rights"
// Rule types
const val holder = "holder"
const val access = "access"
const val usage = "usage"
// Places
const val placeOfCapture = "placeOfCapture"
......
......@@ -53,7 +53,7 @@ class MappingConfig(directory: String) {
private val identifierTypes = listOf("original", "callNumber", "main")
private val titleTypes = listOf("main", "serial", "broadcast")
private val languageTypes = listOf("content", "caption")
private val ruleTypes = listOf("rights", "access", "holder", "usage")
private val ruleTypes = listOf(KEYS.holder, KEYS.access, KEYS.usage)
private val recordTypes = listOf("Film", "Foto", "Radio", "Ton", "Tonbildschau", "TV", "Video")
......
......@@ -21,11 +21,49 @@ package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.builder.Record
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstField
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.SimpleField
class RuleFieldMapper(private val configField: ConfigField) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
//TODO: Implement rules. Need to know more first!
when (configField) {
is SimpleField ->
source[configField.field].let {
if (it != null) {
subject.addRule(configField.key, listOf(subject.literal(it)))
}
}
is ConstField ->
subject.addRule(configField.key, listOf(subject.literal(configField.constant)))
is LanguageField -> {
val literals = configField.fields.map {
it.second.map innerMap@{ field ->
return@innerMap source[field].let { sourceValue ->
if (sourceValue != null) {
listOf(subject.langLiteral(sourceValue, it.first))
} else {
emptyList()
}
}
}.flatten()
}.flatten()
subject.addRule(configField.key, literals)
}
is ListField -> {
val literals = configField.fields.map { key ->
return@map source[key].let { sourceValue ->
if (sourceValue != null) {
listOf(subject.literal(sourceValue))
} else {
emptyList()
}
}
}.flatten()
subject.addRule(configField.key, literals)
}
}
}
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ object RICO {
val Agent = res("Agent")
val Person = res("Person")
val CorporateBody = res("CorporateBody")
val Rule = res("Rule")
val CreationRelation = res("CreationRelation")
......@@ -80,7 +81,9 @@ object RICO {
val creationRelationHasTarget: Property = prop("creationRelationHasTarget")
val recordResourceOrInstantiationIsSourceOfCreationRelation: Property = prop("recordResourceOrInstantiationIsSourceOfCreationRelation")
val isRuleAssociatedWith: Property = prop("isRuleAssociatedWith")
val intellectualPropertyRightsHeldBy: Property = prop("intellectualPropertyRightsHeldBy")
val isAssociatedWithRule: Property = prop("isAssociatedWithRule")
private fun prop(name: String): Property {
return ResourceFactory.createProperty(NS.rico, name)
......
......@@ -47,7 +47,7 @@ record:
hasFindingAid: verwandte_dokumente # rdau:P60262 "has finding aid" (provisional field)
creationDate: erstellung # blank node rico:DateSet with rico:expressedDate
rights: # blank nodes rico:Rule with type "x"
holder: rechtinhaber
holder: rechteinhaber
usage: nutzungsrecht
access:
const: public
......
......@@ -9,6 +9,9 @@
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/BAZ> .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#isAssociatedWithRule> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#isAssociatedWithRule> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#isAssociatedWithRule> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/BAZ-B_MEI> .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#recordResourceOrInstantiationIsSourceOfCreationRelation> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#title> "«Villa Siegel», Zürich"@de .
......@@ -19,17 +22,29 @@ _:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/stand
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Place> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Rule> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Rule> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Rule> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Title> .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasSource> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasTarget> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#expressedDate> "19210914" .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "MEI_49884" .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/BAZ-MEI_49884" .
_:B <https://www.ica.org/standards/RiC/ontology#isRuleAssociatedWith> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#isRuleAssociatedWith> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#isRuleAssociatedWith> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#isTitleOf> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Walz"@de .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Zürich"@de .
_:B <https://www.ica.org/standards/RiC/ontology#title> "BAZ" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "nach Absprache" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "«Villa Siegel», Zürich"@de .
_:B <https://www.ica.org/standards/RiC/ontology#type> "Auftraggeber" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "access" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "callNumber" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "holder" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "usage" .
\ No newline at end of file
Supports Markdown
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