Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
libraries
Mapper Service Configuration
Commits
ec596a8e
Commit
ec596a8e
authored
Feb 11, 2021
by
Jonas Waeber
Browse files
Fix issue with missing person role values.
parent
3cad3d5b
Pipeline
#21662
passed with stage
in 2 minutes and 12 seconds
Changes
12
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/mapping/fields/ConfigField.kt
View file @
ec596a8e
...
...
@@ -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."
)
...
...
src/main/kotlin/mapping/fields/FieldParsers.kt
View file @
ec596a8e
...
...
@@ -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."
)
}
}
}
}
...
...
src/main/kotlin/mapping/mappers/CarrierTypeMapper.kt
View file @
ec596a8e
...
...
@@ -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."
)
}
...
...
src/main/kotlin/mapping/mappers/DateFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}"
)
}
...
...
src/main/kotlin/mapping/mappers/DirectFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
}
...
...
src/main/kotlin/mapping/mappers/ExpandedRuleFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
}
...
...
src/main/kotlin/mapping/mappers/PrefixFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
}
...
...
src/main/kotlin/mapping/mappers/RicoConceptMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
}
...
...
src/main/kotlin/mapping/mappers/RuleFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
}
...
...
src/main/kotlin/mapping/mappers/TypeFieldMapper.kt
View file @
ec596a8e
...
...
@@ -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}."
)
...
...
src/test/kotlin/ch/memobase/test/TestAgentMapper.kt
View file @
ec596a8e
...
...
@@ -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
)
}
}
src/test/resources/turtleOutput/missing-relation-name-value-in-list.ttl
0 → 100644
View file @
ec596a8e
@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"
.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment