Commit 203c9512 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add sftp locator extractor

parent 4df1916a
...@@ -2,6 +2,7 @@ package org.memobase ...@@ -2,6 +2,7 @@ package org.memobase
import org.apache.jena.rdf.model.Model import org.apache.jena.rdf.model.Model
import org.apache.jena.rdf.model.ModelFactory import org.apache.jena.rdf.model.ModelFactory
import org.memobase.rdf.EBUCORE
import org.memobase.rdf.RDF import org.memobase.rdf.RDF
import org.memobase.rdf.RICO import org.memobase.rdf.RICO
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
...@@ -50,4 +51,17 @@ class RdfHandler(data: String) { ...@@ -50,4 +51,17 @@ class RdfHandler(data: String) {
model model
}.toList() }.toList()
} }
fun getSftpLocators(): List<Pair<String, String?>> {
return model.listSubjectsWithProperty(RICO.type, "digitalObject").filterKeep {
it.hasProperty(EBUCORE.locator)
}.mapWith {
val url = it.getProperty(EBUCORE.locator).`object`.asLiteral().string
if (url.startsWith("sftp:")) {
Pair(it.uri, url.replace("sftp:", ""))
} else {
Pair(it.uri, null)
}
}.toList()
}
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ import org.apache.jena.rdf.model.ModelFactory ...@@ -5,6 +5,7 @@ import org.apache.jena.rdf.model.ModelFactory
import org.apache.jena.rdf.model.impl.SelectorImpl import org.apache.jena.rdf.model.impl.SelectorImpl
import org.apache.jena.riot.Lang import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr import org.apache.jena.riot.RDFDataMgr
import org.assertj.core.api.Assertions.`in`
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Condition import org.assertj.core.api.Condition
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
...@@ -64,13 +65,23 @@ class TestRdfHandler { ...@@ -64,13 +65,23 @@ class TestRdfHandler {
assertThat(sortedOut) assertThat(sortedOut)
.isEqualTo(sort(readFile("instantiationOutput$index.nt").split("\n")).trim()) .isEqualTo(sort(readFile("instantiationOutput$index.nt").split("\n")).trim())
} }
}
@Test
fun `test get sftp locators`() {
val rdfHandler = RdfHandler(readFile("inputSftp.nt"))
val pairs = rdfHandler.getSftpLocators()
pairs.forEachIndexed { index, pair ->
assertThat(pair)
.isEqualTo(resultPairs[index])
}
} }
private val resultPairs: List<Pair<String, String?>> = listOf(
Pair("https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1", null),
Pair("https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2", "/path/to/file/filename.jpg")
)
} }
\ No newline at end of file
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#locator> "http://digitalisate.afz.ethz.ch/?&guid=0a9aef73bc2845eabc3c20db7c141bea" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Instantiation> .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <https://www.ica.org/standards/RiC/ontology#type> "digitalObject" .
<https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-2> <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#locator> "sftp:/path/to/file/filename.jpg" .
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