ExtractorSpec.scala 3.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * rico2edm
 * Copyright (C) 2021  UB Basel
 *
 * 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/>.
 *
 */


21
package ch.memobase.rico2edm.edm
22

23
import ch.memobase.Utils
24
import ch.memobase.Utils.loadFile
25
26
import ch.memobase.rico2edm.edm.subjects.ProvidedCHO
import ch.memobase.rico2edm.rdf.writer.RdfXmlWriter
27
import org.eclipse.rdf4j.rio.Rio
28
import org.scalatest.funsuite.AnyFunSuite
29
import org.scalatest.matchers.should.Matchers
30

31
32
33
34
35
class ExtractorSpec extends AnyFunSuite with Matchers{
  private lazy val rawRico = loadFile("src/test/resources/raw1L.json")
  private lazy val rawErroneousFile = loadFile("src/test/resources/raw1LError.json")
  private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")

36
  private lazy val ricoContributors = loadFile("src/test/resources/raw.contributor.json")
37
38
39

  test ("read graph with Extractor") {
    assert(Extractors.jsonGraph(rawRico).isSuccess)
40
41
  }

42
43
44
45
46
47
48
49
50
51
52
  test ("read not valid graph which should throw an Error") {
    assert(Extractors.jsonGraph(rawErroneousFile).isFailure)
  }


  test ("read RecordId from file with indentations") {
    val record = Extractors.record(Extractors.jsonGraph(rawRicoIndent).get.arr).get.obj
    assert(Extractors.recordId(record).get == "https://memobase.ch/record/ati-001-L_44_13")
  }

  test ("create cultural heritage object (CHO") {
53
    val graph = Extractors.jsonGraph(ricoContributors).get.arr
54
55
56
57
58
59
60
61
62
63
64
65
    val record = Extractors.record(graph).get.obj
    val cho = new ProvidedCHO(Extractors.recordId(record).get)
    cho.addTitel(Extractors.title(record))
    cho.addDescription(Extractors.dctAbstract(record))
    cho.addDescription(Extractors.scopeAndContent(record))
    cho.addDescription(Extractors.descriptiveNote(record))

    /*
    todo wir können präziser dcterms:temporal, dcterms:created and dcterms:issued verwenden
     temporal und issued nutzt Sebastian in IIIF nicht
     ich habe das im Beispielrecord auch noch nicht gesehen - gibt es das?
     */
Silvia Witzig's avatar
Silvia Witzig committed
66
    // cho.addCreationDate(Extractors.creationDate(graph)(record))
67

68
69
    Extractors
      .resourceSourceOfRelationCreation(graph)(record.value)("creator")
70
      .foreach(c => cho.addCreator(Some(c)))
71

72
73
    Extractors
      .resourceSourceOfRelationCreation(graph)(record.value)("contributor")
74
      .foreach(c => cho.addContributor(Some(c)))
75
76
77
78

    Extractors
      .identifiedBy(graph)(record.value)
      .foreach(c => cho.addIdentifier(Some(c)))
79

80
    assert(Utils.serializeRDFModel(cho.getModel).contains("""<dc:identifier>rts-002-FNB023_1639_023</dc:identifier>"""))
81
82
83
84

  }


85
86
87
88
89
90
91


  test ("read raw rico from @graph") {

    val graph = Extractors.jsonGraph(rawRico).get.arr
    val digitalObject = Extractors.digitalObject(graph).get
    val record = Extractors.record(graph).get
92
93
    val imageResourceId = Extractors.imageResourceId(digitalObject)
    val recId = Extractors.recordId(record)
94
    val cho = new ProvidedCHO(Extractors.recordId(record).get)
95
96


97
    assert(Utils.serializeRDFModel(cho.getModel).contains("""<edm:ProvidedCHO rdf:about="https://memobase.ch/record/ati-001-L_44_13">"""))
98
99
100
101
102
103

  }



}