Presentation : Konstantinos Kanaris
What is Jena? Usage of Jena Main Concepts Main Components Storage Models OWL API RDF API Reasoning Application-oriented issues
Open source Semantic Web framework for Java based on W3C recommendations for RDF and OWL Provides a suitable programming environment for RDF, RDFS, OWL, SPARQL and an integrated rule-based inference mechanism
Import of owl ontologies, RDF, DAML into suitable models (persistent or in-memory) Processing of these models Export of these models to owl, rdf, daml files
Almost all ontology concepts: Classes: A class is a definition of a group of individuals that belong together because they share common properties. For example John and Mary both belong to the class “person”. Instances: Instances are what the classes consist of; their members, they inherit class characteristics and properties may be used to relate to one another
Properties: binary relations Object Properties: relations between instances of two classes Datatype Properties: relations between instances of classes and RDF literals and XML Schema datatypes
com.hp.hpl.jena.rdf.model: package for creating and manipulating RDF graphs Model: RDF model ModelMaker: ModelMaker contains a collection of named models, methods for creating new models [both named and anonymous] and opening previously-named models, removing models, and accessing a single "default" Model for this Maker. Literal: RDF Literal Statement: RDF Statement
com.hp.hpl.jena.ontology: package that provides a set of abstractions and convenience classes for accessing and manipluating ontologies represented in RDF OntModel: An enhanced view of a Jena model that is known to contain ontology data, under a given ontology vocabulary (such as OWL) OntClass: Interface that represents an ontology node characterising a class description ComplementClass IntersectionClass UnionClass
OntResource: Provides a common super-type for all of the abstractions in this ontology representation package OntModelSpec: Encapsulates a description of the components of an ontology model, including the storage scheme, reasoner and language profile ObjectProperty: Interface encapsulating properties whose range values are restricted to individuals (as distinct from datatype valued properties) DatatypeProperties: Interface that encapsulates the class of properties whose range values are datatype values (as distinct from ObjectProperty whose values are individuals)
com.hp.hpl.jena.reasoner.Reasoner: reasoner subsystem designed to allow a range of inference engines to be plugged into Jena com.hp.hpl.jena.reasoner.ReasonerRegistry: global registry of known reasoner modules
Persistent Storage Example Source Code: OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM); IDBConnection conn = new DBConnection(dbURL, username, password, dbType); ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model m = maker.createModel(" lab/projects/grid4all/ontology/grid4allOnto", false); m.read("file:G4Aonto-example.owl"); conn.close();
In Memory Source Code Example: ModelMaker modelMaker = ModelFactory.createMemModelMaker(); Model model 1 = modelMaker.createModel("myBase"); java.io.InputStream in=FileManager.get().open(fc.getCurrentDirectory().getAbsolutePath()+"\\" +fc.getSelectedFile().getName()); model1.read(in, ""); OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM ); com.hp.hpl.jena.reasoner.Reasoner reasoner1 = PelletReasonerFactory.theInstance().create(); spec.setReasoner( reasoner1 ); OntModel ontTestModel = ModelFactory.createOntologyModel(spec, myModel);
Source Code Example: private ObjectProperty[] getAllPropertiesWithSameDomainAs(ObjectProperty oP){ ObjectProperty[] oPz=new ObjectProperty[0]; OntClass[] domainClasses=listDomainClasses(oP); OntModel oM=oP.getOntModel(); ExtendedIterator it=oM.listObjectProperties(); while(it.hasNext()){ ObjectProperty oP2=(ObjectProperty)it.next(); if(oP2.getLocalName().compareTo(oP.getLocalName())!=0){ OntClass[] domainClasses2=listDomainClasses(oP2); if(isSubclass(domainClasses,domainClasses2)){ oPz=extendArray(oPz,oP2); } it.close(); return oPz; }
private String[] getAllSiblingClasses(OntClass Class2){ OntClass supClass=Class2.getSuperClass(); int iNoOfSubClasses=supClass.listSubClasses().toList().size(); String[] siblings = new String[iNoOfSubClasses-1]; int iCounter=0; for(int i=0; i<iNoOfSubClasses; i++){ OntClass oC=(OntClass)supClass.listSubClasses().toList().get(i); if(!oC.equals(Class2)){ siblings[iCounter]=oC.getLocalName(); iCounter++; } return siblings; }
ExtendedIterator iter = ontModel1.listDatatypeProperties(); while(iter.hasNext()){ DatatypeProperty dP= (DatatypeProperty)iter.next(); if(dP.getRange().getLocalName().compareTo("int")==0 || dP.getRange().getLocalName().compareTo("double")==0){ String[] sProt=new String[4]; ExtendedIterator iter3= ontModel1.listIndividuals(); while(iter3.hasNext()){ OntResource oRes =(OntResource)iter3.next(); NodeIterator sit=oRes.listPropertyValues(dP); while(sit.hasNext()){ com.hp.hpl.jena.rdf.model.impl.LiteralImpl pr=(com.hp.hpl.jena.rdf.model.impl.LiteralImpl)sit.next(); String sSubject=oRes.getLocalName(); String sObject=pr.getString(); String sPredicate=dP.getLocalName();
Internal Reasoning com.hp.hpl.jena.reasoner.ReasonerRegistry,mediocre reasoning ability Source Code Example: OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); com.hp.hpl.jena.reasoner.Reasoner reasoner1 = ReasonerRegistry.getOWLReasoner(); spec.setReasoner( reasoner1 ); ontTestModel = ModelFactory.createOntologyModel(spec, myModel); External Reasoning E.g.:Pellet Reasoner, complete reasoning ability Source Code Example OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); com.hp.hpl.jena.reasoner.Reasoner reasoner1 = PelletReasonerFactory.theInstance().create();spec.setReasoner( reasoner1 ); ontTestModel = ModelFactory.createOntologyModel(spec, myModel);
Jena used One in memory RDF model used A persistent model approach was initially introduced but was rejected Two in memory ontology models used One with a reasoner attached One without reasoner Pellet reasoner used is some occasions only to determine subsumptions between subclasses and superclasses and their individuals respectively
Only ontology files imported (OWL-DL) No alterations on the imported ontology Only Knowledge Extraction Use of this knowledge to create Multiple Choice Questions No SPARQL Queries developed
Limited use of the RDF API Used only to create ontology models and in some occasions to detect certain statements. Extended use of the Ontology API Knowledge extracted concerning: Classes Individuals Object Properties Datatype Properties
??????????????????????????????????????????????? ??????????????????__________?????????????????? ?????????????????/__________\???????????????? ????????????????/_/?????????\_\?????????????? ????????????????\_\?????????/_/?????????????? ?????????????????\_\??????/_/???????????????? ?????????????????????????/_/?????????????????? ???????????????????????/_/???????????????????? ??????????????????????|_|????????????????????? ??????????????????????????????????????????????? ??????????????????????????????????????????????? ??????????????????????|_|?????????????????????