Commit 1e5f7363 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Implements expanded rule filed mapper

It is now possible to add subfields to usage.
parent 2018ffc3
Pipeline #9920 passed with stages
in 10 minutes and 4 seconds
FROM openjdk:8
FROM gradle:6.3-jdk8
ADD . /
WORKDIR /
RUN ./gradlew -q --no-scan --no-daemon --no-build-cache distTar
RUN gradle --no-daemon --no-scan --no-build-cache distTar
RUN cd /build/distributions && tar xf app.tar
FROM openjdk:8-jre-alpine
......
......@@ -27,7 +27,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 addRule(type: String, value: List<Pair<String, Literal>>)
fun addAgent(relation: String, agentType: String, properties: List<Pair<String, Literal>>)
fun langLiteral(text: String, language: String): Literal
fun literal(text: String): Literal
......
......@@ -23,6 +23,7 @@ import org.apache.jena.rdf.model.Model
import org.apache.jena.rdf.model.ModelFactory
import org.apache.jena.rdf.model.Property
import org.apache.jena.rdf.model.Resource
import org.apache.logging.log4j.LogManager
import org.memobase.mapping.KEYS
import org.memobase.rdf.DC
import org.memobase.rdf.EBUCORE
......@@ -33,6 +34,7 @@ import org.memobase.rdf.RICO
import org.memobase.rdf.SKOS
abstract class RecordResource(institutionId: String) : IResource {
private val log = LogManager.getLogger("ResourceBuilder")
val model: Model = ModelFactory.createDefaultModel()
......@@ -131,15 +133,19 @@ abstract class RecordResource(institutionId: String) : IResource {
resource.addProperty(KEYS.agentPropertiesMap[relation], blank)
}
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)
override fun addRule(type: String, value: List<Pair<String, Literal>>) {
if (value.isNotEmpty()) {
val blank = model.createResource()
blank.addProperty(RDF.type, RICO.Rule)
blank.addProperty(RICO.type, literal(type))
value.forEach {
blank.addProperty(KEYS.keysToPropertyMap[it.first], it.second)
}
blank.addProperty(RICO.regulates, resource)
resource.addProperty(RICO.regulatedBy, blank)
} else {
log.error("Add no rule for type $type, because there were no content properties mapped.")
}
blank.addProperty(RICO.regulates, resource)
resource.addProperty(RICO.regulatedBy, blank)
}
override fun langLiteral(text: String, language: String): Literal = model.createLiteral(text.trim(), language)
......
......@@ -52,6 +52,8 @@ object KEYS {
const val access = "access"
const val usage = "usage"
val usageSubPropertiesList = listOf("name", "sameAs")
// Places
const val placeOfCapture = "placeOfCapture"
......
......@@ -39,6 +39,7 @@ import org.memobase.mapping.mappers.PrefixFieldMapper
import org.memobase.mapping.mappers.RuleFieldMapper
import org.memobase.mapping.mappers.SkosConceptFieldMapper
import org.memobase.mapping.mappers.DirectFieldMapper
import org.memobase.mapping.mappers.ExpandedRuleFieldMapper
import org.memobase.mapping.mappers.RicoConceptMapper
import org.memobase.mapping.mappers.TypeFieldMapper
import org.memobase.rdf.SKOS
......@@ -232,11 +233,15 @@ class MappingConfig(directory: String) {
when (value) {
is Map<*, *> -> {
return value.entries.map {
val configField = parseFieldWithKeyValidation(
KEYS.rights,
it as Map.Entry<String, Any>,
ruleTypes)
RuleFieldMapper(configField)
when (it.key) {
KEYS.usage ->
ExpandedRuleFieldMapper(it.key as String, parseSubFieldProperties(it.key as String, (it.value as Map<String, Any>).entries, KEYS.usageSubPropertiesList))
KEYS.access ->
return@map RuleFieldMapper(parseAnnotationField(it as Map.Entry<String, Any>))
KEYS.holder ->
return@map RuleFieldMapper(parseAnnotationField(it as Map.Entry<String, Any>))
else -> throw InvalidMappingException("Rights section has a fixed set of valid types: ${KEYS.rights}.")
}
}
}
else -> throw InvalidMappingException("Expected key value map under rights label.")
......@@ -412,12 +417,27 @@ class MappingConfig(directory: String) {
private fun parseFieldWithKeyValidation(
parent: String,
entry: Map.Entry<String, Any>,
Map: List<String>
list: List<String>
): AnnotationField {
if (Map.contains(entry.key)) {
if (list.contains(entry.key)) {
return parseAnnotationField(entry)
} else {
throw InvalidMappingException("The section $parent does not allow the key: ${entry.key}. Use any of $Map.")
throw InvalidMappingException("The section $parent does not allow the key: ${entry.key}. Use any of $list.")
}
}
private fun parseSubFieldProperties(
parent: String,
entries: Set<Map.Entry<String, Any>>,
allowedSubFields: List<String>
): List<AnnotationField> {
return entries.map { entry ->
if (allowedSubFields.contains(entry.key)) {
return@map parseAnnotationField(entry)
} else {
throw InvalidMappingException("The section $parent only allows the following subfields: $allowedSubFields.")
}
}
}
}
......
/*
* mapper-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.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.LanguageField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.fields.MappedAnnotationField
class ExpandedRuleFieldMapper(private val type: String, private val configField: List<ConfigField>) : IFieldMapper {
override fun apply(source: Map<String, String>, subject: IResource) {
val properties = configField.mapNotNull { field ->
when (field) {
is MappedAnnotationField ->
source[field.field].let {
if (it != null) {
Pair(field.key, listOf(field.toLiteral(it)))
} else {
null
}
}
is ConstantField ->
Pair(field.key, listOf(field.toLiteral()))
is LanguageField -> {
val pair = Pair(field.key, field.toLangLiterals(source))
if (pair.second.isNotEmpty()) {
pair
} else {
null
}
}
is ListField -> {
val pair = Pair(field.key, field.toLiterals(source))
if (pair.second.isNotEmpty()) {
pair
} else {
null
}
}
}
}
if (properties.isNotEmpty()) {
}
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
package org.memobase.mapping.mappers
import org.memobase.builder.IResource
import org.memobase.mapping.KEYS
import org.memobase.mapping.fields.ConfigField
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.LanguageField
......@@ -32,15 +33,15 @@ class RuleFieldMapper(private val configField: ConfigField) : IFieldMapper {
is MappedAnnotationField ->
source[configField.field].let {
if (it != null) {
subject.addRule(configField.key, listOf(configField.toLiteral(it)))
subject.addRule(configField.key, listOf(Pair(KEYS.name, configField.toLiteral(it))))
}
}
is ConstantField ->
subject.addRule(configField.key, listOf(configField.toLiteral()))
subject.addRule(configField.key, listOf(Pair(KEYS.name, configField.toLiteral())))
is LanguageField ->
subject.addRule(configField.key, configField.toLangLiterals(source))
subject.addRule(configField.key, configField.toLangLiterals(source).map { value -> Pair(KEYS.name, value) })
is ListField ->
subject.addRule(configField.key, configField.toLiterals(source))
subject.addRule(configField.key, configField.toLiterals(source).map { value -> Pair(KEYS.name, value) })
}
}
}
\ No newline at end of file
......@@ -51,11 +51,6 @@ record:
de: architekt
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: rechteinhaber
usage: nutzungsrecht
access:
const: public
relatedPlaces: # blank node rico:Place with relation dcterms:spatial
- name:
de: quartier
......
......@@ -13,9 +13,6 @@
<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#publishedBy> _:B .
<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#regulatedBy> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#title> "«Villa Siegel», Zürich"@de .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#type> "Foto" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Agent> .
......@@ -25,9 +22,6 @@ _: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 .
......@@ -37,17 +31,8 @@ _:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch
_: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#name> "publisher"@de .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/record/BAZ-MEI_49884> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/record/BAZ-MEI_49884> .
_: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" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "usage" .
\ No newline at end of file
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
......@@ -12,6 +12,9 @@ digital:
rights: # blank nodes rico:Rule with type "x"
holder: rechte
usage:
const: cc-by-nc-nd
name:
const: In Copyright (InC) # rights statement http://rightsstatements.org/vocab/InC/1.0/
sameAs:
const: http://rightsstatements.org/vocab/InC/1.0/
access:
const: public
\ No newline at end of file
......@@ -6,20 +6,15 @@
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#instantiates> <https://memobase.ch/record/TEST-Sig_Han_1293> .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
_: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#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 <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Familie XYZ" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
_:B <https://www.ica.org/standards/RiC/ontology#title> "Familie XYZ" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "cc-by-nc-nd" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "access" .
_: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> "usage" .
\ No newline at end of file
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
......@@ -64,16 +64,24 @@ physical:
identifiers: # blank node rico:Identifier
callNumber: signatur
rights: # blank nodes rico:Rule with type "x"
holder: rechte
usage:
name:
const: In Copyright (InC) # rights statement http://rightsstatements.org/vocab/InC/1.0/
sameAs:
const: http://rightsstatements.org/vocab/InC/1.0/
access:
const: public
digital:
locator: # ebucore:locator
- link-zu-digitalisat
rights: # blank nodes rico:Rule with type "x"
holder: rechte
usage:
const: cc-by-nc-nd # just a test
name:
const: In Copyright (InC) # rights statement http://rightsstatements.org/vocab/InC/1.0/
sameAs:
const: http://rightsstatements.org/vocab/InC/1.0/
access:
const: public
\ No newline at end of file
......@@ -9,19 +9,14 @@
<https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "bildformat"@de .
<https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "codec"@de .
<https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> <https://www.ica.org/standards/RiC/ontology#type> "physicalObject" .
_: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#Rule> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Rule> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "Sig Han 1293" .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> .
_:B <https://www.ica.org/standards/RiC/ontology#title> "Familie XYZ" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "public" .
_: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" .
\ No newline at end of file
......@@ -5,20 +5,15 @@
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> <https://www.ica.org/standards/RiC/ontology#isDerivedFromInstantiation> <https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0> .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> <https://www.ica.org/standards/RiC/ontology#regulatedBy> _:B .
<https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
_: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#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 <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Familie XYZ" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> .
_:B <https://www.ica.org/standards/RiC/ontology#regulates> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1> .
_:B <https://www.ica.org/standards/RiC/ontology#title> "Familie XYZ" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "cc-by-nc-nd" .
_:B <https://www.ica.org/standards/RiC/ontology#title> "public" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "access" .
_: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> "usage" .
\ No newline at end of file
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ 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