Many thanks for your answer! This is part of a bigger change, which I intend to test during the weekend. I'll write back to you, if I find out something interesting.
Thanks again Dmitri 16.03.2017, 12:27, "Lorenz B." <[email protected]>: > As far as I know, all Jena RDFNodes and Statements are immutable. > The methods on Statements objects or convenience methods that remove the > old statement and add the new one to the underlying model. > > In your case it's just changeObject(RDFNode val), see [1] > > where val denotes the new RDFNode object, in your case the new list. > RDFList::Rmeove will return a new RDFList object, thus, you can use this > one as argument. > > [1] > https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Statement.html#changeObject-org.apache.jena.rdf.model.RDFNode- > >>> Which programming language is this? >> Kotlin. >> >> "companyIds.head" is equivalent to "companyIds.getHead()". >> >>> Does your code compile? I'm asking because there is just a getHead() >>> method on an RDFList object. And this one returns an RDFNode object, >>> thus, remove should be impossible here. >> It does compile, but I haven't tested it manually yet. >> >> Could you point me to an analog of >> org.apache.jena.rdf.model.Statement#changeLiteralObject(...) for lists? >> >> Dmitri >> >> 16.03.2017, 12:18, "Lorenz B." <[email protected]>: >>>> 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() >>> Which programming language is this? >>> Does your code compile? I'm asking because there is just a getHead() >>> method on an RDFList object. And this one returns an RDFNode object, >>> thus, remove should be impossible here. >>>> Thanks in advance >>>> >>>> Dmitri Pisarenko >>> -- >>> Lorenz Bühmann >>> AKSW group, University of Leipzig >>> Group: http://aksw.org - semantic web research center > > -- > Lorenz Bühmann > AKSW group, University of Leipzig > Group: http://aksw.org - semantic web research center
