java - How to add items to rdflist /rdfcollection dynamically in Jena -


is possible add items dynamically rdflist in jena? like:

rdflist list = model.createlist(new rdfnode[] {}); //string names of rdf classes string[] parts = list.split("-");  for(int = 0; i<parts.length; i++){     ontclass oclass = model.getontclass("http://example.org/"+parts[i]);       list.add(oclass); } 

i'm getting
com.hp.hpl.jena.rdf.model.emptylistupdateexception: attempt add() empty list (rdf:nil)
in advance

without seeing of code , of values are, can't sure what's happening, think problem here can't use rdflist#add empty list, , think that's you're creating @ start. since you're creating list no elements, should getting rdf:nil back, empty list. note documentation rdflist#add says:

if list empty (nil) list, cannot perform side-effecting update without changing uri of node (from rdf:nil) blank-node new list cell) without violating jena invariant. therefore, update operation throw exception if attempt made add nil list. safe ways add empty list include with(rdfnode) , cons(rdfnode).

you didn't mention whether you're getting exception or not.

in case, think easiest thing create array of ontclasses, , create list them. is, (untested):

string[] parts = list.split("-"); rdfnode[] elements = new rdfnode[parts.length];  for(int = 0; i<parts.length; i++){     elements[i] = model.getontclass("http://example.org/"+parts[i]);   }  rdflist list = model.createlist(elements); 

alternatively, if want use with, mentioned in documentation, you'd (again, untested):

rdflist list = model.createlist(new rdfnode[] {}); //string names of rdf classes string[] parts = list.split("-");  for(int = 0; i<parts.length; i++){     ontclass oclass = model.getontclass("http://example.org/"+parts[i]);       list = list.with(oclass); } 

for bit more this, might find this answer of mine , comments on relevant. you're not first 1 have had bit of struggle rdflists.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -