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

use only enriched carrier types

remove all println in tests
parent 606b9dc8
Pipeline #24281 passed with stages
in 6 minutes and 22 seconds
......@@ -118,15 +118,38 @@ object Extractors {
List(stringValue(record.get)(property).get)
} else if (arrayValue(record.get)(property).isDefined) {
arrayValue(record.get)(property).get.map(_.str).toList
} else List.empty[String]
} else {
List.empty[String]
}
//todo das ist im Moment eine Annahme, da ich davon ausgehe, dass heldBy entweder ein Literal
//todo das ist im Moment eine Annahme, da ich davon ausgehe, dass heldBy entweder ein Literal
// oder Liste von Literalen mit typ identifier enthält
idents.filter(isHttpIdentifier.matches(_))
}
private val stringOrArrayValue = (jsonObj: JObj) =>
(objProperty: String)
=> (itemInArrProperty: String) => {
if (jsonObj(objProperty).isInstanceOf[JArr]) {
jsonObj(objProperty).arr.flatMap(item =>
stringValue(item.obj)(itemInArrProperty) match {
case Some(s) => Some(s)
case None => None
}
)
}
else {
stringValue(jsonObj)(objProperty) match {
case Some(s) => Some(s)
case None => None
}
}
}
private val stringValue = (jsonObj: JObj) =>
(valueKey: String) => jsonObj.value.get(valueKey).flatMap(v => v.strOpt)
......@@ -369,11 +392,13 @@ object Extractors {
.filter(_.obj.contains("hasCarrierType"))
.flatMap((physicalObject: JValue) =>
Extractors.getAllBlankNodeContent(graph)(physicalObject.obj)("hasCarrierType"))
//todo: nur die angerecherten Werte
// anstelle von name sameAs verwenden, sameAs existiert nur wen nes angereichert ist
// "andere" Variante: existiert rico:resultsFrom
.flatMap(objectWithCarrierType => stringValue(objectWithCarrierType.obj)("name"))
.toList
.filter(onlyEnriched => {
//mögliche Variante: contains("sameAs")
//ich gehe davon aus, dass auch resultsFrom das Kennzeichen für den Anreicherungsprozess ist
onlyEnriched.contains("resultsFrom")
})
.flatMap(objectWithEnrichedCarrierType => stringOrArrayValue(objectWithEnrichedCarrierType)("name")("@value")).toList
val dcTermsCreated
......
......@@ -47,10 +47,13 @@ object PlayArround {
}
// (2) print the results
/*
for (row <- rows) {
println(s"${row(0)}|${row(1)}|${row(2)}|${row(3)}|${row(4)}")
}
*/
}
......
......@@ -166,7 +166,7 @@ class CHOSpec extends AnyFunSuite with Matchers{
// nehmen wir property @language oder Mapping nach Wikidata???
val languages = Extractors.resourceAllLanguages(graph)(record.value)
println(languages)
//println(languages)
//assert(languages.length == 4)
//assert(languages.head == "Français")
......@@ -253,7 +253,15 @@ class CHOSpec extends AnyFunSuite with Matchers{
//println(genres2)
val edm = new EDM
println(Utils.serializeRDFModel(edm.createChoObject(graph2,record2,digObj).obj.getModel))
val dcType = Utils.serializeRDFModel(edm.createChoObject(graph2,record2,digObj).obj.getModel)
assert(dcType.contains("<dc:type>Intervista</dc:type>"))
assert(dcType.contains("<dc:type>Parlato</dc:type>"))
assert(dcType.contains("<dc:type>Rede</dc:type>"))
assert(dcType.contains("<dc:type>Gesprochen</dc:type>"))
assert(dcType.contains("<dc:type>Interview</dc:type>"))
assert(dcType.contains("<dc:type>Parlé</dc:type>"))
assert(dcType.contains("<dc:type>Discours</dc:type>"))
assert(dcType.contains("<dc:type>Discorso</dc:type>"))
......@@ -271,7 +279,7 @@ class CHOSpec extends AnyFunSuite with Matchers{
val graph1 = Extractors.jsonGraph(ricoCertainty).get.arr
val record1 = Extractors.record(graph1).get.obj
val certainty = Extractors.dcTermsCreated(graph1)(record1)
certainty.foreach(println)
assert(certainty.head == "Monat 5 1945")
}
......@@ -328,11 +336,25 @@ class CHOSpec extends AnyFunSuite with Matchers{
}
test ("collect dcterms:medium") {
val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
val graph = Extractors.jsonGraph(ricoRawContributor).get.arr
val record = Extractors.record(graph).get
val dObj = Extractors.digitalObject(graph).get
//s. zum Umgang mit dem Extractor auch den ausführlichen Kommentar bei der Funktion
val mediums = Extractors.resourceDCTermsMedium(graph)
assert(mediums.nonEmpty && mediums.head == "Nitrato")
assert(mediums.length == 3 && mediums.head == "Direktschnitt")
val edm = new EDM
val serialization = Utils.serializeRDFModel(edm.createChoObject(graph,record,dObj).obj.getModel)
assert(serialization.contains("<dcterms:medium>Direktschnitt</dcterms:medium>"))
assert(serialization.contains("<dcterms:medium>L'ÉTIQUETTE MANQUANTE</dcterms:medium>"))
assert(serialization.contains("<dcterms:medium>GALATEO MANCANTE</dcterms:medium>"))
val gMediumNotEnriched = Extractors.jsonGraph(rawRicoIndent).get.arr
val m = Extractors.resourceDCTermsMedium(gMediumNotEnriched)
assert(m.isEmpty)
}
......
......@@ -20,6 +20,7 @@
package ch.memobase.rico2edm.edm
import ch.memobase.Utils
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.Aggregation
import ch.memobase.rico2edm.rdf.writer.RdfXmlWriter
......@@ -38,7 +39,7 @@ class EDMSpec extends AnyFunSuite with Matchers {
test ("complete EDM creation") {
ignore("complete EDM creation") {
val edm = new EDM
......@@ -47,9 +48,9 @@ class EDMSpec extends AnyFunSuite with Matchers {
edmCreationResult match {
case Success(value) =>
println(value.obj._1)
println(value.obj._2)
case Failure(exception) => println(exception)
//println(value.obj._1)
//println(value.obj._2)
case Failure(exception) => //println(exception)
}
}
......@@ -61,12 +62,10 @@ class EDMSpec extends AnyFunSuite with Matchers {
val recordId = Extractors.recordId(record.get).get
val agg = new Aggregation(recordId)
val sOut = new StringWriter
val rdfWriter = new RdfXmlWriter(sOut)
Rio.write(agg.getModel, rdfWriter)
println(sOut)
assert(Utils.serializeRDFModel(agg.getModel).contains("""<ore:Aggregation rdf:about="https://memobase.ch/record/rts-002-FNB023_1639_023">"""))
}
......
......@@ -20,10 +20,11 @@
package ch.memobase.rico2edm.edm
import ch.memobase.Utils
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.ProvidedCHO
import ch.memobase.rico2edm.rdf.writer.RdfXmlWriter
import org.eclipse.rdf4j.rio.{RDFFormat, Rio}
import org.eclipse.rdf4j.rio.Rio
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
......@@ -76,8 +77,7 @@ class ExtractorSpec extends AnyFunSuite with Matchers{
.identifiedBy(graph)(record.value)
.foreach(c => cho.addIdentifier(Some(c)))
val rdfWriter = new RdfXmlWriter(System.out)
Rio.write(cho.getModel,rdfWriter)
assert(Utils.serializeRDFModel(cho.getModel).contains("""<dc:identifier>rts-002-FNB023_1639_023</dc:identifier>"""))
}
......@@ -101,13 +101,8 @@ class ExtractorSpec extends AnyFunSuite with Matchers{
val recId = Extractors.recordId(record)
val cho = new ProvidedCHO(Extractors.recordId(record).get)
//use our own writer so we are able to create special EDM output requirements
val rdfWriter = new RdfXmlWriter(System.out)
Rio.write(cho.getModel,rdfWriter)
//println(graph)
//println(digitalObject)
//println(record)
assert(Utils.serializeRDFModel(cho.getModel).contains("""<edm:ProvidedCHO rdf:about="https://memobase.ch/record/ati-001-L_44_13">"""))
}
......
......@@ -20,6 +20,7 @@
package ch.memobase.rico2edm.edm
import ch.memobase.Utils
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.{ProvidedCHO, WebResource}
import ch.memobase.rico2edm.rdf.writer.RdfXmlWriter
......@@ -65,8 +66,8 @@ class ExtractorSpecWebResource extends AnyFunSuite with Matchers {
*/
cho.addCreationDate(Extractors.creationDate(graph.arr)(record))
webresource.get.getModel.addAll(cho.getModel)
val rdfWriter = new RdfXmlWriter(System.out)
Rio.write(webresource.get.getModel, rdfWriter)
assert(Utils.serializeRDFModel(cho.getModel).contains("<dc:description>Veduta dell'albergo</dc:description>"))
}
}
......
......@@ -28,7 +28,7 @@ import java.io.StringReader
class RdfXmlWriterSpec extends AnyFunSuite{
import ch.memobase.Utils._
test("read result created by own RdfXmlWriter and write again with writer") {
ignore("read result created by own RdfXmlWriter and write again with writer") {
val rdfParser = Rio.createParser(RDFFormat.RDFXML);
//val rdfWriter: RDFWriter = Rio.createWriter(RDFFormat.RDFXML, System.out)
......
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