Question

I try to remove an existing individual from my RDF file, but I always get a NullPointerException. The Individual I am getting is there, because I can print out a property. Can someone please tell me what I have done wrong?

final static String SN = "http://vaceta.pavo.uberspace.de/RDF/social-media.owl#";

InputStream in = context.getResourceAsStream("WEB-INF/resources/social-media.rdf");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.read(in, null);
in.close();

Individual user01 = model.getIndividual(SN + "User01");
model.remove(user01, null, (RDFNode) null);
model.remove(null, null, user01);

output = new FileOutputStream(context.getRealPath("/")+"WEB-INF/resources/social-media.rdf");
model.writeAll(output, "RDF/XML", null);
output.close();

stacktrace:

enter image description here

Was it helpful?

Solution

You're using ModelCon.remove(s,p,o) which doesn't allow nulls. You want to use Model.removeAll(s,p,o) instead which does allow nulls and uses them as wildcards. Here are the corresponding Javadocs (with emphasis added):

ModelCon.remove

Model remove(Resource s, Property p, RDFNode o)

remove the statement (s, p, o) from this model and answer this model. None of s, p, o are permitted to be null: for wildcard removal, see removeAll.

Model.removeAll

Model removeAll(Resource s, Property p, RDFNode r)

Remove all the statements matching (s, p, o) from this model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top