TestLanguageNormalizer.kt 2.28 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * 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/>.
 */
Jonas Waeber's avatar
Jonas Waeber committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.memobase

import ch.memobase.model.NormalizeLanguages
import ch.memobase.rdf.MemobaseModel
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 TestLanguageNormalizer {
    @Test
    fun `test language normalizer`() {
        val memobaseModel = MemobaseModel()
        NS.prefixMapping.map {
            memobaseModel.setNsPrefix(it.key, it.value)
        }
        val language =
            memobaseModel.createRicoResource(RICO.Language)
                .addLiteral(RICO.name, "Deutsch")
                .addLiteral(RICO.type, "caption")

        val record = memobaseModel.createRicoResource(RICO.Record)
            .addProperty(RICO.hasLanguage, language)

        val n = NormalizeLanguages(
Jonas Waeber's avatar
Jonas Waeber committed
49
50
            "src/test/resources/global/facets/languages.csv",
            "src/test/resources/global/facets/language_labels.csv"
Jonas Waeber's avatar
Jonas Waeber committed
51
52
53
54
55
56
        )
        val transform = n.generate()
        val output = transform.transform(language, memobaseModel)
        RDFDataMgr.write(
            FileOutputStream("src/test/resources/tmp/turtle-output-language-normalization.ttl"),
            memobaseModel,
Jonas Waeber's avatar
Jonas Waeber committed
57
            RDFFormat.TURTLE
Jonas Waeber's avatar
Jonas Waeber committed
58
59
60
61
62
63
64
65
        )
        assertAll("",
            {
                assertThat(output).isEmpty()
            }
        )
    }
}