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

more aggregation properties

parent 59b0e2db
Pipeline #24178 passed with stages
in 6 minutes and 57 seconds
......@@ -27,7 +27,7 @@ import ch.memobase.rico2edm.edm.subjects.{Aggregation, Concept, ModelXMLTransfor
import java.time.format.DateTimeFormatter
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Try
import scala.util.{Success, Try}
import ujson.{Arr => JArr, Obj => JObj}
......@@ -237,6 +237,28 @@ class EDM {
aggregation.addAggregatedCHO(recordIdShort)
//todo: ich denke, die Implementierung als Ganzes ist noch nicht konsistent
// haben wir immer ein digitales Objekt
// (behalten wir den Filter "hasNoDigitalObject" - Export auch von pur metadata über OAI),
// wenn nein (deswegen hier try) könnte man das aber
// noch konsistenter implementieren
//
Try { Extractors.digitalObjectIdShort(graph)(digitalObject) } match {
case Success(value) =>
aggregation.addIsShownBy(value)
Extractors.ricoType(record) match {
case Some(value) =>
if (value == "Foto") {
aggregation.addEDMObjectFoto(Option(value))
}else {
aggregation.addEDMObjectNoFoto(Option(value))
}
case None =>
}
case _ =>
}
Option(ExtractionResult(aggregation))
} else {
......
......@@ -620,6 +620,22 @@ object Extractors {
case res => stringValue(res)("identifier").getOrElse("")
}
val digitalObjectIdShort: JArr => JObj => Option[String] =
graph =>
digObj =>
getAllBlankNodeContent(graph)(digObj.obj)("identifiedBy")
.filter(obj =>
stringValue(obj)("type") match {
case Some(value) if value == "main" => true
case _ => false
}
).collectFirst {
//todo: a better default as ""
case res => stringValue(res)("identifier").getOrElse("")
}
val recordSource: JObj => Option[String] = record => stringValue(record)("source")
......
......@@ -158,6 +158,39 @@ class Aggregation(private val id: String) {
}
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 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 getModel: Model = model
......
......@@ -42,7 +42,8 @@ object EDMVocab extends VocabularyFactory("http://www.europeana.eu/schemas/edm/"
val RIGHTS: IRI = getIri("rights")
val AGGREGATED_CHO:IRI = getIri("aggregatedCHO")
val IS_SHOWN_AT: IRI = getIri("isShownAt")
val IS_SHOWN_BY: IRI = getIri("isShownBy")
val OBJECT: IRI = getIri("object")
}
......
......@@ -19,6 +19,10 @@
package ch.memobase
import org.eclipse.rdf4j.model.Model
import org.eclipse.rdf4j.rio.Rio
import ch.memobase.rico2edm.rdf.writer.{RdfXmlWriter => EDMRdfXmlWriter}
import java.io.StringWriter
import scala.io.Source
object Utils {
......@@ -28,4 +32,13 @@ object Utils {
source.close
string
}
def serializeRDFModel(model: Model): String = {
val sOut = new StringWriter
val rdfWriter = new EDMRdfXmlWriter(sOut)
Rio.write(model, rdfWriter)
sOut.toString
}
}
......@@ -20,18 +20,30 @@
package ch.memobase.rico2edm.edm
import ch.memobase.Utils
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}
import ujson.Value.Value
import scala.collection.mutable
import scala.util.Try
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")
private lazy val rawNoFoto = loadFile("src/test/resources/rico.duration.json")
private def testAggregation = {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val record = Extractors.record(graph).get
val shortRecordId = Extractors.recordIdShort(graph)(record)
Aggregation(shortRecordId.get)
}
test ("id creation for Aggregation") {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
......@@ -52,22 +64,65 @@ class AggregationSpec extends AnyFunSuite with Matchers {
test ("edm:isShownAt") {
//entspricht id - identifier (keine http URI)
//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)
*/
*/
}
test ("edm:isShownBy") {
val graph = Extractors.jsonGraph(rawCertainty).get.arr
val doObj = Extractors.digitalObject(graph).get
val shortDobjectId = Extractors.digitalObjectIdShort(graph)(doObj)
assert(shortDobjectId.isDefined && shortDobjectId.get == "lmz-001--597216-1")
}
private def createAgg(rawGraph: String): Aggregation = {
val graph = Extractors.jsonGraph(rawGraph).get.arr
val record = Extractors.record(graph).get
val doObj = Extractors.digitalObject(graph).get
val digiObjIdShort = Extractors.digitalObjectIdShort(graph)(doObj)
val tempTestAgg = testAggregation
Extractors.ricoType(record) match {
case Some(value) =>
if (value == "Foto") {
tempTestAgg.addEDMObjectFoto(digiObjIdShort)
}else {
tempTestAgg.addEDMObjectNoFoto(digiObjIdShort)
}
case None =>
}
tempTestAgg
}
test ("aggregation edm:object") {
val aggFoto = createAgg(rawCertainty)
assert(Utils.serializeRDFModel(aggFoto.getModel).contains(
s"<edm:object>https://media.memobase.ch/memo/lmz-001--597216-1/master</edm:object>"))
val aggNoFoto = createAgg(rawNoFoto)
assert(Utils.serializeRDFModel(aggNoFoto.getModel).contains(
s"<edm:object>https://media.memobase.ch/memo/raf-001-2893-1-poster</edm:object>"))
}
......
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