Reputation: 12383
I'm working on how to automatically instantiate an ontology with Jena. I'm interested in instantiating concepts discovered from a set of data.
My problem is that sometimes I need just to instantiate one concept of the ontology. And I'm confused since in Jena, we need a complete Statement to instantiate an ontology.
Assuming that I've the following ontology.
What would be the statement to instantiate only one concept on the ontology for example EventType
?
Is it necessary to have a Statement
to instantiate an ontology ?
or Is my ontology not expressive enough ?
Edition : My Jena Code
public static void manageOntologies() throws FileNotFoundException{
int i,inFrame, lineSize;
int frameNum = 0;
Individual individu;
Resource resource;
Statement statement;
OntModel domainModel;
Vector<String> lines = readFile("data/Trace.dat");
String[] parts = null;
String event = null;
domainModel = ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG);
domainModel.read((new FileInputStream(ontopath)), null);
lineSize = lines.size();
for(i = 0; i < lineSize; i++){
parts = lines.elementAt(i).split(" ");
event = parts[parts.length - 1];
resource = domainModel.createResource(xmlbase + "frame" + frameNum);//, domainModel.getOntClass(xmlbase + "Event"));
domainModel.add(resource, RDF.type, domainModel.getOntClass("Event"));
}
System.out.println("Numbre de frame = " + frameNum);
domainModel.write(System.out);
}
And here are is problem encountered
Exception in thread "main" java.lang.NullPointerException
at com.hp.hpl.jena.rdf.model.impl.ModelCom.add(ModelCom.java:929)
at soctrace.Intology.manageOntologies(Intology.java:87) -- domainModel.add(...)
at soctrace.Intology.main(Intology.java:38)
Edition 2 : My OWL/XML Code
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY tima "http://www.soctrace.org/ontologies/tima.owl#" >
]>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.w3.org/2002/07/owl"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:tima="http://www.soctrace.org/ontologies/tima.owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Ontology rdf:about="http://www.soctrace.org/ontologies/tima.owl">
</Ontology>
<!-- http://www.soctrace.org/ontologies/tima.owl#Event -->
<Class rdf:about="&tima;Event">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</Class>
<!-- http://www.soctrace.org/ontologies/tima.owl#EventDuration -->
<Class rdf:about="&tima;EventDuration">
<rdfs:subClassOf rdf:resource="&tima;ValuePartition"/>
</Class>
<!-- http://www.soctrace.org/ontologies/tima.owl#EventType -->
<Class rdf:about="&tima;EventType">
<rdfs:subClassOf rdf:resource="&tima;ValuePartition"/>
</Class>
<!-- http://www.soctrace.org/ontologies/tima.owl#ValuePartition -->
<Class rdf:about="&tima;ValuePartition"/>
</rdf:RDF>
Thanks for any reply !
Upvotes: 1
Views: 1404
Reputation: 13315
It's hard to be precise, since you haven't provided your data or ontology (so we can't try your code). However, it is quite likely that this is the problem:
domainModel.getOntClass("Event")
"Event"
is not a URI, so it is very unlikely that your ontology has an event class by that name (and if it does, you should change it to use full URI's instead!).
You will need to provide a full URI to getOntClass
, otherwise it will return null
because it does not recognise the class. Assuming you provide a suitable value for EVENT_NS
, then:
domainModel.getOntClass( EVENT_NS + "Event")
Upvotes: 2
Reputation: 8908
You are correct that in RDF you store statements, not individual terms or concepts.
However everything has a type, even if it's just rdfs:Resource
(or in owl typically owl:Individual
or owl:Class
). Thus you all always add something via a statement of the form thing rdf:type Type
, just pick the appropriate type.
In this case presumably EventType
is a class? In that case:
Resource eventTypeResource = model.createResource(eventTypeURI);
model.add(eventTypeResource, RDF.type, OWL.class);
However that's such a common pattern you can use:
Resource eventTypeResource = model.createResource(eventTypeURI, OWL.class);
Or even better use the Jena ontology API:
OntClass eventTypeResource = ontModel.createClass(eventTypeURI);
(OntClass
is still a Resource
, but with some very useful methods added)
Jena provides a nice introduction to the ontology api.
Upvotes: 2