LocalTestRun.kt 4.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Normalization Service Configuration
 * Copyright (C) 2020 Memoriav
 *
 * 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.test

import ch.memobase.configs.GlobalTransformsLoader
import ch.memobase.configs.LocalTransformsLoader
import ch.memobase.rdf.MemobaseModel
import ch.memobase.settings.HeaderMetadata
import java.io.File
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Disabled
class LocalTestRun {

    private val headerMetadata = HeaderMetadata(
Jonas Waeber's avatar
Jonas Waeber committed
36
        "soz-007",
37
        "1",
Jonas Waeber's avatar
Jonas Waeber committed
38
        "soz",
39
40
41
42
43
44
45
46
47
        false,
        "record",
        "identifierMain",
        0, 0, 0, 0
    )

    @Test
    @Disabled
    fun `test a single file`() {
Jonas Waeber's avatar
Jonas Waeber committed
48
49
50
51
52
53
54
55
56
57
58
59
60
        val folder = "src/test/resources/single-item/"
        val mappingFile = "localTransform.yml"
        val global = GlobalTransformsLoader("src/test/resources/global/transforms.yml")
        global.parse()
        val local = LocalTransformsLoader(File(folder + mappingFile).readBytes())
        local.parse("test-key")
        val transformConfigs = local.get() + global.get()
        File(folder + "test-item.nt")
            .let { Pair(it.name, it) }
            .let {
                val model = MemobaseModel()
                RDFDataMgr.read(model, it.second.inputStream(), Lang.NTRIPLES)
                Pair(it.first, model)
61
            }
Jonas Waeber's avatar
Jonas Waeber committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
            .let {
                for (transformConfig in transformConfigs) {
                    val listOfResources = it.second.listRicoResourceSubjects().toList()
                    for (resource in listOfResources) {
                        transformConfig.transform(resource, it.second)
                    }
                }
                Pair(it.first, it.second)
            }
            .let { result ->
                RDFDataMgr.write(
                    File(folder + "output.nt").outputStream(),
                    result.second,
                    Lang.TURTLE
                )
77
78
79
            }

    }
Jonas Waeber's avatar
Jonas Waeber committed
80

81
82
83
    @Test
    @Disabled
    fun `test local folder`() {
Jonas Waeber's avatar
Jonas Waeber committed
84
85
86
        val folder = "/home/jonas/memobase/data/soz-007"
        val inputFolder = "/home/jonas/memobase/data/test-soz/step-3"
        val outputFolder = "/home/jonas/memobase/data/test-soz/step-4"
87
88
        val mappingFile = "/config/localTransforms.yml"
        val global = GlobalTransformsLoader("src/test/resources/global/transforms.yml")
Jonas Waeber's avatar
Jonas Waeber committed
89
        global.parse()
90
        val local = LocalTransformsLoader(File(folder + mappingFile).readBytes())
91
        local.parse("test-key")
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        val transformConfigs = local.get() + global.get()
        File(inputFolder)
            .walk(FileWalkDirection.TOP_DOWN)
            .maxDepth(1)
            .filter { it.isFile }
            .map { Pair(it.name, it) }
            .map {
                val model = MemobaseModel()
                RDFDataMgr.read(model, it.second.inputStream(), Lang.NTRIPLES)
                Pair(it.first, model)
            }
            .map {
                for (transformConfig in transformConfigs) {
                    val listOfResources = it.second.listRicoResourceSubjects().toList()
                    for (resource in listOfResources) {
                        transformConfig.transform(resource, it.second)
                    }
                }
                Pair(it.first, it.second)
            }
            .forEach { result ->
                RDFDataMgr.write(
                    File(outputFolder + "/" + result.first.substringAfterLast("/")).outputStream(),
                    result.second,
                    Lang.TURTLE
                )
            }
    }
}