inline fun <T, R> RepositoryResult<T>.map(transform: (T) -> R): List<R>
(source)
Iterates over the RepositoryResult elements using block
/**
* RDF Tutorial example 13: Adding an RDF Model to a database
*
* @author Jeen Broekstra
* @author Jonathan Bisson
*/
object Example13AddRDFToDatabase {
@Throws(IOException::class)
@JvmStatic
fun main(args: Array<String>) {
// First load our RDF file as a Model.
val filename = "example-data-artists.ttl"
val input = javaClass.getResourceAsStream("/$filename")
val model = Rio.parse(input, "", RDFFormat.TURTLE)
// Create a new Repository. Here, we choose a database implementation
// that simply stores everything in main memory. Obviously, for most real-life applications, you will
// want a different database implementation, that can handle large amounts of data without running
// out of memory and keeps data safely on disk.
// See http://docs.rdf4j.org/programming/#_the_repository_api for more extensive net.nprod.rdf4k.examples.examples on
// how to create and maintain different types of databases.
val db = SailRepository(MemoryStore())
db.initialize()
// Open a connection to the database
try {
db.connection.apply {
// add the model
add(model)
// let's check that our data is actually in the database
getStatements(null, null, null).map {
println("db contains: $it")
}
}
} finally {
// before our program exits, make sure the database is properly shut down.
db.shutDown()
}
}
}
block
- is a lambda handling each statement
Author
Jonathan Bisson