Pedro
Pedro

Reputation: 4160

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"); 

Upvotes: 2

Views: 2663

Answers (2)

aptr322
aptr322

Reputation: 53

There is OntModel.createIndividual() method which does that.

Upvotes: 3

Pradeep Gollakota
Pradeep Gollakota

Reputation: 2181

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

Upvotes: 2

Related Questions