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

webresources as mapping defined by Silvia on 2021/03/31

parent ff554dfe
Pipeline #24087 passed with stages
in 7 minutes and 52 seconds
......@@ -21,6 +21,7 @@
package ch.memobase.rico2edm.edm
import ch.memobase.rico2edm.edm
import ch.memobase.rico2edm.edm.subjects.{Aggregation, Concept, ModelXMLTransformer, Place, ProvidedCHO, TimeSpan, WebResource}
import java.time.format.DateTimeFormatter
......@@ -173,11 +174,23 @@ class EDM {
}
def createWebResources(graph: JArr, record: JObj, digitalObject: JObj): ExtractionResult[List[WebResource]] = {
def createWebResources(graph: JArr, record: JObj, digitalObject: JObj): ExtractionResult[Option[WebResource]] = {
//how many digital objects are part of a document??
val webresource: Option[List[WebResource]] = Extractors.dobjectId(digitalObject).map(id => List[WebResource](new WebResource(id)))
ExtractionResult(webresource.getOrElse(List()) )
//actually I suppose only one web-resource because we have only one digital object
val webresource: Option[WebResource] = Extractors.webResourceID(graph)(digitalObject).map(id =>
(new WebResource(s"https://media.memobase.ch/memo/${id}/master")))
if (webresource.isDefined) {
Extractors.usageRegulationDigitalObject(graph)(digitalObject.value)
.foreach(c => webresource.get.addRights(Option(c)))
Extractors.mimeType(digitalObject).foreach(format => webresource.get.addDcFormat(Option(format)))
}
ExtractionResult(webresource)
}
def createPlace(graph: JArr, record: JObj, digitalObject: JObj): ExtractionResult[Place] = {
......
......@@ -321,7 +321,14 @@ object Extractors {
.flatMap(obj =>
stringValue(obj)("duration")
)
.map(v => v)
//.map(v => v)
val resourceDCTermsExtentDigitalObject
: mutable.LinkedHashMap[String, JValue] => Option[String] =
digitalObject =>
stringValue(digitalObject)("duration").flatMap(Some(_))
/*
......@@ -627,4 +634,14 @@ object Extractors {
getBlankNodeContent(graph)(record)("created").flatMap(v =>
stringValue(v)("normalizedDateValue")
)
val webResourceID: JArr => JObj => Option[String] =
graph =>
digiObj =>
getBlankNodeContent(graph)(digiObj.obj)("identifiedBy").flatMap(
prop => stringValue(prop)("identifier")
)
}
......@@ -24,8 +24,6 @@ import ch.memobase.rico2edm.rdf.writer.RdfXmlWriter
import ch.memobase.rico2edm.utils.Helper
import org.eclipse.rdf4j.model.Model
import org.eclipse.rdf4j.rio.Rio
import org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter
import java.io.StringWriter
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
......@@ -53,6 +51,8 @@ object ModelXMLTransformer {
//create whole ES structure and replace XML prolog
//what about OAI header - I think we can create it here and should relief the OAI server from this task
//println(sOut)
prologPattern.replaceFirstIn(ujson.Obj(
//is this the correct ID
"id" -> id,
......
......@@ -105,6 +105,15 @@ class WebResource (val id: String) {
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)
......
......@@ -39,6 +39,8 @@ object EDMVocab extends VocabularyFactory("http://www.europeana.eu/schemas/edm/"
val TYPE: IRI = getIri("type")
val RIGHTS: IRI = getIri("rights")
}
......
......@@ -34,13 +34,15 @@ class EDMSpec extends AnyFunSuite with Matchers {
private lazy val ricoWithContributors = loadFile("src/test/resources/raw.contributor.json")
private lazy val rawEdmRights = loadFile("src/test/resources/rico.certainty.json")
test ("complete EDM creation") {
val edm = new EDM
val edmCreationResult: Try[ExtractionResult[(String, String)]] = edm.create(ricoWithContributors)
val edmCreationResult: Try[ExtractionResult[(String, String)]] = edm.create(rawEdmRights)
assert(edmCreationResult.isSuccess)
edmCreationResult match {
......
......@@ -37,9 +37,12 @@ class ExtractorSpecWebResource extends AnyFunSuite with Matchers {
private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
private lazy val rawEdmRights = loadFile("src/test/resources/rico.certainty.json")
private lazy val graph = Extractors.jsonGraph(rawRico).get
private val rawDigiObjectWithDuration = loadFile("src/test/resources/rico.NoPhysicalObject.json")
private val rawDCFormat = loadFile("src/test/resources/rico.regulatedBy.json")
test ("get digital object") {
val dobject = Extractors.digitalObject(graph.arr)
......@@ -100,11 +103,43 @@ class ExtractorSpecWebResource extends AnyFunSuite with Matchers {
val dObj = Extractors.digitalObject(graphGet.arr)
val usage = Extractors.usageRegulationDigitalObject(graphGet.arr)(dObj.get)
println(usage)
//println(usage)
//List(http://rightsstatements.org/vocab/CNE/1.0/)
}
test ("dcterms:extend on digital object (in opposite to physical object of record) for webresource") {
val graph = Extractors.jsonGraph(rawDigiObjectWithDuration).get
val digiObj = Extractors.digitalObject(graph.arr).get
val duration = Extractors.resourceDCTermsExtentDigitalObject(digiObj)
assert(duration.get == "1696.026122")
}
test ("dc:format with hasMimeType") {
val graph = Extractors.jsonGraph(rawDCFormat).get.arr
val doB = Extractors.digitalObject(graph).get
val mimeType = Extractors.mimeType(doB)
assert(mimeType.isDefined && mimeType.get == "image/jpeg")
}
test ("create ID for webressource") {
val graph = Extractors.jsonGraph(rawRico)
val dobject = Extractors.digitalObject(graph.get.arr)
val webresourceId = Extractors.webResourceID(graph.get.arr)(dobject.get)
assert(webresourceId.isDefined)
val id = s"https://media.memobase.ch/memo/${webresourceId.get}/master"
assert (id == "https://media.memobase.ch/memo/ati-001-L_44_13-1/master")
}
}
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