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

more evaluation on contributor vs. creator

parent 3231bc02
Pipeline #22832 passed with stages
in 6 minutes and 32 seconds
......@@ -52,6 +52,24 @@ object Extractors {
res.obj.value
}
private val objContainsValue = (resource: JObj) => (property: String) =>
(value: String) => {
resource(property).getClass match {
case _ : Class[ujson.Arr] => resource(property).arr.exists(_.str == value)
case _ : Class[ujson.Str] => resource(property).str == value
case _ => false
}
}
private val getAllBlankNodeContent = (graph: JArr) =>
(resource: mutable.LinkedHashMap[String, JValue]) =>
(property: String) =>
graph.value.collect {
case res if objContainsValue(resource)(property) (res.obj("@id").str)
=> res.obj.value
}
private val getBlankNodesContent = (graph: JArr) =>
(resource: mutable.LinkedHashMap[String, JValue]) =>
(property: String) =>
......@@ -133,6 +151,40 @@ object Extractors {
)
.toList
//noinspection ScalaStyle
val resourceContributor: JArr => mutable.LinkedHashMap[String, JValue] => List[
(String, String)
] =
graph =>
record =>
getBlankNodesContent(graph)(record)(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
)
.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
val resourceContributorBlanknodes: JArr => mutable.LinkedHashMap[String, JValue] => List[
mutable.LinkedHashMap[String,JValue]
] =
graph =>
record =>
getAllBlankNodeContent(graph)(record)(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
).toList
val producer
: JArr => mutable.LinkedHashMap[String, JValue] => Option[String] =
graph =>
......
This diff is collapsed.
......@@ -31,8 +31,9 @@ class CHOSpec extends AnyFunSuite with Matchers{
private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
private lazy val rawRicoIndentNoContributor = loadFile("src/test/resources/rawIndent.no.contributor.json")
private lazy val ricoWithContributors = loadFile("src/test/resources/raw.contributor.json")
test("get contributors") {
test("get creator") {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val record = Extractors.record(graph).get.obj
......@@ -46,7 +47,7 @@ class CHOSpec extends AnyFunSuite with Matchers{
}
test("missing contributors - wrong blank node") {
test("missing creators - wrong blank node") {
val graph = Extractors.jsonGraph(rawRicoIndentNoContributor).get.arr
val record = Extractors.record(graph).get.obj
......@@ -58,5 +59,18 @@ 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)
}
}
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