Verified Commit af4e93d8 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

fix license extractor

parent d07bb699
Pipeline #44601 passed with stages
in 5 minutes and 49 seconds
......@@ -26,7 +26,9 @@ import scala.util.Try
object Extractors {
val jsonGraph: String => Try[JValue] = jsonString =>
Try { ujson.read(jsonString).obj("@graph").arr }
Try {
ujson.read(jsonString).obj("@graph").arr
}
private val fedoraResource =
(jsonGraph: JArr) =>
......@@ -34,11 +36,11 @@ object Extractors {
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) =>
if (res.obj
.contains("type") && res.obj("type").str == resourceType) ||
(res.obj.contains("@type") && res
.obj("@type")
.str == resourceType) =>
res.obj.value
}.get
}
......@@ -47,17 +49,19 @@ object Extractors {
(resource: mutable.LinkedHashMap[String, JValue]) =>
(property: String) =>
graph.value.collectFirst {
case res
if res.obj("@id") == resource.getOrElse(property, JStr("")) =>
res.obj.value
case res if resource.contains(property) && resource(property).strOpt.isDefined && res.obj("@id") == resource(property) => res.obj.value
case res if resource.contains(property) && resource(property).arrOpt.isDefined && resource(property).arr.contains(res.obj("@id")) => 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(""))
.filter(res => resource.get(property) match {
case Some(JArr(v)) => v.toList.contains(res.obj("@id"))
case Some(str@JStr(_)) => res.obj("@id") == str
case None => false
}
)
.map(_.obj.value)
......@@ -87,14 +91,14 @@ object Extractors {
val scopeAndContent: JObj => Option[String] = record =>
stringValue(record)("scopeAndContent")
val publishedBy
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
: 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] =
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("P60556").flatMap(v =>
......@@ -107,7 +111,7 @@ object Extractors {
stringValue(v)("name")
)
val hasLanguage
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("hasLanguage").flatMap(v =>
......@@ -134,7 +138,7 @@ object Extractors {
.toList
val producer
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodeContent(graph)(record)("P60441").flatMap(v =>
......@@ -151,7 +155,7 @@ object Extractors {
val conditionsOfUse: JObj => Option[String] = record =>
stringValue(record)("conditionsOfUse")
val regulatedByHolder
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
digitalObject =>
getBlankNodesContent(graph)(digitalObject)("regulatedBy")
......@@ -165,7 +169,7 @@ object Extractors {
getBlankNodesContent(graph)(digitalObject)("regulatedBy")
.collectFirst {
case res if res.obj("type").str == "usage" =>
res.obj("name").str
res.obj("sameAs").str
}
/* val logo: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
......@@ -173,7 +177,7 @@ object Extractors {
getBlankNodeContent(graph)(recordSet)("heldBy")
.flatMap(v => v.get("P154").flatMap(vi => Some(vi.str))) */
val digitalObjectId: JObj => Option[String] = digitalObject =>
stringValue(digitalObject)("@id")
stringValue(digitalObject)("@id")
val manifestId: JObj => Option[String] = digitalObject =>
digitalObjectId(digitalObject).flatMap(v => Some(s"$v/manifest"))
val sequenceId: JObj => Option[String] = digitalObject =>
......@@ -193,7 +197,7 @@ object Extractors {
val imageWidth: JObj => Option[Double] = digitalObject =>
numValue(digitalObject)("width")
val creationDate
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
digitalObject =>
getBlankNodeContent(graph)(digitalObject)("created").flatMap(v =>
......
{
"@graph": [
{
"@id": "_:b0",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"name": "Burgerbibliothek Bern",
"regulates": "https://memobase.ch/record/bbb-001-208499",
"type": "holder"
},
{
"@id": "_:b1",
"@type": "https://www.ica.org/standards/RiC/ontology#CarrierType",
"sameAs": "http://www.wikidata.org/entity/Q1138868",
"name": [
{
"@language": "de",
"@value": "Fotoplatte"
},
{
"@language": "fr",
"@value": "plaque photographique"
},
{
"@language": "it",
"@value": "lastra fotografica"
}
],
"resultsFrom": "_:b2"
},
{
"@id": "_:b10",
"@type": "https://www.ica.org/standards/RiC/ontology#DateRange",
"expressedDate": "s. d. (sine dato)"
},
{
"@id": "_:b11",
"@type": "https://www.ica.org/standards/RiC/ontology#Place",
"name": "Stockhorn Vorderälpital"
},
{
"@id": "_:b12",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "bbb-001-208499",
"type": "main"
},
{
"@id": "_:b13",
"@type": "https://www.ica.org/standards/RiC/ontology#Title",
"title": "Oberstocken; Vorderälpital; Stockhorn -- Alphütte; Landwirtschaft; Ziege; Tierdarstellung; Haustier",
"type": "main"
},
{
"@id": "_:b14",
"@type": "http://www.w3.org/2004/02/skos/core#Concept",
"prefLabel": "Alphütte"
},
{
"@id": "_:b15",
"@type": "https://www.ica.org/standards/RiC/ontology#Place",
"name": "Oberstocken (BE)"
},
{
"@id": "_:b16",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "208499",
"type": "original"
},
{
"@id": "_:b17",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"sameAs": "http://rightsstatements.org/vocab/InC/1.0/",
"name": "In Copyright (InC)",
"regulates": "https://memobase.ch/digital/bbb-001-208499-1",
"type": "usage"
},
{
"@id": "_:b18",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "bbb-001-208499-1",
"type": "main"
},
{
"@id": "_:b2",
"@type": "https://www.ica.org/standards/RiC/ontology#Activity",
"affects": "_:b9",
"beginningDate": "2022-03-10T17:08:50Z",
"endDate": "2022-03-10T17:08:50Z",
"performedBy": "_:b5",
"resultsIn": "_:b1",
"type": "enrichment"
},
{
"@id": "_:b3",
"@type": "https://www.ica.org/standards/RiC/ontology#CreationRelation",
"creationRelationHasSource": "https://memobase.ch/record/bbb-001-208499",
"creationRelationHasTarget": "_:b4",
"name": "1884-1980",
"type": "creator"
},
{
"@id": "_:b4",
"@type": "https://www.ica.org/standards/RiC/ontology#Person",
"firstName": "Hans",
"lastName": "Moeglé",
"agentIsTargetOfCreationRelation": "_:b3",
"name": "Moeglé, Hans"
},
{
"@id": "_:b5",
"@type": "https://www.ica.org/standards/RiC/ontology#Mechanism",
"name": "CarrierTypeNormalizer",
"performs": "_:b2"
},
{
"@id": "_:b6",
"@type": "https://www.ica.org/standards/RiC/ontology#Rule",
"name": "onsite",
"regulates": "https://memobase.ch/physical/bbb-001-208499-1",
"type": "access"
},
{
"@id": "_:b7",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "Historische Sammlung Krebser 55/24",
"type": "callNumber"
},
{
"@id": "_:b8",
"@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
"identifier": "bbb-001-208499-1",
"type": "main"
},
{
"@id": "_:b9",
"@type": "https://www.ica.org/standards/RiC/ontology#CarrierType",
"name": "Glasplatte"
},
{
"@id": "https://memobase.ch/digital/bbb-001-208499-1",
"@type": "https://www.ica.org/standards/RiC/ontology#Instantiation",
"P60558": "Grayscale",
"hasFormat": "fmt/42",
"hasMimeType": "image/jpeg",
"height": "2172.0",
"isDistributedOn": "image",
"locator": "sftp:/swissbib_index/mb_sftp/bbb-001/media/208499.jpg",
"orientation": "Undefined",
"width": "1442.0",
"componentColor": [
"A8A8A8",
"C0C0C0",
"527F76",
"545454",
"2F2F4F",
"E6E6FA",
"C0D9D9"
],
"eventType": "CREATE",
"proxyType": "proxydirect",
"identifiedBy": "_:b18",
"instantiates": "https://memobase.ch/record/bbb-001-208499",
"isDerivedFromInstantiation": "https://memobase.ch/physical/bbb-001-208499-1",
"regulatedBy": "_:b17",
"type": "digitalObject"
},
{
"@id": "https://memobase.ch/physical/bbb-001-208499-1",
"@type": "https://www.ica.org/standards/RiC/ontology#Instantiation",
"P60558": "s/w",
"hasCarrierType": [
"_:b9",
"_:b1"
],
"hasDerivedInstantiation": "https://memobase.ch/digital/bbb-001-208499-1",
"identifiedBy": [
"_:b7",
"_:b8"
],
"instantiates": "https://memobase.ch/record/bbb-001-208499",
"physicalCharacteristics": "120 mm x 180 mm",
"regulatedBy": "_:b6",
"type": "physicalObject"
},
{
"@id": "https://memobase.ch/record/bbb-001-208499",
"@type": "https://www.ica.org/standards/RiC/ontology#Record",
"abstract": "Hütte Vorderälpital mit Stockhorn <br> Bildeintrag: auf dem Negativ: Auf Älpital H. Moeglé",
"created": "_:b10",
"spatial": [
"_:b11",
"_:b15"
],
"P60451": "https://memobase.ch/institution/mav",
"sameAs": "http://katalog.burgerbib.ch/detail.aspx?ID=208499",
"eventType": "CREATE",
"isPublished": true,
"conditionsOfUse": "Die physische Zugänglichkeit ist eingeschränkt und erfolgt nach Rücksprache mit der Burgerbibliothek Bern. Es gelten die Preis- und Reprobedingungen und die Benutzungsordnung der BBB. Kontaktperson: Philipp Stämpfli / http://www.burgerbib.ch/dokumente/benutzung/angebot_und_preise_reproduktionen.pdf.",
"hasInstantiation": [
"https://memobase.ch/digital/bbb-001-208499-1",
"https://memobase.ch/physical/bbb-001-208499-1"
],
"hasSubject": "_:b14",
"hasTitle": "_:b13",
"heldBy": "https://memobase.ch/institution/bbb",
"identifiedBy": [
"_:b12",
"_:b16"
],
"isPartOf": "https://memobase.ch/recordSet/bbb-001",
"recordResourceOrInstantiationIsSourceOfCreationRelation": "_:b3",
"regulatedBy": "_:b0",
"title": "Oberstocken; Vorderälpital; Stockhorn -- Alphütte; Landwirtschaft; Ziege; Tierdarstellung; Haustier",
"type": "Foto"
}
],
"@context": {
"type": {
"@id": "https://www.ica.org/standards/RiC/ontology#type"
},
"name": {
"@id": "https://www.ica.org/standards/RiC/ontology#name"
},
"regulates": {
"@id": "https://www.ica.org/standards/RiC/ontology#regulates",
"@type": "@id"
},
"sameAs": {
"@id": "http://schema.org/sameAs"
},
"resultsFrom": {
"@id": "https://www.ica.org/standards/RiC/ontology#resultsFrom",
"@type": "@id"
},
"creationRelationHasSource": {
"@id": "https://www.ica.org/standards/RiC/ontology#creationRelationHasSource",
"@type": "@id"
},
"creationRelationHasTarget": {
"@id": "https://www.ica.org/standards/RiC/ontology#creationRelationHasTarget",
"@type": "@id"
},
"performs": {
"@id": "https://www.ica.org/standards/RiC/ontology#performs",
"@type": "@id"
},
"P60558": {
"@id": "http://rdaregistry.info/Elements/u/P60558"
},
"regulatedBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#regulatedBy",
"@type": "@id"
},
"identifiedBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#identifiedBy",
"@type": "@id"
},
"hasDerivedInstantiation": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasDerivedInstantiation",
"@type": "@id"
},
"instantiates": {
"@id": "https://www.ica.org/standards/RiC/ontology#instantiates",
"@type": "@id"
},
"hasCarrierType": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasCarrierType",
"@type": "@id"
},
"physicalCharacteristics": {
"@id": "https://www.ica.org/standards/RiC/ontology#physicalCharacteristics"
},
"expressedDate": {
"@id": "https://www.ica.org/standards/RiC/ontology#expressedDate"
},
"heldBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#heldBy",
"@type": "@id"
},
"spatial": {
"@id": "http://purl.org/dc/terms/spatial",
"@type": "@id"
},
"recordResourceOrInstantiationIsSourceOfCreationRelation": {
"@id": "https://www.ica.org/standards/RiC/ontology#recordResourceOrInstantiationIsSourceOfCreationRelation",
"@type": "@id"
},
"title": {
"@id": "https://www.ica.org/standards/RiC/ontology#title"
},
"hasTitle": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasTitle",
"@type": "@id"
},
"hasSubject": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasSubject",
"@type": "@id"
},
"isPublished": {
"@id": "https://memobase.ch/internal/isPublished",
"@type": "http://www.w3.org/2001/XMLSchema#boolean"
},
"conditionsOfUse": {
"@id": "https://www.ica.org/standards/RiC/ontology#conditionsOfUse"
},
"hasInstantiation": {
"@id": "https://www.ica.org/standards/RiC/ontology#hasInstantiation",
"@type": "@id"
},
"created": {
"@id": "http://purl.org/dc/terms/created",
"@type": "@id"
},
"P60451": {
"@id": "http://rdaregistry.info/Elements/u/P60451",
"@type": "@id"
},
"abstract": {
"@id": "http://purl.org/dc/terms/abstract"
},
"isPartOf": {
"@id": "https://www.ica.org/standards/RiC/ontology#isPartOf",
"@type": "@id"
},
"eventType": {
"@id": "https://memobase.ch/internal/eventType"
},
"prefLabel": {
"@id": "http://www.w3.org/2004/02/skos/core#prefLabel"
},
"agentIsTargetOfCreationRelation": {
"@id": "https://www.ica.org/standards/RiC/ontology#agentIsTargetOfCreationRelation",
"@type": "@id"
},
"lastName": {
"@id": "http://xmlns.com/foaf/0.1/lastName"
},
"firstName": {
"@id": "http://xmlns.com/foaf/0.1/firstName"
},
"identifier": {
"@id": "https://www.ica.org/standards/RiC/ontology#identifier"
},
"componentColor": {
"@id": "http://www.europeana.eu/schemas/edm/componentColor",
"@type": "http://www.w3.org/2001/XMLSchema#hexBinary"
},
"isDerivedFromInstantiation": {
"@id": "https://www.ica.org/standards/RiC/ontology#isDerivedFromInstantiation",
"@type": "@id"
},
"width": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#width"
},
"orientation": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#orientation"
},
"height": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#height"
},
"hasFormat": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasFormat"
},
"proxyType": {
"@id": "https://memobase.ch/internal/proxyType"
},
"locator": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#locator"
},
"hasMimeType": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType"
},
"isDistributedOn": {
"@id": "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#isDistributedOn"
},
"beginningDate": {
"@id": "https://www.ica.org/standards/RiC/ontology#beginningDate",
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"endDate": {
"@id": "https://www.ica.org/standards/RiC/ontology#endDate",
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"performedBy": {
"@id": "https://www.ica.org/standards/RiC/ontology#performedBy",
"@type": "@id"
},
"affects": {
"@id": "https://www.ica.org/standards/RiC/ontology#affects",
"@type": "@id"
},
"resultsIn": {
"@id": "https://www.ica.org/standards/RiC/ontology#resultsIn",
"@type": "@id"
}
}
}
\ No newline at end of file
{
"@graph": [
{
"@id": "_:b3",
"@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/apf-001-1284-1",
"type": "usage"
},
{
"@id": "_:b4",
"@type": "https://www.ica.org/standards/RiC/ontology#CreationRelation",
"creationRelationHasSource": "https://memobase.ch/record/apf-001-1284",
"creationRelationHasTarget": "_:b5",
"name": "interlocuteur",
"type": "contributor"
},
{
"@id": "_:b5",
"@type": "https://www.ica.org/standards/RiC/ontology#Person",
"firstName": "Jacques",
"lastName": "Poget",
"agentIsTargetOfCreationRelation": "_:b4",
"name": "Jacques Poget"
},
{
"@id": "_:b8",
"@type": "https://www.ica.org/standards/RiC/ontology#Place",
"name": "Genève"
},
{
"@id": "_:b14",
"@type": "https://www.ica.org/standards/RiC/ontology#Person",
"firstName": "Gilles",
"lastName": "Vuissoz",
"agentIsTargetOfCreationRelation": "_:b15",
"name": "Gilles Vuissoz"
},
{
"@id": "_:b15",
"@type": "https://www.ica.org/standards/RiC/ontology#CreationRelation",
"creationRelationHasSource": "https://memobase.ch/record/apf-001-1284",
"creationRelationHasTarget": "_:b14",
"name": "photographe",
"type": "contributor"
},
{
"@id": "_:b24",
"@type": "https://www.ica.org/standards/RiC/ontology#Activity",
"affects": "_:b26",
"beginningDate": "2021-27-19T09:27:09+0000",
"endDate": "2021-27-19T09:27:09+0000",
"performedBy": "_:b25",
"resultsIn": "_:b27",
"type": "enrichment"
},
{
"@id": "_:b25",
"@type": "https://www.ica.org/standards/RiC/ontology#Mechanism",
"name": "LanguagesNormalizer",
"performs": "_:b24"
},
{
"@id": "_:b26",
"@type": "https://www.ica.org/standards/RiC/ontology#Language",
"name": "français",
"type": "content"
},
{
"@id": "_:b27",
"@type": "https://www.ica.org/standards/RiC/ontology#Language",
"sameAs": "http://www.wikidata.org/entity/Q150",
"name": [
{