Reputation: 195
In my ontology I have the class called "festival
" and it has property value called "CRISTMAS
". It's a string type value. How can I get this value using Jena OWL API?
Upvotes: 1
Views: 3538
Reputation: 33
I guess you have a instance in the class and the value of a property for this instance is a String.
If so, do the following steps:
create OntModel and read file.
OntModel ontModel = ModelFactory.createOntologyModel( OntModelSpec.XXX);
ontModel.read(file:xxx);
get class and property:
OntClass iClass =ontModel.getOntClass(className);
OntProperty iProperty= ontModel.getOntProperty(propertyName);
get instance and output the string:
for (ExtendedIterator<? extends OntResource> it= iClass.listInstances(true);it.hasNext();) {
Individual ins = (Individual) it.next();
RDFNode iValue = ins.getPropertyValue(iProperty);
System.out.println(iValue.toString());
}
Upvotes: 1
Reputation: 9492
Load your ontology into an OntModel
. I assume you did that already.
Use the getProperty(String uri)
method of the OntModel
to retrieve the property.
Use the getOntClass(String uri)
method of the OntModel
to retrieve the class. It returns an OntClass
.
Use the getPropertyValue(Property property)
method of the OntClass
to get the value. It returns an RDFNode
.
To turn the RDFNode
into a string, either use simply toString()
, or do myRDFNode.asLiteral().getString()
.
Upvotes: 0