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

more facts / trying to get a better understanding

parent a17358e1
Pipeline #22817 passed with stages
in 6 minutes and 31 seconds
......@@ -80,6 +80,11 @@ class EDM {
cho.addDescription(Extractors.descriptiveNote(record))
cho.addCreationDate(Extractors.creationDate(graph)(record.obj))
Extractors
.resourceCreator(graph)(
record.value
).foreach(c => cho.addCreator(Some(c._2)))
ExtractionResult(cho)
}
......
/*
* IIIF Manifest Creator
* Copyright (C) 2020 Memobase
* Copyright (C) 2021 Memobase
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -126,7 +126,8 @@ object Extractors {
.flatMap(obj =>
getBlankNodeContent(graph)(obj)("creationRelationHasTarget")
.flatMap(v => stringValue(v)("name")) match {
case Some(name) => Some(obj("name").str, name)
case Some(name) =>
Some(obj.getOrElse("name", obj("type")).str, name)
case None => None
}
)
......@@ -171,17 +172,25 @@ object Extractors {
recordSet =>
getBlankNodeContent(graph)(recordSet)("heldBy")
.flatMap(v => v.get("P154").flatMap(vi => Some(vi.str))) */
val manifestId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/manifest"))
val digitalObjectId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id")
val dobjectId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(Some(_))
val recordId: JObj => Option[String] = record => stringValue(record)("@id").flatMap(Some(_))
val manifestId: JObj => Option[String] = digitalObject =>
digitalObjectId(digitalObject).flatMap(v => Some(s"$v/manifest"))
val sequenceId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/sequence/default"))
digitalObjectId(digitalObject).flatMap(v => Some(s"$v/sequence/default"))
val canvasId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/canvas/default"))
digitalObjectId(digitalObject).flatMap(v => Some(s"$v/canvas/default"))
// This is a slight concession to the fact that the locator is sent as invalid
// sftp link. The locator link can however be built easily from the digitalObject
// id, so we check only the existence of the locator property, but discard a potential
// value.
val imageResourceId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("locator")
val mimeType: JObj => Option[String] = digitalObject =>
......@@ -197,7 +206,4 @@ object Extractors {
getBlankNodeContent(graph)(record)("created").flatMap(v =>
stringValue(v)("normalizedDateValue")
)
val recordId: JObj => Option[String] = record => stringValue(record)("@id").flatMap(Some(_))
}
/*
* IIIF Manifest Creator
* Copyright (C) 2020 Memobase
*
* 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.edm.guenterold
import ujson.Value.{Value => JValue}
import ujson.{Arr => JArr, Obj => JObj, Str => JStr}
import scala.collection.mutable
import scala.util.Try
object Extractors {
val jsonGraph: String => Try[JValue] = jsonString =>
Try { ujson.read(jsonString).obj("@graph").arr }
private val fedoraResource =
(jsonGraph: JArr) =>
(resourceType: String) =>
Try {
jsonGraph.value.collectFirst {
case res
if (res.obj
.contains("type") && res.obj("type").str == resourceType) ||
(res.obj.contains("@type") && res
.obj("@type")
.str == resourceType) =>
res.obj.value
}.get
}
private val getBlankNodeContent = (graph: JArr) =>
(resource: mutable.LinkedHashMap[String, JValue]) =>
(property: String) =>
graph.value.collectFirst {
case res
if res.obj("@id") == resource.getOrElse(property, JStr("")) =>
res.obj.value
}
private val getBlankNodesContent = (graph: JArr) =>
(resource: mutable.LinkedHashMap[String, JValue]) =>
(property: String) =>
graph.value
.filter(res =>
res.obj("@id") == resource.getOrElse(property, JStr(""))
)
.map(_.obj.value)
val digitalObject: JArr => Try[mutable.LinkedHashMap[String, JValue]] = {
jsonGraph => fedoraResource(jsonGraph)("digitalObject")
}
val record: JArr => Try[mutable.LinkedHashMap[String, JValue]] = jsonGraph =>
fedoraResource(jsonGraph)(
"https://www.ica.org/standards/RiC/ontology#Record"
)
/*val recordSet: JArr => Try[mutable.LinkedHashMap[String, JValue]] =
jsonGraph => fedoraResource(jsonGraph)("recordSet")*/
private val stringValue = (jsonObj: JObj) =>
(valueKey: String) => jsonObj.value.get(valueKey).flatMap(v => v.strOpt)
private val numValue = (jsonObj: JObj) =>
(valueKey: String) =>
stringValue(jsonObj)(valueKey).flatMap(v => Some(v.toDouble))
private val arrayValues = (jsonObj: JObj) =>
(valueKey: String) =>
jsonObj.value.get(valueKey).flatMap(v => Some(v.arr.toList.map(_.str)))
val ricoType: JObj => Option[String] = record => stringValue(record)("type")
val title: JObj => Option[String] = record => stringValue(record)("title")
val descriptiveNote: JObj => Option[String] = record =>
stringValue(record)("descriptiveNote")
val scopeAndContent: JObj => Option[String] = record =>
stringValue(record)("scopeAndContent")
val publishedBy
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("publishedBy").flatMap(v =>
stringValue(v)("name")
)
val placeOfCapture
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("P60556").flatMap(v =>
stringValue(v)("name")
)
val spatial: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("spatial").flatMap(v =>
stringValue(v)("name")
)
val hasLanguage
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("hasLanguage").flatMap(v =>
stringValue(v)("name")
)
//noinspection ScalaStyle
val resourceCreator: JArr => mutable.LinkedHashMap[String, JValue] => List[
(String, String)
] =
graph =>
record =>
getBlankNodesContent(graph)(record)(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
)
.flatMap(obj =>
getBlankNodeContent(graph)(obj)("creationRelationHasTarget")
.flatMap(v => stringValue(v)("name")) match {
case Some(name) => Some(obj("name").str, name)
case None => None
}
)
.toList
val producer
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("P60441").flatMap(v =>
stringValue(v)("name")
)
val componentColor: JObj => Option[List[String]] = digitalObject =>
arrayValues(digitalObject)("componentColor")
val dctAbstract: JObj => Option[String] = record =>
stringValue(record)("abstract")
val mediaResourceDescription: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("mediaResourceDescription")
val conditionsOfUse: JObj => Option[String] = record =>
stringValue(record)("conditionsOfUse")
val regulatedByHolder
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
digitalObject =>
getBlankNodesContent(graph)(digitalObject)("regulatedBy")
.collectFirst {
case res if res.obj("type").str == "holder" =>
res.obj("name").str
}
val license: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
digitalObject =>
getBlankNodesContent(graph)(digitalObject)("regulatedBy")
.collectFirst {
case res if res.obj("type").str == "usage" =>
res.obj("name").str
}
/* val logo: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
recordSet =>
getBlankNodeContent(graph)(recordSet)("heldBy")
.flatMap(v => v.get("P154").flatMap(vi => Some(vi.str))) */
val manifestId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/manifest"))
val dobjectId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(Some(_))
val sequenceId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/sequence/default"))
val canvasId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id").flatMap(v => Some(s"$v/canvas/default"))
val imageResourceId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("locator")
val mimeType: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("hasMimeType")
val imageHeight: JObj => Option[Double] = digitalObject =>
numValue(digitalObject)("height")
val imageWidth: JObj => Option[Double] = digitalObject =>
numValue(digitalObject)("width")
val creationDate
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("created").flatMap(v =>
stringValue(v)("normalizedDateValue")
)
val recordId: JObj => Option[String] = record => stringValue(record)("@id").flatMap(Some(_))
}
......@@ -46,6 +46,16 @@ class ProvidedCHO (val id: String) {
def addCreationDate(createDate:Option[String]): Unit =
createDate.map(t => model.add(iri(id),DC.DATE,factory.createLiteral(t)))
def addCreator(contributor:Option[String]): Unit =
contributor.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 getModel: Model = model
}
......
This diff is collapsed.
{
"@graph": [
{
"@id": "_:b0",
"@type": "http://www.w3.org/2004/02/skos/core#Concept",
"prefLabel": "Minusio edif"
},
{
"@id": "_:b1",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"name": "Archivio di Stato del Cantone Ticino",
"regulates": "https://memobase.ch/record/ati-001-L_44_13",
"type": "holder"
},
{
"@id": "_:b10",
"@type": "https://www.ica.org/standards/RiC/ontology#DateRange",
"normalizedDateValue": "1930/1950"
},
{
"@id": "_:b11",
"@type": "http://www.w3.org/2004/02/skos/core#Concept",
"prefLabel": "Locarnese edif"
},
{
"@id": "_:b12",
"@type": "https://www.ica.org/standards/RiC/ontology#Language",
"name": "Italian",
"type": "content"
},
{
"@id": "_:b13",
"@type": "https://www.ica.org/standards/RiC/ontology#Mechanism",
"name": "LanguagesNormalizer",
"performs": "_:b14"
},
{
"@id": "_:b14",
"@type": "https://www.ica.org/standards/RiC/ontology#Activity",
"affects": "_:b12",
"beginningDate": "2021-45-26T09:45:39+0000",
"endDate": "2021-45-26T09:45:39+0000",
"performedBy": "_:b13",
"resultsIn": "_:b5",
"type": "enrichment"
},
{
"@id": "_:b15",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"name": "public",
"regulates": "https://memobase.ch/digital/ati-001-L_44_13-1",
"type": "access"
},
{
"@id": "_:b16",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "ati-001-L_44_13-1",
"type": "main"
},
{
"@id": "_:b1777",
"@type": "https://www.ica.org/standards/RiC/ontology#Person",
"firstName": "Valentino",
"lastName": "Monotti",
"agentIsTargetOfCreationRelation": "_:b8",
"name": "Valentino Monotti"
},
{
"@id": "_:b18",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"name": "onsite",
"regulates": "https://memobase.ch/physical/ati-001-L_44_13-1",
"type": "access"
},
{
"@id": "_:b19",
"@type": "https://www.ica.org/standards/RiC/ontology#CarrierType",
"name": "Nitrato"
},
{
"@id": "_:b2",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "L/44.13",
"type": "original"
},
{
"@id": "_:b20",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "L/44.13",
"type": "callNumber"
},
{
"@id": "_:b21",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"sameAs": "http://rightsstatements.org/vocab/CNE/1.0/",
"name": "Copyright Not Evaluated (CNE)",
"regulates": "https://memobase.ch/physical/ati-001-L_44_13-1",
"type": "usage"
},
{
"@id": "_:b22",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "ati-001-L_44_13-1",
"type": "main"
},
{
"@id": "_:b23",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"sameAs": "http://rightsstatements.org/vocab/CNE/1.0/",
"name": "Copyright Not Evaluated (CNE)",
"regulates": "https://memobase.ch/digital/ati-001-L_44_13-1",
"type": "usage"
},
{
"@id": "_:b3",
"@type": "https://www.ica.org/standards/RiC/ontology#Place",
"name": "Minusio"
},
{
"@id": "_:b4",
"@type": "http://www.w3.org/2004/02/skos/core#Concept",
"prefLabel": "Edifici, piazze, strade, monumenti"
},
{
"@id": "_:b5",
"@type": "https://www.ica.org/standards/RiC/ontology#Language",
"sameAs": "http://www.wikidata.org/entity/Q652",
"name": [
{
"@language": "de",
"@value": "Italienisch"
},
{
"@language": "fr",
"@value": "italien"
},
{
"@language": "it",
"@value": "italiano"
}
],
"resultsFrom": "_:b14",
"type": "content"
},
{
"@id": "_:b6",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "ASTi-L_44_13",
"type": "oldMemobase"
},
{
"@id": "_:b7",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "ati-001-L_44_13",
"type": "main"
},
{
"@id": "_:b8",
"@type": "https://www.ica.org/standards/RiC/ontology#CreationRelation",
"creationRelationHasSource": "https://memobase.ch/record/ati-001-L_44_13",
"creationRelationHasTarget": "_:b17",
"type": "creator"
},
{
"@id": "_:b9",
"@type": "https://www.ica.org/standards/RiC/ontology#Title",
"title": "Hotel Esplanade",
"type": "main"
},
{
"@id": "https://memobase.ch/digital/ati-001-L_44_13-1",
"@type": "https://www.ica.org/standards/RiC/ontology#Instantiation",
"identifiedBy": "_:b22",
"instantiates": "https://memobase.ch/record/ati-001-L_44_13",
"isDerivedFromInstantiation": "https://memobase.ch/physical/ati-001-L_44_13-1",
"regulatedBy": [
"_:b15",
"_:b23"
],
"type": "digitalObject"
},
{
"@id": "https://memobase.ch/physical/ati-001-L_44_13-1",
"@type": "https://www.ica.org/standards/RiC/ontology#Instantiation",
"P60558": "B/N",
"eventType": "CREATE",
"hasCarrierType": "_:b19",
"hasDerivedInstantiation": "https://memobase.ch/digital/ati-001-L_44_13-1",
"identifiedBy": [
"_:b20",
"_:b16"
],
"instantiates": "https://memobase.ch/record/ati-001-L_44_13",
"physicalCharacteristics": [
"Bemerkung: Pellicola",
"Verfahren: Negativo",
"Höhe: 13 cm",
"Weite: 18 cm"
],
"regulatedBy": [
"_:b18",
"_:b21"
],
"type": "physicalObject"
},
{
"@id": "https://memobase.ch/record/ati-001-L_44_13",
"@type": "https://www.ica.org/standards/RiC/ontology#Record",
"abstract": "Veduta dell'albergo",
"created": "_:b10",
"spatial": "_:b3",
"P60451": "https://memobase.ch/institution/mrv",
"sameAs": "http://www3.ti.ch/DECS/sw/struttura/decs/dcsu/ac/asti/cff/index.php?p=immagine&id_immagine=17666",
"eventType": "CREATE",
"isPublished": false,
"conditionsOfUse": "Si veda il regolamento per la consultazione e la riproduzione di immagini fotografiche",
"hasInstantiation": [
"https://memobase.ch/digital/ati-001-L_44_13-1",
"https://memobase.ch/physical/ati-001-L_44_13-1"
],
"hasLanguage": [
"_:b5",
"_:b12"
],
"hasSubject": [
"_:b4",
"_:b0",
"_:b11"
],
"hasTitle": "_:b9",
"heldBy": "https://memobase.ch/institution/ati",
"identifiedBy": [
"_:b2",
"_:b6",
"_:b7"
],
"isPartOf": "https://memobase.ch/recordSet/ati-001",
"recordResourceOrInstantiationIsSourceOfCreationRelation": "_:b8",
"regulatedBy": "_:b1",
"scopeAndContent": "Discreto",
"source": "Monotti_L_44.13.jpg",
"title": "Hotel Esplanade",
"type": "Foto"
}
],
"@context": {
"prefLabel": {"@id": "http://www.w3.org/2004/02/skos/core#prefLabel"},
"regulatedBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#regulatedBy",
"@type": "@id"
},
"identifiedBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#identifiedBy",
"@type": "@id"
},
"source": {"@id": "https://www.ica.org/standards/RiC/ontology#source"},
"spatial": {
"@id": "http://purl.org/dc/terms/spatial",
"@type": "@id"
},
"scopeAndContent": {"@id": "https://www.ica.org/standards/RiC/ontology#scopeAndContent"},
"abstract": {"@id": "http://purl.org/dc/terms/abstract"},
"heldBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#heldBy",
"@type": "@id"
},
"hasSubject": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasSubject",
"@type": "@id"
},
"hasLanguage": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasLanguage",
"@type": "@id"
},
"isPublished": {
"@id": "https://memobase.ch/internal/isPublished",
"@type": "http://www.w3.org/2001/XMLSchema#boolean"
},
"hasInstantiation": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasInstantiation",
"@type": "@id"
},
"recordResourceOrInstantiationIsSourceOfCreationRelation": {