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

intermediate result while working on ChoObject

parent 5a7f5e5d
Pipeline #22879 passed with stages
in 6 minutes and 50 seconds
## CHOObject
#### dc:date
wie ist diese Aussage zu verstehen?
wir können präziser dcterms:temporal, dcterms:created and dcterms:issued verwenden
Erstellen wir dc:date mit diesen properties?
#### dc:description
nochmal anschauen, ob die bestehende Implementierung ok ist (war eine der ersten)
......@@ -80,12 +80,27 @@ class EDM {
cho.addDescription(Extractors.descriptiveNote(record))
cho.addCreationDate(Extractors.creationDate(graph)(record.obj))
//todo: q.f.S. creator and contributor together with role??
Extractors
.resourceCreator(graph)(
record.value
).foreach(c => cho.addCreator(Some(c._2)))
.resourceSourceOfRelationCreation(graph)(record.value)("creator")
.foreach(c => cho.addCreator(Some(s"${c._1} / ${c._2}")))
//add contributors from two different sources
Extractors
.resourceSourceOfRelationCreation(graph)(record.value)("contributor")
.foreach(c => cho.addContributor(Some(s"${c._1} / ${c._2}")))
Extractors
.resourceContributorRDauP60441(graph)(record.value)
.foreach(c => cho.addContributor(Some(c)))
Extractors
.identifiedBy(graph)(record.value)
.foreach(c => cho.addIdentifier(Some(c)))
ExtractionResult(cho)
}
private def createWebResources(graph: JArr, record: JObj, digitalObject: JObj): ExtractionResult[List[WebResource]] = {
......
......@@ -22,6 +22,7 @@ import ujson.Value.{Value => JValue}
import ujson.{Arr => JArr, Obj => JObj, Str => JStr}
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Try
object Extractors {
......@@ -151,38 +152,46 @@ object Extractors {
)
.toList
//noinspection ScalaStyle
val resourceContributor: JArr => mutable.LinkedHashMap[String, JValue] => List[
(String, String)
] =
val resourceContributorRDauP60441: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
record =>
getBlankNodesContent(graph)(record)(
getBlankNodeContent(graph)(record)("P60441").flatMap(v =>
stringValue(v)("name"))
val resourceSourceOfRelationCreation: JArr => mutable.LinkedHashMap[String, JValue] => String => List[(String, String)] =
graph =>
record =>
relationType =>
getAllBlankNodeContent(graph)(record)(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
)
).filter(obj => obj("type").str == relationType)
.flatMap(obj =>
getBlankNodeContent(graph)(obj)("creationRelationHasTarget")
.filter(v =>
v("type").str == "contributor")
.flatMap(v => stringValue(v)("name")) match {
case Some(name) =>
Some(obj.getOrElse("name", obj("type")).str, name)
case None => None
}
)
.toList
).toList
val resourceContributorBlanknodes: JArr => mutable.LinkedHashMap[String, JValue] => List[
mutable.LinkedHashMap[String,JValue]
] =
val identifiedBy
: JArr => mutable.LinkedHashMap[String, JValue] => ArrayBuffer[String] =
graph =>
record =>
getAllBlankNodeContent(graph)(record)(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
).toList
getAllBlankNodeContent(graph)(record)("identifiedBy")
.filter(obj =>
obj("type").str == "main" || obj("type").str == "original")
.flatMap(v =>
stringValue(v)("identifier") match {
case Some(identifier) =>
Some(v.getOrElse("identifier", v("type")).str)
case None => None
}
)
val producer
......
......@@ -53,6 +53,8 @@ class ProvidedCHO (val id: String) {
def addContributor(contributor:Option[String]): Unit =
contributor.map(t => model.add(iri(id),DC.CONTRIBUTOR,factory.createLiteral(t)))
def addIdentifier(contributor:Option[String]): Unit =
contributor.map(t => model.add(iri(id),DC.IDENTIFIER,factory.createLiteral(t)))
......
......@@ -32,6 +32,7 @@ class CHOSpec extends AnyFunSuite with Matchers{
private lazy val rawRicoIndentNoContributor = loadFile("src/test/resources/rawIndent.no.contributor.json")
private lazy val ricoWithContributors = loadFile("src/test/resources/raw.contributor.json")
private lazy val ricoContributorP60441 = loadFile("src/test/resources/contributor.p60441.json")
test("get creator") {
......@@ -61,16 +62,42 @@ class CHOSpec extends AnyFunSuite with Matchers{
test ("get contributors") {
val graph = Extractors.jsonGraph(ricoWithContributors).get.arr
//val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val record = Extractors.record(graph).get.obj
val contributors = Extractors
.resourceContributorBlanknodes(graph)(
//.resourceCreator(graph)(
record.value
)
println(contributors)
.resourceSourceOfRelationCreation(graph)(record.value)("contributor")
assert(contributors.length == 4)
val creators = Extractors
.resourceSourceOfRelationCreation(graph)(record.value)("creator")
assert(creators.length == 1)
val graph1 = Extractors.jsonGraph(ricoContributorP60441).get.arr
val record1 = Extractors.record(graph1).get.obj
val creators1 = Extractors
.resourceSourceOfRelationCreation(graph1)(record1.value)("creator")
val contributors1 = Extractors
.resourceSourceOfRelationCreation(graph1)(record1.value)("contributor")
assert(creators1.length == 1)
assert(contributors1.length == 2)
val p60441 = Extractors.resourceContributorRDauP60441(graph1)(record1.value)
assert(p60441.get == "Studio Radio Lausanne")
}
test ("get identifier") {
val graph = Extractors.jsonGraph(ricoWithContributors).get.arr
val record = Extractors.record(graph).get.obj
val identifier = Extractors.identifiedBy(graph)(record.value)
assert(identifier.length == 2)
assert(identifier(0) == "FNB023_1639.023")
assert(identifier(1) == "rts-002-FNB023_1639_023")
}
}
......@@ -32,6 +32,7 @@ class ExtractorSpec extends AnyFunSuite with Matchers{
private lazy val rawErroneousFile = loadFile("src/test/resources/raw1LError.json")
private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
private lazy val ricoContributors = loadFile("src/test/resources/raw.contributor.json")
test ("read graph with Extractor") {
assert(Extractors.jsonGraph(rawRico).isSuccess)
......@@ -48,7 +49,7 @@ class ExtractorSpec extends AnyFunSuite with Matchers{
}
test ("create cultural heritage object (CHO") {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val graph = Extractors.jsonGraph(ricoContributors).get.arr
val record = Extractors.record(graph).get.obj
val cho = new ProvidedCHO(Extractors.recordId(record).get)
cho.addTitel(Extractors.title(record))
......@@ -63,8 +64,17 @@ class ExtractorSpec extends AnyFunSuite with Matchers{
*/
cho.addCreationDate(Extractors.creationDate(graph)(record))
//creationDate
Extractors
.resourceSourceOfRelationCreation(graph)(record.value)("creator")
.foreach(c => cho.addCreator(Some(s"${c._1} / ${c._2}")))
Extractors
.resourceSourceOfRelationCreation(graph)(record.value)("contributor")
.foreach(c => cho.addContributor(Some(s"${c._1} / ${c._2}")))
Extractors
.identifiedBy(graph)(record.value)
.foreach(c => cho.addIdentifier(Some(c)))
val rdfWriter = new RdfXmlWriter(System.out)
Rio.write(cho.getModel,rdfWriter)
......
Markdown is supported
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