/* * 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 . * */ package ch.memobase.rico2edm.edm.subjects import ch.memobase.rico2edm.edm.EDMRdf4jModel import ch.memobase.rico2edm.rdf.vocabularies.{EDMVocab, OreVocab} import org.eclipse.rdf4j.model.Model import org.eclipse.rdf4j.model.impl.SimpleValueFactory import org.eclipse.rdf4j.model.util.Values.iri import org.eclipse.rdf4j.model.vocabulary.{DC, DCTERMS, RDF, SKOS} class ProvidedCHO (val id: String) { import org.eclipse.rdf4j.model.util.Values.iri //import org.eclipse.rdf4j.model.util.Values.literal private val model = EDMRdf4jModel.getModelWithEDMNamespaces model.add(iri(id),RDF.TYPE, EDMVocab.ProvidedCHO) 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))) def addCreator(creator:Option[String]): Unit = creator.map(t => model.add(iri(id),DC.CREATOR,factory.createLiteral(t))) def addContributor(contributor:Option[String]): Unit = contributor.map(t => model.add(iri(id),DC.CONTRIBUTOR,factory.createLiteral(t))) def addIdentifier(identifier:Option[String]): Unit = identifier.map(t => model.add(iri(id),DC.IDENTIFIER,factory.createLiteral(t))) 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))) def addDcTermsCreated(dctermsCreated:Option[String]): Unit = dctermsCreated.map(t => model.add(iri(id),DCTERMS.CREATED,factory.createLiteral(t))) def addDcTermsExtent(dctermsExtent:Option[String]): Unit = dctermsExtent.map(t => model.add(iri(id),DCTERMS.EXTENT,factory.createLiteral(t))) 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))) def addEdmType(edmtype:Option[String]): Unit = edmtype.map(t => model.add(iri(id),EDMVocab.TYPE,factory.createLiteral(t))) def getModel: Model = model } class WebResource (private val id: String) { private val model = EDMRdf4jModel.getModelWithEDMNamespaces private val factory = SimpleValueFactory.getInstance() 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))) model.add(iri(id),RDF.TYPE, EDMVocab.WebResource) def getModel: Model = model } object WebResource { def apply (shortID: String): WebResource = new WebResource(s"https://media.memobase.ch/memo/${shortID}/master") } class Aggregation(private val id: String) { private val model = EDMRdf4jModel.getModelWithEDMNamespaces model.add(iri(id),RDF.TYPE, OreVocab.AGGREGATION) private val identValue = "^https.*".r 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 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}")) } }) } def addIsShownBy(edmIsShownBy: Option[String]): Unit = { edmIsShownBy.map(a => { if (identValue.matches(edmIsShownBy.get)) { model.add(iri(id),EDMVocab.IS_SHOWN_BY,factory.createLiteral(a)) } else { model.add(iri(id),EDMVocab.IS_SHOWN_BY,factory.createLiteral( s"https://media.memobase.ch/memo/${a}/master")) } }) } def addEDMObjectFoto(edmObjectFoto: Option[String]): Unit = { edmObjectFoto.map(a => { if (identValue.matches(edmObjectFoto.get)) { model.add(iri(id),EDMVocab.OBJECT,factory.createLiteral(a)) } else { model.add(iri(id),EDMVocab.OBJECT,factory.createLiteral( s"https://media.memobase.ch/memo/${a}/master")) } }) } def addProvider(edmProvider: Option[String]): Unit = { edmProvider.map(a => model.add(iri(id),EDMVocab.PROVIDER,factory.createLiteral(a)) ) } def addEDMObjectNoFoto(edmObjectNoFoto: Option[String]): Unit = { edmObjectNoFoto.map(a => { if (identValue.matches(edmObjectNoFoto.get)) { model.add(iri(id),EDMVocab.OBJECT,factory.createLiteral(a)) } else { model.add(iri(id),EDMVocab.OBJECT,factory.createLiteral( s"https://media.memobase.ch/memo/${a}-poster")) } }) } def addRights(edmRights:Option[String]): Unit = edmRights.map(t => model.add(iri(id),EDMVocab.RIGHTS,factory.createLiteral(t))) def getModel: Model = model } object Aggregation { def apply (shortID: String): Aggregation = new Aggregation(s"https://memobase.ch/object/${shortID}") } class Concept(val id: String) { private val model = EDMRdf4jModel.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 = EDMRdf4jModel.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 = EDMRdf4jModel.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 }