Search code examples
javasemantic-webjenaontologyprotege

How to create individuals of a specific class using Jena?


I've created an ontology using Protege and would now like to add individuals with Jena.

Let's say there is a class SpecialThing that has a property hasData. Now I'd like to programmatically add a new SpecialThing. That's my code so far, but the created individual is only an instance of Thing. So what do I have to add here? Using model.createResourceI can only specify the URI of the resource to be created.

String ns = "http://example.org";
Resource res = model.createResource(ns + "/NewThing"); 
Property prop = model.getProperty(ns + "#hasData"); 
res.addProperty(prop, "something"); 

Solution

  • You can specify the type of the resource as a second argument to the createResource() method. Take a look at ModelCon.createResource()