Dmitri Pisarenko
2017-03-16 09:11:20 UTC
Hello!
I have an application, which creates an individual called batch. A batch has a list of company IDs (strings). Add the property like this:
open fun addCompanyIdsList(
batch: Resource,
companyIds: List<String>,
model: Model) {
val prop = model.createProperty(Bp2BatchCompanyIds)
val list = model.createList()
companyIds
.filter { it.isNumeric() }
.map { it.toInt() }
.map { id -> model.createTypedLiteral(id) }
.forEach { literal -> list.add(literal) }
batch.addProperty(prop, list)
}
In another operation I want to remove the first element of the list so that this change is saved in Jena. For primitive data types like integers, there is the method
org.apache.jena.rdf.model.Statement#changeLiteralObject(boolean)
and its analogs.
How do I change the list? Is it sufficient to just remove an element from the list like in the code snippet below?
ds.begin(ReadWrite.WRITE)
val query = createQuery("""SELECT ?x
WHERE { ?x $Bp2BatchNumber $batchId }""")
val qexec = createQueryExecution(ds, query)
val rs = qexec.execSelect()
val sol = rs.nextSolution()
val rec = sol["x"]
val prop = findStatement(Bp2BatchCompanyIds, rec as Resource)
val companyIds = prop.`object` as RDFList
val head = companyIds.head
companyIds.remove(result)
ds.end()
Thanks in advance
Dmitri Pisarenko
I have an application, which creates an individual called batch. A batch has a list of company IDs (strings). Add the property like this:
open fun addCompanyIdsList(
batch: Resource,
companyIds: List<String>,
model: Model) {
val prop = model.createProperty(Bp2BatchCompanyIds)
val list = model.createList()
companyIds
.filter { it.isNumeric() }
.map { it.toInt() }
.map { id -> model.createTypedLiteral(id) }
.forEach { literal -> list.add(literal) }
batch.addProperty(prop, list)
}
In another operation I want to remove the first element of the list so that this change is saved in Jena. For primitive data types like integers, there is the method
org.apache.jena.rdf.model.Statement#changeLiteralObject(boolean)
and its analogs.
How do I change the list? Is it sufficient to just remove an element from the list like in the code snippet below?
ds.begin(ReadWrite.WRITE)
val query = createQuery("""SELECT ?x
WHERE { ?x $Bp2BatchNumber $batchId }""")
val qexec = createQueryExecution(ds, query)
val rs = qexec.execSelect()
val sol = rs.nextSolution()
val rec = sol["x"]
val prop = findStatement(Bp2BatchCompanyIds, rec as Resource)
val companyIds = prop.`object` as RDFList
val head = companyIds.head
companyIds.remove(result)
ds.end()
Thanks in advance
Dmitri Pisarenko