Commit ef55c697 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Implements related agents and producers for mapping

parent d23980ba
......@@ -31,6 +31,7 @@ interface IResource {
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 addAgent(relation: String, agentType: String, properties: List<Pair<String, Literal>>)
fun langLiteral(text: String, language: String): Literal
fun literal(text: String): Literal
}
\ No newline at end of file
......@@ -132,6 +132,15 @@ abstract class RecordResource(institutionId: String) : IResource {
resource.addProperty(RICO.recordResourceOrInstantiationIsSourceOfCreationRelation, relation)
}
override fun addAgent(relation: String, agentType: String, properties: List<Pair<String, Literal>>) {
val blank = model.createResource()
blank.addProperty(RDF.type, KEYS.agentTypeMap[agentType])
for (property in properties) {
blank.addProperty(KEYS.keysToPropertyMap[property.first], property.second)
}
resource.addProperty(KEYS.agentPropertiesMap[relation], blank)
}
override fun addRule(type: String, value: List<Literal>) {
val blank = model.createResource()
blank.addProperty(RDF.type, RICO.Rule)
......
......@@ -56,17 +56,29 @@ object KEYS {
val allowedPlaceProperties = listOf("name")
// Creators
// Agents
const val creators = "creators"
const val creatorType = "creatorType"
const val producer = "producers"
const val relatedAgents = "relatedAgents"
val agentPropertiesMap = mapOf(
Pair(producer, RDA.hasProducer),
Pair(relatedAgents, RICO.hasSubject)
)
// Agent Types
const val agent = "agent"
const val corporateBody = "corporateBody"
const val person = "person"
val agentTypeMap = mapOf(
Pair(agent, RICO.Agent),
Pair(corporateBody, RICO.CorporateBody),
Pair(person, RICO.Person)
)
val allowedAgentProperties = listOf("name")
// skos:Concept
......@@ -92,13 +104,6 @@ object KEYS {
const val languages = "languages"
val agentTypeMap = mapOf(
Pair(agent, RICO.Agent),
Pair(corporateBody, RICO.CorporateBody),
Pair(person, RICO.Person)
)
// Physical Object Keys
const val medium = "medium"
......@@ -110,10 +115,12 @@ object KEYS {
const val playbackSpeed = "playbackSpeed"
const val hasStandard = "hasStandard"
// Digtal Object Keys
// Digital Object Keys
const val locator = "locator"
// datatype properties
val keysToPropertyMap = mapOf(
Pair(abstract, DC.abstract),
Pair(relatedPlaces, DC.spatial),
......
......@@ -176,8 +176,8 @@ class MappingConfig(directory: String) {
)
else -> throw InvalidMappingException("Dates only allow simple field assignment. Invalid mapping ${entry.key}.")
}
KEYS.creators ->
recordFieldMappers.addAll(buildCreatorMapper(entry.value))
KEYS.producer, KEYS.relatedAgents, KEYS.creators ->
recordFieldMappers.addAll(buildAgentMapper(key, entry.value))
else -> throw InvalidMappingException("Unknown key '$key' in record mapping.")
}
}
......@@ -236,14 +236,14 @@ class MappingConfig(directory: String) {
}
}
private fun buildCreatorMapper(value: Any?): List<IFieldMapper> {
private fun buildAgentMapper(key: String, value: Any?): List<IFieldMapper> {
when (value) {
is Map<*, *> -> {
return listOf(extractAgentTypeMapper(value as Map<String, Any>))
return listOf(extractAgentTypeMapper(key, value as Map<String, Any>))
}
is List<*> -> {
return value.map {
return@map extractAgentTypeMapper(it as Map<String, Any>)
return@map extractAgentTypeMapper(key, it as Map<String, Any>)
}
}
else -> throw InvalidMappingException("The section ${KEYS.creators} expects a map or list.")
......@@ -265,7 +265,7 @@ class MappingConfig(directory: String) {
}
}
private fun extractAgentTypeMapper(value: Map<String, Any>): IFieldMapper {
private fun extractAgentTypeMapper(key: String, value: Map<String, Any>): IFieldMapper {
val mapper = when {
value.containsKey(KEYS.agent) -> {
extractEntityFields<AgentFieldMapper>(
......@@ -292,7 +292,11 @@ class MappingConfig(directory: String) {
throw InvalidMappingException("Creation relation requires a field agent, corporateBody or person.")
}
}
(mapper as AgentFieldMapper).creationType = parseField(value.entries.first { i -> i.key == KEYS.creatorType })
(mapper as AgentFieldMapper).property = key
if (value.containsKey(KEYS.creatorType)) {
mapper.creationType = parseField(value.entries.first { i -> i.key == KEYS.creatorType })
}
return mapper
}
......
......@@ -25,6 +25,7 @@ import org.memobase.mapping.fields.SimpleField
class AgentFieldMapper : TypeFieldMapper() {
var creationType: ConfigField? = null
var property: String = ""
override fun apply(source: Map<String, String>, subject: IResource) {
translateProperties(source, subject)
if (properties.size > 0) {
......@@ -32,6 +33,7 @@ class AgentFieldMapper : TypeFieldMapper() {
is ConstField -> subject.addCreationRelation(creationTypeField.constant, type, properties)
is SimpleField -> source[creationTypeField.key].let {
if (it != null) subject.addCreationRelation(it, type, properties) }
else -> subject.addAgent(property, type, properties)
}
}
}
......
......@@ -27,6 +27,7 @@ object RDA {
val hasFindingAid = prop("P60262")
val hasPlaceOfCapture = prop("P60556")
val hasColourContent = prop("P60558")
val hasProducer = prop("P60441")
private fun prop(name: String): Property {
return ResourceFactory.createProperty(NS.rdau, name)
......
......@@ -139,10 +139,6 @@ class Tests {
)
recordCount += 1
}
}
private fun kafkaTests() = Stream.of(
......@@ -150,7 +146,7 @@ class Tests {
1,
"MEI_49884",
listOf("https://memobase.ch/record/BAZ-MEI_49884",
"https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0")
"https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0")
),
KafkaTestParams(
2,
......@@ -158,6 +154,15 @@ class Tests {
listOf(
"https://memobase.ch/record/TEST-Sig_Han_1293",
"https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0")
),
KafkaTestParams(
3,
"Sig Han 1293",
listOf(
"https://memobase.ch/record/TEST-Sig_Han_1293",
"https://memobase.ch/instantiation/physical/TEST-Sig_Han_1293-0",
"https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-1"
)
)
)
......
id: jobXYZ
app:
institutionId: "TEST"
recordSetId: "TEST_RECORD_SET"
configs: src/test/resources/kafkaTests/3/config
kafka:
streams:
bootstrap.servers: localhost:12345
application.id: test-clinet-1234
topic:
in: test-topic-in
out: test-topic-out
process: test-topic-process
\ No newline at end of file
......@@ -4,7 +4,7 @@
<https://memobase.ch/record/BAZ-MEI_49884> <http://rdaregistry.info/Elements/u/P60556> _:B .
<https://memobase.ch/record/BAZ-MEI_49884> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#descriptiveNote> "Villa mit Garten und Brunnen im Vordergrund. Vermutlich von Architekt Walz"@de .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#hasInstantiation> <https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#hasInstantiation> <https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> .
<https://memobase.ch/record/BAZ-MEI_49884> <https://www.ica.org/standards/RiC/ontology#hasTitle> _:B .
<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/instatiation/physical/BAZ-MEI_49884-0> <http://rdaregistry.info/Elements/u/P60558> "sw" .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMedium> "Negativ Nitrat (NN)"@de .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/BAZ> .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#instantiates> <https://memobase.ch/record/BAZ-MEI_49884> .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "18x24"@de .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "Nitratschaden"@de .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "Querformat"@de .
<https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#type> "physicalObject" .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <http://rdaregistry.info/Elements/u/P60558> "sw" .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMedium> "Negativ Nitrat (NN)"@de .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/BAZ> .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#instantiates> <https://memobase.ch/record/BAZ-MEI_49884> .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "18x24"@de .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "Nitratschaden"@de .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0> <https://www.ica.org/standards/RiC/ontology#physicalCharacteristics> "Querformat"@de .
<https://memobase.ch/instantiation/physical/BAZ-MEI_49884-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 <https://www.ica.org/standards/RiC/ontology#identifier> "MEI_49884" .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/instatiation/physical/BAZ-MEI_49884-0" .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/instantiation/physical/BAZ-MEI_49884-0" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "original" .
\ No newline at end of file
record:
uri: signatur
type: Tonbildschau # is always a constant!
title:
de: titel
descriptiveNote: # rico:descriptiveNote
de: beschreibung
scopeAndContent: # rico:scopeAndContent
de: kontext
creators: # a list of creators (with creationRelation rico:type)
- creatorType:
const: "Autor"
person:
name:
de: autor
- creatorType:
const: "Regie"
person:
name:
de: regie
- creatorType:
const: "Kamera"
person:
name:
de: kamera
producers: # rdau:P60441 has producer
corporateBody:
name:
de: produktion
relatedPlaces: # blank node rico:Place with dcterms:spatial
- name:
de: geographie
relatedAgents: # blank node rico:Agent with rico:hasSubject
agent:
name:
de: personen-körperschaften
subject: # blank node skos:Concept with rico:hasSubject
- prefLabel:
de:
- sachthemen
editorialNote:
const: "Ursprungsfeld: Sachthemen"
genre:
- prefLabel:
de:
- genre
editorialNote:
const: "Ursprungsfeld: Genre"
sameAs: # schema:sameAs
- link-zu-quellsystem
physical:
medium: # ebucore:hasMedium
de:
- ausgangsformat
physicalCharacteristics: # rico:physicalCharacteristics
de:
- bildformat
- filetype-codec-masterdatei
colour:
- farbe # rdau:P60558 has colour content (provisional field)
duration:
- dauer-exakt # ebucore:duration
identifier: # blank node rico:Identifier
callNumber:
- signatur
rights: # blank nodes rico:Rule with type "x"
holder: rechte
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
access:
const: public
\ No newline at end of file
{
"signatur": "Sig Han 1293",
"titel": "Das ist ein Titel",
"beschreibung": "Eine Bespielbeschreibung",
"rechte": "Familie XYZ",
"duration": "10:10:10",
"kontext": "Kontext text",
"autor": "name",
"regie": "name",
"kamera": "name",
"produktion": "name",
"geographie": "name",
"personen-körperschaften": "name",
"sachthemen": "name",
"genre": "name",
"link-zu-quellsystem": "http://example.org/stuff",
"ausgangsformat": "format",
"bildformat": "bildformat",
"filetype-codec-masterdatei": "codec",
"farbe": "farbe",
"dauer-exakt": "10:10:10",
"link-zu-digitalisat": "http://exampl.org/video/play"
}
\ No newline at end of file
<https://memobase.ch/record/TEST-Sig_Han_1293> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#hasInstantiation> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/TEST> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#type> "Video" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-Sig_Han_1293" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
<https://memobase.ch/record/TEST-Sig_Han_1293> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#hasInstantiation> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/TEST> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#type> "Video" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-Sig_Han_1293" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
<https://memobase.ch/record/TEST-Sig_Han_1293> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#hasInstantiation> <https://memobase.ch/instantiation/digital/TEST-Sig_Han_1293-0> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/TEST> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-Sig_Han_1293> <https://www.ica.org/standards/RiC/ontology#type> "Video" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-Sig_Han_1293" .
_: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