ProvidedCHO.scala 6.93 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.subjects
22

23
24
import ch.memobase.rico2edm.rdf.Helper
import ch.memobase.rico2edm.rdf.vocabularies.{EDMVocab, OreVocab}
25
26
27
import org.eclipse.rdf4j.model.Model
import org.eclipse.rdf4j.model.impl.SimpleValueFactory
import org.eclipse.rdf4j.model.util.Values.iri
28
import org.eclipse.rdf4j.model.vocabulary.{DC, DCTERMS, RDF, SKOS}
29
30
31
32
33
34

class ProvidedCHO (val id: String)  {

  import org.eclipse.rdf4j.model.util.Values.iri
  //import org.eclipse.rdf4j.model.util.Values.literal
  private val model = Helper.getModelWithEDMNamespaces
35
  model.add(iri(id),RDF.TYPE, EDMVocab.ProvidedCHO)
36
37
38
39
40
41
42
43
44
45
46
47
48

  private val factory = SimpleValueFactory.getInstance()

  def addDescription(desc: Option[String]): Unit =
    desc.map(t => model.add(iri(id),DC.DESCRIPTION,factory.createLiteral(t)))

  def addTitel(title: Option[String]): Unit = {
    title.map(t => model.add(iri(id),DC.TITLE,factory.createLiteral(t)))
  }

  def addCreationDate(createDate:Option[String]): Unit =
    createDate.map(t => model.add(iri(id),DC.DATE,factory.createLiteral(t)))

49
50
  def addCreator(creator:Option[String]): Unit =
    creator.map(t => model.add(iri(id),DC.CREATOR,factory.createLiteral(t)))
51
52
53
54
55


  def addContributor(contributor:Option[String]): Unit =
    contributor.map(t => model.add(iri(id),DC.CONTRIBUTOR,factory.createLiteral(t)))

56
57
  def addIdentifier(identifier:Option[String]): Unit =
    identifier.map(t => model.add(iri(id),DC.IDENTIFIER,factory.createLiteral(t)))
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  def addLanguage(language:Option[String]): Unit =
    language.map(t => model.add(iri(id),DC.LANGUAGE,factory.createLiteral(t)))

  def addPublisher(publisher:Option[String]): Unit =
    publisher.map(t => model.add(iri(id),DC.PUBLISHER,factory.createLiteral(t)))

  def addRights(rights:Option[String]): Unit =
    rights.map(t => model.add(iri(id),DC.RIGHTS,factory.createLiteral(t)))

  def addSource(source:Option[String]): Unit =
    source.map(t => model.add(iri(id),DC.SOURCE,factory.createLiteral(t)))

  def addSubject(subject:Option[String]): Unit =
    subject.map(t => model.add(iri(id),DC.SUBJECT,factory.createLiteral(t)))

  def addGenre(genre:Option[String]): Unit =
    genre.map(t => model.add(iri(id),DC.TYPE,factory.createLiteral(t)))
76

77
78
79
  def addDcTermsCreated(dctermsCreated:Option[String]): Unit =
    dctermsCreated.map(t => model.add(iri(id),DCTERMS.CREATED,factory.createLiteral(t)))

80
81
  def addDcTermsExtent(dctermsExtent:Option[String]): Unit =
    dctermsExtent.map(t => model.add(iri(id),DCTERMS.EXTENT,factory.createLiteral(t)))
82

83
84
85
86
87
88
89
90
91
92
93
  def addDcTermsIssued(dctermsIssued:Option[String]): Unit =
    dctermsIssued.map(t => model.add(iri(id),DCTERMS.ISSUED,factory.createLiteral(t)))

  def addDcTermsMedium(medium:Option[String]): Unit =
    medium.map(t => model.add(iri(id),DCTERMS.MEDIUM,factory.createLiteral(t)))

  def addDcTermsSpatial(spatial:Option[String]): Unit =
    spatial.map(t => model.add(iri(id),DCTERMS.SPATIAL,factory.createLiteral(t)))

  def addDcTermsTemporal(temporal:Option[String]): Unit =
    temporal.map(t => model.add(iri(id),DCTERMS.TEMPORAL,factory.createLiteral(t)))
94

95
96
97
98
  def addEdmType(edmtype:Option[String]): Unit =
    edmtype.map(t => model.add(iri(id),EDMVocab.TYPE,factory.createLiteral(t)))


99
100
101
102
  def getModel: Model = model

}

