Commit dff3db92 authored by Günter Hipler's avatar Günter Hipler
Browse files

more aggregations but only tests by now

parent c0e99e91
Pipeline #24110 passed with stages
in 7 minutes and 47 seconds
##Type EDM.scala
### todo (Aggregation_1)
......@@ -55,7 +55,7 @@ class EDM {
//actually only one instance - correct?
//val placeExtraction: ExtractionResult[Place] = createPlace(graph,record.get,digitalObject)
val aggregationExtraction: ExtractionResult[Aggregation] = createAggregation(graph,record.get,digitalObject)
val aggregationExtraction = createAggregation(graph,record.get,digitalObject)
//val conceptExtraction: ExtractionResult[Concept] = createConcept(graph,record.get,digitalObject)
//val timespanExtraction: ExtractionResult[TimeSpan] = createTimeSpan(graph,record.get,digitalObject)
......@@ -63,7 +63,9 @@ class EDM {
choExtraction.obj.getModel.addAll(webResource.getModel)
)
//choExtraction.obj.getModel.addAll(placeExtraction.obj.getModel)
choExtraction.obj.getModel.addAll(aggregationExtraction.obj.getModel)
aggregationExtraction.map(agg => choExtraction.obj.getModel.addAll(agg.obj.getModel))
//choExtraction.obj.getModel.addAll(aggregationExtraction.obj.getModel)
//choExtraction.obj.getModel.addAll(conceptExtraction.obj.getModel)
//choExtraction.obj.getModel.addAll(timespanExtraction.obj.getModel)
......@@ -183,7 +185,7 @@ class EDM {
val webresource: Option[WebResource] = Extractors.webResourceID(graph)(digitalObject).map(id =>
(new WebResource(s"https://media.memobase.ch/memo/${id}/master")))
WebResource(id))
if (webresource.isDefined) {
Extractors.usageRegulationDigitalObject(graph)(digitalObject.value)
......@@ -221,17 +223,28 @@ class EDM {
}
def createAggregation(graph: JArr, record: JObj, digitalObject: JObj): ExtractionResult[Aggregation] = {
def createAggregation(graph: JArr, record: JObj, digitalObject: JObj): Option[ExtractionResult[Aggregation]] = {
//how many places instances are available??
//is it correct to use recordId
//use apply method because we do not know how to build the identifier for Aggregations right now
val aggregation = Aggregation(Extractors.recordId(record).get)
//val aggregation = new Aggregation("http://iwerk.ch/4567")
aggregation.addSkosPrefLabel(Some("only test for aggregation"))
val recordIdShort = Extractors.recordIdShort(graph)(record)
if (recordIdShort.isDefined) {
val aggregation = Aggregation(recordIdShort.get)
Option(ExtractionResult(aggregation))
} else {
//todo (Aggregation_1): was passiert, wenn wir keine Aggregation bilden können? - Exception und der rico record wird nicht nach Europeana geliefert??
None
}
//val place: Option[List[WebResource]] = Extractors.recordId(record).map(id => List[Place](new Place(id)))
ExtractionResult(aggregation)
}
......
......@@ -100,7 +100,7 @@ class ProvidedCHO (val id: String) {
}
class WebResource (val id: String) {
class WebResource (private val id: String) {
private val model = Helper.getModelWithEDMNamespaces
private val factory = SimpleValueFactory.getInstance()
......@@ -122,32 +122,55 @@ class WebResource (val id: String) {
}
class Aggregation(val id: String) {
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 = Helper.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 getModel: Model = model
}
object Aggregation {
//todo: GH discussion with Silvia 11.3.2021
// we should use the Aggreagatuon subject already in the first prototype
// although at the moment we do not know how to create a unique identifier so
// so it is build a subject of it's own in the EDM document (so to say RDF graph for the
// document
def apply (id: String): Aggregation = new Aggregation(s"${id}_??")
def apply (shortID: String): Aggregation = new Aggregation(s"https://memobase.ch/object/${shortID}")
}
class Concept(val id: String) {
private val model = Helper.getModelWithEDMNamespaces
model.add(iri(id),RDF.TYPE, SKOS.CONCEPT)
......
......@@ -40,6 +40,9 @@ object EDMVocab extends VocabularyFactory("http://www.europeana.eu/schemas/edm/"
val TYPE: IRI = getIri("type")
val RIGHTS: IRI = getIri("rights")
val AGGREGATED_CHO:IRI = getIri("aggregatedCHO")
val IS_SHOWN_AT: IRI = getIri("isShownAt")
}
......
/*
* 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/>.
*
*/
package ch.memobase.rico2edm.edm
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.Aggregation
import org.eclipse.rdf4j.rio.Rio
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import ch.memobase.rico2edm.rdf.writer.{RdfXmlWriter => EDMRdfXmlWriter}
class AggregationSpec extends AnyFunSuite with Matchers {
private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
private lazy val rawCertainty = loadFile("src/test/resources/rico.certainty.json")
test ("id creation for Aggregation") {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val record = Extractors.record(graph).get
val shortRecordId = Extractors.recordIdShort(graph)(record)
assert(shortRecordId.isDefined && s"https://memobase.ch/object/${shortRecordId.get}" == "https://memobase.ch/object/ati-001-L_44_13")
}
test ("edm:aggregatedCHO") {
//entspricht id - identifier (keine http URI)
val graph = Extractors.jsonGraph(rawCertainty).get.arr
val record = Extractors.record(graph).get
val shortRecordId = Extractors.recordIdShort(graph)(record)
assert(shortRecordId.isDefined && shortRecordId.get == "lmz-001--597216")
}
test ("edm:isShownAt") {
//entspricht id - identifier (keine http URI)
val graph = Extractors.jsonGraph(rawCertainty).get.arr
val record = Extractors.record(graph).get
val shortRecordId = Extractors.recordIdShort(graph)(record)
assert(shortRecordId.isDefined && shortRecordId.get == "lmz-001--597216")
/*
val agg = Aggregation(shortRecordId.get)
agg.addIsShownAt(shortRecordId)
val rdfWriter = new EDMRdfXmlWriter(System.out)
Rio.write(agg.getModel, rdfWriter)
*/
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment