문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top