103
class WebResource (private val id: String) {
104
  private val model = Helper.getModelWithEDMNamespaces
105
106
107
  private val factory = SimpleValueFactory.getInstance()


108
109
110
111
112
113
114
115
116
  def addRights(edmRights:Option[String]): Unit =
    edmRights.map(t => model.add(iri(id),EDMVocab.RIGHTS,factory.createLiteral(t)))

  def addDcTermsExtent(dctermsExtent:Option[String]): Unit =
    dctermsExtent.map(t => model.add(iri(id),DCTERMS.EXTENT,factory.createLiteral(t)))

  def addDcFormat(dcFormat:Option[String]): Unit =
    dcFormat.map(t => model.add(iri(id),DC.FORMAT,factory.createLiteral(t)))

117
118
119
120
121
122
123
124

  model.add(iri(id),RDF.TYPE, EDMVocab.WebResource)

  def getModel: Model = model

}


125
126
127
128
129
130
131
132
133
object WebResource {

  def apply (shortID: String): WebResource =
    new WebResource(s"https://media.memobase.ch/memo/${shortID}/master")

}


class Aggregation(private val id: String) {
134
135
136
  private val model = Helper.getModelWithEDMNamespaces
  model.add(iri(id),RDF.TYPE, OreVocab.AGGREGATION)

137
138
  private val identValue = "^https.*".r

139
140
141
142
  private val factory = SimpleValueFactory.getInstance()

  def addSkosPrefLabel(skospreflabel:Option[String]): Unit =
    skospreflabel.map(t => model.add(iri(id),SKOS.PREF_LABEL,factory.createLiteral(t)))
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  def addAggregatedCHO(edmAggregatedCHO: Option[String]): Unit = {
    edmAggregatedCHO.map(a => model.add(iri(id),EDMVocab.AGGREGATED_CHO,factory.createLiteral(a)))
  }

  def addIsShownAt(edmIsShownAt: Option[String]): Unit = {
    edmIsShownAt.map(a => {
      if (identValue.matches(edmIsShownAt.get)) {
        model.add(iri(id),EDMVocab.IS_SHOWN_AT,factory.createLiteral(a))
      } else {
        model.add(iri(id),EDMVocab.IS_SHOWN_AT,factory.createLiteral(
          s"https://memobase.ch/object/${a}"))

      }
    })
  }



162
163
164
165
  def getModel: Model = model

}

166

167
168
object Aggregation {

169
  def apply (shortID: String): Aggregation = new Aggregation(s"https://memobase.ch/object/${shortID}")
170
171
172

}

173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
class Concept(val id: String) {
  private val model = Helper.getModelWithEDMNamespaces
  model.add(iri(id),RDF.TYPE, SKOS.CONCEPT)

  private val factory = SimpleValueFactory.getInstance()

  def addSkosPrefLabel(skospreflabel:Option[String]): Unit =
    skospreflabel.map(t => model.add(iri(id),SKOS.PREF_LABEL,factory.createLiteral(t)))

  def getModel: Model = model

}


class TimeSpan(val id: String) {

  //not used so far in Silvia mapping
  private val model = Helper.getModelWithEDMNamespaces
  model.add(iri(id),RDF.TYPE, EDMVocab.TIMESPAN)
  private val factory = SimpleValueFactory.getInstance()

  def addSkosPrefLabel(skospreflabel:Option[String]): Unit =
    skospreflabel.map(t => model.add(iri(id),SKOS.PREF_LABEL,factory.createLiteral(t)))

  def getModel: Model = model

}

class Place(val id: String) {

  //not used so far in Silvia mapping
  private val model = Helper.getModelWithEDMNamespaces
  model.add(iri(id),RDF.TYPE, EDMVocab.PLACE)
  private val factory = SimpleValueFactory.getInstance()

  def addSkosPrefLabel(skospreflabel:Option[String]): Unit =
    skospreflabel.map(t => model.add(iri(id),SKOS.PREF_LABEL,factory.createLiteral(t)))

  def getModel: Model = model

}