Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
🚀
This server has been upgraded to GitLab release
15.7
.
🚀
Open sidebar
memoriav
Memobase 2020
libraries
Normalizer Service Configuration
Commits
1c5890cc
Commit
1c5890cc
authored
Nov 17, 2020
by
Jonas Waeber
Browse files
Update tests for transforms.
parent
f8a40aa5
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/ch/memobase/helpers/KEYS.kt
View file @
1c5890cc
...
...
@@ -7,6 +7,8 @@ object KEYS {
const
val
firstToLast
=
"first-to-last"
const
val
lastToFirst
=
"last-to-first"
const
val
DUMMY_VALUE
=
"DUMMY-VALUE"
const
val
missingLabelDe
=
"FEHLENDES LABEL"
const
val
missingLabelFr
=
"L'ÉTIQUETTE MANQUANTE"
...
...
src/main/kotlin/ch/memobase/model/ExtractCreationRelationName.kt
View file @
1c5890cc
package
ch.memobase.model
import
org.memobase.exceptions.InvalidMappingException
import
ch.memobase.transform.ExtractCreationRelationTransform
import
ch.memobase.transform.ExtractCreationRelation
Name
Transform
data class
ExtractCreationRelationName
(
val
pattern
:
String
,
...
...
@@ -20,7 +20,7 @@ data class ExtractCreationRelationName(
}
}
fun
generate
():
ExtractCreationRelationTransform
{
return
ExtractCreationRelationTransform
(
Regex
(
pattern
),
if
(
language
==
"NONE"
)
""
else
language
)
fun
generate
():
ExtractCreationRelation
Name
Transform
{
return
ExtractCreationRelation
Name
Transform
(
Regex
(
pattern
),
if
(
language
==
"NONE"
)
""
else
language
)
}
}
src/main/kotlin/ch/memobase/transform/ExtractCreationRelationTransform.kt
→
src/main/kotlin/ch/memobase/transform/ExtractCreationRelation
Name
Transform.kt
View file @
1c5890cc
...
...
@@ -5,7 +5,7 @@ import ch.memobase.rdf.MemobaseModel
import
org.memobase.rdf.RICO
import
ch.memobase.rdf.RicoResource
class
ExtractCreationRelationTransform
(
private
val
regex
:
Regex
,
private
val
language
:
String
)
:
ITransformer
{
class
ExtractCreationRelation
Name
Transform
(
private
val
regex
:
Regex
,
private
val
language
:
String
)
:
ITransformer
{
private
val
log
=
LogManager
.
getLogger
(
"ExtractCreationRelationName"
)
override
fun
transform
(
item
:
RicoResource
,
model
:
MemobaseModel
):
List
<
String
>
{
...
...
@@ -57,7 +57,7 @@ class ExtractCreationRelationTransform(private val regex: Regex, private val lan
if
(
this
===
other
)
return
true
if
(
javaClass
!=
other
?.
javaClass
)
return
false
other
as
ExtractCreationRelationTransform
other
as
ExtractCreationRelation
Name
Transform
if
(
regex
.
pattern
!=
other
.
regex
.
pattern
)
return
false
if
(
language
!=
other
.
language
)
return
false
...
...
src/test/kotlin/TestExtractCreationRelationNameTransform.kt
0 → 100644
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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
import
ch.memobase.helpers.KEYS
import
ch.memobase.rdf.MemobaseModel
import
ch.memobase.transform.ExtractCreationRelationNameTransform
import
org.apache.jena.riot.RDFDataMgr
import
org.apache.jena.riot.RDFFormat
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
import
org.memobase.rdf.NS
import
org.memobase.rdf.RICO
import
java.io.FileOutputStream
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
internal
class
TestExtractCreationRelationNameTransform
{
@Test
fun
`test
extract
creation
relation
name
normalizer`
()
{
val
memobaseModel
=
MemobaseModel
()
NS
.
prefixMapping
.
map
{
memobaseModel
.
setNsPrefix
(
it
.
key
,
it
.
value
)
}
val
person
=
memobaseModel
.
createRicoResource
(
RICO
.
Person
)
.
addLiteral
(
RICO
.
name
,
"Markus Mäder (Autor)"
)
val
resource
=
memobaseModel
.
createRicoResource
(
RICO
.
CreationRelation
)
.
addLiteral
(
RICO
.
name
,
KEYS
.
DUMMY_VALUE
)
.
addProperty
(
RICO
.
creationRelationHasTarget
,
person
)
person
.
addProperty
(
RICO
.
agentIsTargetOfCreationRelation
,
resource
)
val
record
=
memobaseModel
.
createRicoResource
(
RICO
.
Record
)
.
addProperty
(
RICO
.
recordResourceOrInstantiationIsSourceOfCreationRelation
,
resource
)
resource
.
addProperty
(
RICO
.
creationRelationHasSource
,
record
)
val
n
=
ExtractCreationRelationNameTransform
(
Regex
(
"\\(?<relation>.+\\)"
),
"NONE"
)
val
output
=
n
.
transform
(
resource
,
memobaseModel
)
RDFDataMgr
.
write
(
FileOutputStream
(
"src/test/resources/tmp/turtle-output-extract-creation-relation-name.ttl"
),
memobaseModel
,
RDFFormat
.
TURTLE_PRETTY
)
assertAll
(
""
,
{
assertThat
(
output
).
isEmpty
()
},
{
assertThat
(
resource
).
satisfies
{
it
.
hasProperty
(
RICO
.
name
,
"Autor"
)
}.
satisfies
{
!
it
.
hasProperty
(
RICO
.
name
,
KEYS
.
DUMMY_VALUE
)
}
}
)
}
}
\ No newline at end of file
src/test/kotlin/TestGlobalTransformLoader.kt
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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/>.
*/
import
ch.memobase.configs.GlobalTransformsLoader
import
org.assertj.core.api.Assertions.assertThat
import
org.junit.jupiter.api.Test
...
...
src/test/kotlin/TestLanguageNormalizer.kt
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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
import
ch.memobase.model.NormalizeLanguages
...
...
src/test/kotlin/TestLocalTransformLoader.kt
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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/>.
*/
import
ch.memobase.configs.LocalTransformsLoader
import
org.assertj.core.api.Assertions.assertThat
import
org.junit.jupiter.api.Test
...
...
src/test/kotlin/TestPersonNormalizer.kt
0 → 100644
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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
import
ch.memobase.model.NormalizeLanguages
import
ch.memobase.rdf.MemobaseModel
import
ch.memobase.transform.PersonNormalizer
import
org.apache.jena.riot.RDFDataMgr
import
org.apache.jena.riot.RDFFormat
import
org.apache.jena.sparql.vocabulary.FOAF
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
import
org.memobase.rdf.NS
import
org.memobase.rdf.RDA
import
org.memobase.rdf.RICO
import
java.io.FileOutputStream
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
internal
class
TestPersonNormalizer
{
@Test
fun
`test
person
normalizer`
()
{
val
memobaseModel
=
MemobaseModel
()
NS
.
prefixMapping
.
map
{
memobaseModel
.
setNsPrefix
(
it
.
key
,
it
.
value
)
}
val
resource
=
memobaseModel
.
createRicoResource
(
RICO
.
Person
)
.
addLiteral
(
RICO
.
name
,
"Markus Mäder"
)
val
record
=
memobaseModel
.
createRicoResource
(
RICO
.
Record
)
.
addProperty
(
RDA
.
hasProducer
,
resource
)
val
n
=
PersonNormalizer
(
"first-to-last"
,
true
,
" "
)
val
output
=
n
.
transform
(
resource
,
memobaseModel
)
RDFDataMgr
.
write
(
FileOutputStream
(
"src/test/resources/tmp/turtle-output-person-normalization.ttl"
),
memobaseModel
,
RDFFormat
.
TURTLE_PRETTY
)
assertAll
(
""
,
{
assertThat
(
output
).
isEmpty
()
},
{
assertThat
(
resource
).
satisfies
{
it
.
hasProperty
(
FOAF
.
firstName
,
"Markus"
)
}.
satisfies
{
it
.
hasProperty
(
FOAF
.
familyName
,
"Mäder"
)
}
}
)
}
}
\ No newline at end of file
src/test/kotlin/TestRicoResources.kt
View file @
1c5890cc
/*
* normalization service
* Copyright (C) 2019 Memobase
*
* 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
import
ch.memobase.rdf.MemobaseModel
...
...
src/test/kotlin/TestTransformers.kt
View file @
1c5890cc
...
...
@@ -19,7 +19,7 @@ package org.memobase
import
ch.memobase.rdf.MemobaseModel
import
ch.memobase.rdf.RicoResource
import
ch.memobase.transform.ExtractCreationRelationTransform
import
ch.memobase.transform.ExtractCreationRelation
Name
Transform
import
ch.memobase.transform.PersonNormalizer
import
ch.memobase.transform.SplitEntityTransform
import
org.apache.jena.rdf.model.Statement
...
...
@@ -52,7 +52,7 @@ class TestTransformers {
@Test
fun
`test
creation
relation
name
extractor`
()
{
val
creationRelationTransform
=
ExtractCreationRelationTransform
(
Regex
(
"\\((?<relation>.*)\\)"
),
"fr"
)
val
creationRelationTransform
=
ExtractCreationRelation
Name
Transform
(
Regex
(
"\\((?<relation>.*)\\)"
),
"fr"
)
val
memobaseModel
=
MemobaseModel
()
val
person
=
...
...
src/test/resources/tmp/turtle-output-extract-creation-relation-name.ttl
0 → 100644
View file @
1c5890cc
@prefix
schema:
<http://schema.org/>
.
@prefix
internal:
<http://memobase.ch/internal/>
.
@prefix
mbrs:
<https://memobase.ch/recordSet/>
.
@prefix
owl:
<http://www.w3.org/2002/07/owl#>
.
@prefix
wdt:
<http://www.wikidata.org/prop/direct/>
.
@prefix
mbpo:
<https://memobase.ch/physical/>
.
@prefix
mbcb:
<https://memobase.ch/institution/>
.
@prefix
xsd:
<http://www.w3.org/2001/XMLSchema#>
.
@prefix
skos:
<http://www.w3.org/2004/02/skos/core#>
.
@prefix
rdfs:
<http://www.w3.org/2000/01/rdf-schema#>
.
@prefix
wd:
<http://www.wikidata.org/entity/>
.
@prefix
wdtn:
<http://www.wikidata.org/prop/direct-normalized/>
.
@prefix
mbdo:
<https://memobase.ch/digital/>
.
@prefix
rdau:
<http://rdaregistry.info/Elements/u/>
.
@prefix
fedora:
<http://fedora.info/definitions/v4/repository#>
.
@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
ldp:
<http://www.w3.org/ns/ldp#>
.
@prefix
dcterms:
<http://purl.org/dc/terms/>
.
@prefix
mbr:
<https://memobase.ch/record/>
.
@prefix
foaf:
<http://xmlns.com/foaf/0.1/>
.
@prefix
dc:
<http://purl.org/dc/elements/1.1/>
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
[
a
rico:
Record
;
rico:
recordResourceOrInstantiationIsSourceOfCreationRelation
_:
b0
]
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"Markus Mäder (Autor)"
]
.
src/test/resources/tmp/turtle-output-person-normalization.ttl
0 → 100644
View file @
1c5890cc
@prefix
schema:
<http://schema.org/>
.
@prefix
internal:
<http://memobase.ch/internal/>
.
@prefix
mbrs:
<https://memobase.ch/recordSet/>
.
@prefix
owl:
<http://www.w3.org/2002/07/owl#>
.
@prefix
wdt:
<http://www.wikidata.org/prop/direct/>
.
@prefix
mbpo:
<https://memobase.ch/physical/>
.
@prefix
mbcb:
<https://memobase.ch/institution/>
.
@prefix
xsd:
<http://www.w3.org/2001/XMLSchema#>
.
@prefix
skos:
<http://www.w3.org/2004/02/skos/core#>
.
@prefix
rdfs:
<http://www.w3.org/2000/01/rdf-schema#>
.
@prefix
wd:
<http://www.wikidata.org/entity/>
.
@prefix
wdtn:
<http://www.wikidata.org/prop/direct-normalized/>
.
@prefix
mbdo:
<https://memobase.ch/digital/>
.
@prefix
rdau:
<http://rdaregistry.info/Elements/u/>
.
@prefix
fedora:
<http://fedora.info/definitions/v4/repository#>
.
@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
ldp:
<http://www.w3.org/ns/ldp#>
.
@prefix
dcterms:
<http://purl.org/dc/terms/>
.
@prefix
mbr:
<https://memobase.ch/record/>
.
@prefix
foaf:
<http://xmlns.com/foaf/0.1/>
.
@prefix
dc:
<http://purl.org/dc/elements/1.1/>
.
_:
b0
a
rico:
CreationRelation
;
rico:
creationRelationHasSource
[
a
rico:
Record
;
rico:
recordResourceOrInstantiationIsSourceOfCreationRelation
_:
b0
]
;
rico:
creationRelationHasTarget
[
a
rico:
Person
;
rico:
agentIsTargetOfCreationRelation
_:
b0
;
rico:
name
"Markus Mäder (Autor)"
]
.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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