Commit 61db65ac authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Update RdfHandler to include Activity & Mechanisms to Record.

parent 4403ec19
......@@ -35,6 +35,19 @@ class RdfHandler(data: String, private val externalBaseUrl: String) {
resultModel.add(targetStatement.`object`.asResource().listProperties())
}
}
// Adding statements connected via Activity / Mechanism.
if (blankNode.hasProperty(RICO.resultsFrom)) {
blankNode.listProperties(RICO.resultsFrom).forEach { targetStatement ->
val values = targetStatement.`object`.asResource().listProperties()
values.forEach { activityStatement ->
if (activityStatement.predicate == RICO.performedBy) {
val mechanism = activityStatement.`object`.asResource()
resultModel.add(mechanism.listProperties())
}
resultModel.add(activityStatement)
}
}
}
// Adding blank node statements connected to record
resultModel.add(blankNode.listProperties())
}
......
......@@ -5,12 +5,14 @@ import java.io.StringWriter
import java.nio.charset.Charset
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.apache.logging.log4j.LogManager
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestRdfHandler {
private val log = LogManager.getLogger("TestRdfHandler")
private val resourcePath = "src/test/resources/rdf"
private fun readFile(fileName: String): String {
......@@ -38,6 +40,8 @@ class TestRdfHandler {
val out = StringWriter()
RDFDataMgr.write(out, pair.second, Lang.NTRIPLES)
log.error(out.toString())
val sortedOut = sort(out.toString().split("\n")).trim()
assertThat(sortedOut)
......@@ -47,6 +51,26 @@ class TestRdfHandler {
.isEqualTo("https://memobase.ch/record/AFZ-IB_Becker_Audiovisuals_63")
}
@Test
fun `test get record with activity and mechanism`() {
val rdfHandler = RdfHandler(readFile("inputActivity.nt"), "https://memobase.ch/")
val pair = rdfHandler.getRecord()
val out = StringWriter()
RDFDataMgr.write(out, pair.second, Lang.NTRIPLES)
log.error(out.toString())
val sortedOut = sort(out.toString().split("\n")).trim()
assertThat(sortedOut)
.isEqualTo(sort(readFile("recordActivityOutput.nt").split("\n")).trim())
assertThat(pair.first)
.isEqualTo("https://memobase.ch/record/AfZ-Bosshard-NL_Walter_Bosshard-504")
}
@Test
fun `test get referenced non binary resources`() {
val rdfHandler = RdfHandler(readFile("input.nt"), "https://memobase.ch/")
......
<https://memobase.ch/record/AfZ-Bosshard-NL_Walter_Bosshard-504> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasGenre> _:b1 .
<https://memobase.ch/record/AfZ-Bosshard-NL_Walter_Bosshard-504> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
_:b1 <https://www.ica.org/standards/RiC/ontology#resultsFrom> _:b2 .
_:b1 <http://www.w3.org/2004/02/skos/core#prefLabel> "Documentario"@it .
_:b1 <http://www.w3.org/2004/02/skos/core#prefLabel> "Documentaire"@fr .
_:b1 <http://www.w3.org/2004/02/skos/core#prefLabel> "Dokumentarfilm"@de .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
_:b2 <https://www.ica.org/standards/RiC/ontology#resultsIn> _:b1 .
_:b2 <https://www.ica.org/standards/RiC/ontology#performedBy> _:b3 .
_:b2 <https://www.ica.org/standards/RiC/ontology#endDate> "2020-33-07T13:33:24+0000"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
_:b2 <https://www.ica.org/standards/RiC/ontology#beginningDate> "2020-33-07T13:33:24+0000"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
_:b2 <https://www.ica.org/standards/RiC/ontology#type> "enrichment" .
_:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Activity> .
_:b3 <https://www.ica.org/standards/RiC/ontology#performs> _:b2 .
_:b3 <https://www.ica.org/standards/RiC/ontology#name> "GenreNormalizer" .
_:b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Mechanism> .
<https://memobase.ch/record/AfZ-Bosshard-NL_Walter_Bosshard-504> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasGenre> _:B .
<https://memobase.ch/record/AfZ-Bosshard-NL_Walter_Bosshard-504> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Activity> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Mechanism> .
_:B <http://www.w3.org/2004/02/skos/core#prefLabel> "Documentaire"@fr .
_:B <http://www.w3.org/2004/02/skos/core#prefLabel> "Documentario"@it .
_:B <http://www.w3.org/2004/02/skos/core#prefLabel> "Dokumentarfilm"@de .
_:B <https://www.ica.org/standards/RiC/ontology#beginningDate> "2020-33-07T13:33:24+0000"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
_:B <https://www.ica.org/standards/RiC/ontology#endDate> "2020-33-07T13:33:24+0000"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
_:B <https://www.ica.org/standards/RiC/ontology#name> "GenreNormalizer" .
_:B <https://www.ica.org/standards/RiC/ontology#performedBy> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#performs> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#resultsFrom> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#resultsIn> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#type> "enrichment" .
\ No newline at end of file
This diff is collapsed.
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