JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations ›...
Transcript of JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations ›...
![Page 1: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/1.jpg)
JENA–ASEMANTICWEBTOOL
byRanjaniSankaran
&krishnaPriyankaChebrolu
![Page 2: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/2.jpg)
RDF
• ResourceDescriptorFramework• W3CStandardfordescribingresourcesontheweb.
• IsdesignedtoprovidecommonwaytodescribeinformaNonsoitcanbereadandunderstoodbycomputerapplicaNon.
![Page 3: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/3.jpg)
• WhatisJena• CapabiliNesofJena• RDFImplementaNonusingJena
![Page 4: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/4.jpg)
WhatisJena
• JenaisaJavaframeworkforthecreaNonofapplicaNonsfortheSemanNcWeb.
• ProvidesinterfacesandclassesforthecreaNonandmanipulaNonofRDFrepositories.
• Alsoprovidesclasses/interfacesforthemanagementofOWL‐basedontologies
![Page 5: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/5.jpg)
CapabiliNesofJena
• RDFAPI• ReadingandwriNnginRDF/XML,N‐Triples
• OWLAPI
• In‐memoryandpersistentstorage
• SPARQLqueryengine
![Page 6: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/6.jpg)
RDFImplementaNonusingJena
![Page 7: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/7.jpg)
RDFAPI‐Example• HelloWorldExample:importcom.hp.hpl.jena.rdf.model.Model;importcom.hp.hpl.jena.datatypes.xsd.XSDDatatype;importcom.hp.hpl.jena.rdf.model.ModelFactory;importcom.hp.hpl.jena.rdf.model.Property;importcom.hp.hpl.jena.rdf.model.Resource;publicclassHelloRDFWorld{
publicstaNcvoidmain(String[]args){ Modelm=ModelFactory.createDefaultModel(); StringNS="h`p://example.com/test/"; Resourcer=m.createResource(NS+"r"); Propertyp=m.createProperty(NS+"p"); r.addProperty(p,"helloworld",XSDDatatype.XSDstring); m.write(System.out,"Turtle"); }
}
![Page 8: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/8.jpg)
RDFAPI–Examplecond..
• //NamespacedeclaraNonssta$cfinalStringfamilyUri="h-p://1nman.cs.gsu.edu#";• //CreateanemptyModelmodel=ModelFactory.createDefaultModel();model.setNsPrefix("student","h`p://Nnman.cs.gsu.edu#");• //CreateanemptyModelmodel=ModelFactory.createDefaultModel();model.setNsPrefix("student","h`p://Nnman.cs.gsu.edu#");• //CreateresourcesrepresenNngthepeopleinourmodelResourceranjani=model.createResource(familyUri
+"Ranjani");
•
![Page 9: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/9.jpg)
RDFAPI‐ExampleCont..• //AddproperNestodescribingtherelaNonshipsbetweenthemranjani.addProperty(fullname,"RanjaniSankaran");• //Statementscanalsobedirectlycreated...Statementstatement1=
model.createStatement(ranjani,college,"gsu");• //...thenaddedtothemodel:model.add(statement1);• //ArraysofStatementscanalsobeaddedtoaModel:Statementstatements[]=newStatement[5];statements[0]=model.createStatement(ranjani,major,"csc");model.add(statements);
![Page 10: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/10.jpg)
RDFAPI‐Contd..
• //AListofStatementscanalsobeaddedListlist=newArrayList();list.add(model.createStatement(ranjani,course,"DBandtheWeb"));
• model.add(list);
model.write(newPrintWriter(System.out));
![Page 11: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/11.jpg)
RDFRepresentaNonofVcard
• AnalternaNveRDFmappingfortheformatdefinedbyvCard
![Page 12: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/12.jpg)
QueryingRDFusingJENA//ListstudentswhohavetakenacourseResIteratorstudents_course=model.listSubjectsWithProperty(course);
//BecausesubjectsofstatementsareResources,themethodreturnedaResIterator
while(students_course.hasNext()){
//ResIteratorhasatypednextResource()methodResourceperson=students_course.nextResource();
//PrinttheURIoftheresourceSystem.out.println("Thelistofstudentswhohavetaken
coures"+person.getURI());}
![Page 13: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/13.jpg)
QueryingRDFusingJENAcontd..
//Tofindallthecoursestakenbyastudent,themodelitselfcanbequeried
NodeIteratormoreStudents1=model.listObjectsOfProperty(priyanka,course);
System.out.println("****LISTOFCOURSESTAKENBYPRIYANKA***");
while(moreStudents1.hasNext()){
System.out.println(moreStudents1.nextNode().toString());}
![Page 14: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/14.jpg)
RDFValidator• ValidatestheformatofRDFdocumentscreatedusingJENApublicstaNcvoidmain(Stringargs[]){ Modeldata=FileManager.get().loadModel("student.rdf");InfModelinfmodel=ModelFactory.createRDFSModel(data);ValidityReportvalidity=infmodel.validate();if(validity.isValid()){System.out.println("OK");}else{System.out.println("Conflicts");for(Iteratori=validity.getReports();i.hasNext();){System.out.println("‐"+i.next());
![Page 15: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/15.jpg)
JENAONTOLOGYMODEL
• AnontologymodelisanextensionoftheJenaRDFmodelthatprovidesextracapabiliNesforhandlingontologies.OntologymodelsarecreatedthroughtheJenaModelFactory.Thesimplestwaytocreateanontologymodelisasfollows:
• OntModelm=ModelFactory.createOntologyModel();Thiswillcreateanontologymodelwiththedefaultsenngs,whicharesetformaximumcompaNbilitywiththepreviousversionofJena.
![Page 16: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/16.jpg)
OWLAPI//CreateanemptyontologymodelOntModelontModel=ModelFactory.createOntologyModel();Stringns=newString(“h`p://www.example.com/onto1#”);StringbaseURI=newString(“h`p://www.example.com/onto1”);Ontologyonto=ontModel.createOntology(baseURI);
//Create‘Person’,‘MalePerson’and‘FemalePerson’classesOntClassperson=ontModel.createClass(ns+"Person");OntClassmalePerson=ontModel.createClass(ns+"MalePerson");OntClassfemalePerson=ontModel.createClass(ns+"FemalePerson");
//FemalePersonandMalePersonaresubclassesofPersonperson.addSubClass(malePerson);person.addSubClass(femalePerson);
//FemalePersonandMalePersonaredisjointmalePerson.addDisjointWith(femalePerson);femalePerson.addDisjointWith(malePerson);
![Page 17: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/17.jpg)
OWLAPI‐ProperNes//Createdatatypeproperty'hasAge'DatatypePropertyhasAge=ontModel.createDatatypeProperty(ns+"hasAge");//'hasAge'takesintegervalues,soitsrangeis'integer'//Basicdatatypesaredefinedinthe‘vocabulary’packagehasAge.setDomain(person);hasAge.setRange(XSD.integer);//com.hp.hpl.jena.vocabulary.XSD
//CreateindividualsIndividualjohn=malePerson.createIndividual(ns+"John");Individualjane=femalePerson.createIndividual(ns+"Jane");Individualbob=malePerson.createIndividual(ns+"Bob");
//Createstatement'JohnhasAge20'Literalage20=ontModel.createTypedLiteral("20",XSDDatatype.XSDint);StatementjohnIs20=ontModel.createStatement(john,hasAge,age20);ontModel.add(johnIs20);
![Page 18: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/18.jpg)
Reasoning
• Jenaisdesignedsothatinferenceenginescanbe‘plugged’inModelsandreasonwiththem.
• ThereasoningsubsystemofJenaisfoundinthecom.hp.hpl.jena.reasonerpackage.
• AllreasonersmustprovideimplementaNonsofthe‘Reasoner’Javainterface
• OnceaReasonerobjectisobtained,itmustbe‘a`ached’toaModel.ThisisaccomplishedbymodifyingtheModelspecificaNons
![Page 19: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/19.jpg)
Reasoning‐OWLexample
• Asampleschemaandadatafilearetaken.• WecancreateaninstanceoftheOWLreasoner,specializedtotheschemaandthenapplythattothedatatoobtainaninferencemodel.
![Page 20: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/20.jpg)
Reasoning‐Example
Modelschema=FileManager.get().loadModel("owlDemoSchema.owl");
Modeldata=FileManager.get().loadModel("owlDemoData.rdf");
Reasonerreasoner=ReasonerRegistry.getOWLReasoner();
reasoner=reasoner.bindSchema(schema);InfModelinfmodel=ModelFactory.createInfModel(reasoner,data);
![Page 21: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/21.jpg)
SPARQLqueryprocessing• JenausestheARQenginefortheprocessingofSPARQLqueriesThe
ARQAPIclassesarefoundincom.hp.hpl.jena.query• BasicclassesinARQ:Query:RepresentsasingleSPARQLquery.• Dataset:Theknowledgebaseonwhichqueriesareexecuted
(EquivalenttoRDFModels)• QueryFactory:CanbeusedtogenerateQueryobjectsfromSPARQL
strings• QueryExecuNon:ProvidesmethodsfortheexecuNonofqueries• ResultSet:Containstheresultsobtainedfromanexecutedquery• QuerySoluNon:Representsarowofqueryresults.
– Iftherearemanyanswerstoaquery,aResultSetisreturnedauerthequeryisexecuted.TheResultSetcontainsmanyQuerySoluNons
![Page 22: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/22.jpg)
SPARQLQUERY‐Example//CreateanewqueryStringqueryString="PREFIXrdfs:<h`p://www.w3.org/2000/01/rdf‐schema#>"+"PREFIXrdf:<h`p://www.w3.org/1999/02/22‐rdf‐syntax‐ns#>"+"select?uri"+"where{"+"?urirdfs:subClassOf<h`p://www.opentox.org/api/1.1#Feature>
"+"}\n";com.hp.hpl.jena.query.Queryquery=
QueryFactory.create(queryString);
![Page 23: JENA –A SEMANTIC WEB TOOLtinman.cs.gsu.edu › ~raj › 8711 › sp11 › presentations › jenaPresentation.pdf• Jena is designed so that inference engines can be ‘plugged’](https://reader033.fdocuments.us/reader033/viewer/2022060510/5f273f3983e8b51ee439fba7/html5/thumbnails/23.jpg)
References
• IntroducNontoJENA
• JenaOntologyAPI
h`p://jena.sourceforge.net/ontology/#creaNngModels