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

Update tests for transforms.

parent f8a40aa5
......@@ -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"
......
package ch.memobase.model
import org.memobase.exceptions.InvalidMappingException
import ch.memobase.transform.ExtractCreationRelationTransform
import ch.memobase.transform.ExtractCreationRelationNameTransform
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(): ExtractCreationRelationNameTransform {
return ExtractCreationRelationNameTransform(Regex(pattern), if (language == "NONE") "" else language)
}
}
......@@ -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 ExtractCreationRelationNameTransform(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 ExtractCreationRelationNameTransform
if (regex.pattern != other.regex.pattern) return false
if (language != other.language) return false
......
/*
* 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
/*
* 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
......
/*
* 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
......
/*
* 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
......
/*
* 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
/*
* 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
......
......@@ -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.ExtractCreationRelationNameTransform
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 = ExtractCreationRelationNameTransform(Regex("\\((?<relation>.*)\\)"), "fr")
val memobaseModel = MemobaseModel()
val person =
......
@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)"
] .
@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)"
] .
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