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

Fix issue with missing person role values.

parent 3cad3d5b
Pipeline #21662 passed with stage
in 2 minutes and 12 seconds
......@@ -90,10 +90,13 @@ sealed class ConfigField {
value.value.forEachIndexed { index, s ->
// This makes the assumption that each value within each field
// is at the same index for a specific field.
if (resultList.size >= index + 1) {
resultList[index].add(field.toLiteral(s))
} else {
resultList.add(mutableListOf(field.toLiteral(s)))
// empty string act as padding to keep the original order.
if (s.isNotEmpty()) {
if (resultList.size >= index + 1) {
resultList[index].add(field.toLiteral(s))
} else {
resultList.add(mutableListOf(field.toLiteral(s)))
}
}
}
else -> log.debug("No value found for field $field.")
......@@ -135,10 +138,12 @@ sealed class ConfigField {
value.value.forEachIndexed { index, s ->
// This makes the assumption that each value within each field
// is at the same index for a specific field.
if (resultList.size >= index + 1) {
resultList[index].add(field.toLangLiteral(s, tag))
} else {
resultList.add(mutableListOf(field.toLangLiteral(s, tag)))
if (s.isNotEmpty()) {
if (resultList.size >= index + 1) {
resultList[index].add(field.toLangLiteral(s, tag))
} else {
resultList.add(mutableListOf(field.toLangLiteral(s, tag)))
}
}
}
else -> log.debug("No value found for field $field.")
......
......@@ -167,6 +167,7 @@ object FieldParsers {
}
}
is List<*> -> {
// TODO:
when {
objectValue.isEmpty() -> Empty
objectValue.size == 1 -> {
......@@ -188,7 +189,12 @@ object FieldParsers {
when (val unpackedValue = unpackValue(field, item[fields[1]])) {
is SimpleString -> resultList.add(unpackedValue.value)
is StringList -> resultList.addAll(unpackedValue.value)
Empty -> log.debug("No or illegal value in map found.")
Empty -> {
// Adding an empty value here because optional fields in objects
// otherwise mess up the order. This means that empty fields need to be ignored.
resultList.add("")
log.debug("No or illegal value in map found.")
}
}
}
}
......
......@@ -41,7 +41,8 @@ class CarrierTypeMapper(val field: AnnotationField) : AbstractFieldMapper() {
is SimpleString -> subject.addRicoCarrierType(listOf(field.toLiteral(sourceElement.value)))
is StringList ->
sourceElement.value.forEach {
subject.addRicoCarrierType(listOf(field.toLiteral(it)))
if (it.isNotEmpty())
subject.addRicoCarrierType(listOf(field.toLiteral(it)))
}
is Empty -> log.debug("No value for field ${field.key} in source data.")
}
......
......@@ -34,7 +34,8 @@ class DateFieldMapper(private val directMapField: DirectMapField) : AbstractFiel
when (sourceElement) {
is SimpleString -> subject.addDate(directMapField.key, sourceElement.value)
is StringList -> sourceElement.value.forEach {
subject.addDate(directMapField.key, it)
if (it.isNotEmpty())
subject.addDate(directMapField.key, it)
}
is Empty -> log.debug("Found no element for field ${directMapField.key}")
}
......
......@@ -34,7 +34,8 @@ class DirectFieldMapper(private val directMapField: DirectMapField) : AbstractFi
when (sourceElement) {
is SimpleString -> subject.addLiteral(directMapField.key, directMapField.toLiteral(sourceElement.value))
is StringList -> sourceElement.value.forEach {
subject.addLiteral(directMapField.key, directMapField.toLiteral(it))
if (it.isNotEmpty())
subject.addLiteral(directMapField.key, directMapField.toLiteral(it))
}
is Empty -> log.debug("Found no element for field ${directMapField.key}.")
}
......
......@@ -59,13 +59,15 @@ class ExpandedRuleFieldMapper(
)
is StringList ->
sourceElement.value.forEachIndexed { index, s ->
if (properties.size == index + 1)
properties[index].add(Pair(field.key, listOf(field.toLiteral(s))))
else
properties.add(
index,
mutableListOf(Pair(field.key, listOf(field.toLiteral(s))))
)
if (s.isNotEmpty()) {
if (properties.size == index + 1)
properties[index].add(Pair(field.key, listOf(field.toLiteral(s))))
else
properties.add(
index,
mutableListOf(Pair(field.key, listOf(field.toLiteral(s))))
)
}
}
Empty -> log.debug("Could not find a valid value for field ${field.key}.")
}
......
......@@ -34,7 +34,8 @@ class PrefixFieldMapper(private val prefixField: PrefixField) : AbstractFieldMap
when (sourceElement) {
is SimpleString -> subject.addLiteral(prefixField.key, prefixField.toLiteral(sourceElement.value))
is StringList -> sourceElement.value.forEach {
subject.addLiteral(prefixField.key, prefixField.toLiteral(it))
if (it.isNotEmpty())
subject.addLiteral(prefixField.key, prefixField.toLiteral(it))
}
is Empty -> log.debug("Found no element for field ${prefixField.key}.")
}
......
......@@ -41,7 +41,8 @@ class RicoConceptMapper(private val rdfType: String, val field: AnnotationField)
is SimpleString -> subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(it.value)))
is StringList ->
it.value.forEach { value ->
subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(value)))
if (value.isNotEmpty())
subject.addRicoConcept(rdfType, field.key, listOf(field.toLiteral(value)))
}
is Empty -> log.debug("Found no element for field ${field.key}.")
}
......
......@@ -44,10 +44,11 @@ class RuleFieldMapper(private val configField: ConfigField) : AbstractFieldMappe
)
is StringList ->
it.value.forEach { value ->
subject.addRule(
configField.key,
listOf(Pair(KEYS.name, listOf(configField.toLiteral(value))))
)
if (value.isNotEmpty())
subject.addRule(
configField.key,
listOf(Pair(KEYS.name, listOf(configField.toLiteral(value))))
)
}
is Empty -> log.debug("Found no element for field ${configField.key}.")
}
......
......@@ -54,10 +54,12 @@ abstract class TypeFieldMapper : AbstractFieldMapper() {
}
is StringList ->
sourceElement.value.forEachIndexed { index, s ->
if (properties.size >= index + 1) {
properties[index].add(Pair(field.key, field.toLiteral(s)))
} else {
properties.add(index, mutableListOf(Pair(field.key, field.toLiteral(s))))
if (s.isNotEmpty()) {
if (properties.size >= index + 1) {
properties[index].add(Pair(field.key, field.toLiteral(s)))
} else {
properties.add(index, mutableListOf(Pair(field.key, field.toLiteral(s))))
}
}
}
Empty -> log.debug("No valid value found for field ${field.key}.")
......
......@@ -20,11 +20,15 @@ package ch.memobase.test
import ch.memobase.builder.Record
import ch.memobase.mapping.MapperParsers
import ch.memobase.rdf.RICO
import java.io.FileOutputStream
import org.apache.jena.rdf.model.impl.SelectorImpl
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertAll
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestAgentMapper {
......@@ -67,8 +71,10 @@ class TestAgentMapper {
@Test
fun `test agent mapper with name and relation`() {
val source: Map<String, Any> = mapOf(
Pair("creatorPerson",
mapOf(Pair("name", "Hans Zimmer"), Pair("relationName", "Author")))
Pair(
"creatorPerson",
mapOf(Pair("name", "Hans Zimmer"), Pair("relationName", "Author"))
)
)
val record = Record(
"1",
......@@ -79,6 +85,74 @@ class TestAgentMapper {
isPublished = false
)
mapper.apply(source, record)
RDFDataMgr.write(FileOutputStream("$resourcePath/agent-mapper-with-name-and-relation.ttl"), record.model, Lang.TURTLE)
RDFDataMgr.write(
FileOutputStream("$resourcePath/agent-mapper-with-name-and-relation.ttl"),
record.model,
Lang.TURTLE
)
}
@Test
fun `test missing role name in list`() {
val source: Map<String, Any> = mapOf(
Pair(
"creatorPerson",
listOf(
mapOf(Pair("name", "First Person"), Pair("relationName", "Relation 1")),
mapOf(Pair("name", "Second Person")),
mapOf(Pair("name", "Third Person"), Pair("relationName", "Relation 3"))
)
)
)
val record = Record(
"1",
"Foto",
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
)
mapper.apply(source, record)
assertAll(
"",
{
assertThat(record.model)
.satisfies {
val selectR3 = SelectorImpl(null, RICO.name, "Relation 3")
val selectP3 = SelectorImpl(null, RICO.name, "Third Person")
val relationThreeStatements = it.listStatements(selectR3).toList()
val personThreeStatements = it.listStatements(selectP3).toList()
val selectCombination = SelectorImpl(
relationThreeStatements[0].subject,
RICO.creationRelationHasTarget,
personThreeStatements[0].subject
)
val relationIsConnectedToPerson = it.listStatements(selectCombination).toList()
assertAll(
"",
{
assertThat(relationThreeStatements)
.hasSize(1)
},
{
assertThat(personThreeStatements)
.hasSize(1)
},
{
assertThat(relationIsConnectedToPerson)
.hasSize(1)
}
)
}
}
)
RDFDataMgr.write(
FileOutputStream("$resourcePath/missing-relation-name-value-in-list.ttl"),
record.model,
Lang.TURTLE
)
}
}
@prefix rdau: <http://rdaregistry.info/Elements/u/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rico: <https://www.ica.org/standards/RiC/ontology#> .
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "First Person"
] ;
rico:name "Relation 1" ;
rico:type "creator" .
<https://memobase.ch/record/rs1-1>
a rico:Record ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
rico:type "main"
] ;
rico:isPartOf <https://memobase.ch/recordSet/rs1> ;
rico:recordResourceOrInstantiationIsSourceOfCreationRelation
_:b1 , _:b0 , _:b2 ;
rico:type "Foto" .
_:b2 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b2 ;
rico:name "Second Person"
] ;
rico:type "creator" .
_:b1 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b1 ;
rico:name "Third Person"
] ;
rico:name "Relation 3" ;
rico:type "creator" .
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