您好,欢迎访问三七文档
TheJenaRDFFrameworkKonstantinosTzonasContents•WhatisJena•CapabilitiesofJena•Basicnotions•RDFconceptsinJena•Persistence•Ontologymanagement•Reasoning•SPARQLQueryprocessingWhatisJena•JenaisaJavaframeworkforthecreationofapplicationsfortheSemanticWeb•ProvidesinterfacesandclassesforthecreationandmanipulationofRDFrepositories•Alsoprovidesclasses/interfacesforthemanagementofOWL-basedontologiesCapabilitiesofJena•RDFAPI•ReadingandwritinginRDF/XML,N-Triples•OWLAPI•In-memoryandpersistentstorage•SPARQLqueryengineRDFConcepts•Resources,Properties,Literals,Statements(Triples:subjpredobj)•Asetof(related)statementsconstituteanRDFgraph•TheJenaRDFAPIcontainsclassesandinterfacesforeveryimportantaspectoftheRDFspecification•TheycanbeusedinordertoconstructRDFgraphsfromscratch,oreditexistentgraphs•Theseclasses/interfacesresideinthecom.hp.hpl.jena.rdf.modelpackage•InJena,theModelinterfaceisusedtorepresentRDFgraphs•ThroughModel,statementscanbeobtained/created/removedetcRDFAPI-Example//CreateanemptymodelModelmodel=ModelFactory.createDefaultModel();Stringns=newString();//CreatetwoResourcesResourcejohn=model.createResource(ns+John);Resourcejane=model.createResource(ns+Jane);//Createthe'hasBrother'PropertydeclarationPropertyhasBrother=model.createProperty(ns,hasBrother);//Associatejanetojohnthrough'hasBrother'jane.addProperty(hasBrother,john);//Createthe'hasSister'PropertydeclarationPropertyhasSister=model.createProperty(ns,hasSister);//Associatejohnandjanethrough'hasSister'withaStatementStatementsisterStmt=model.createStatement(john,hasSister,jane);model.add(sisterStmt);Reading/Writingmodels•RDFModelscanberetrievedfromexternalsources(files/databases)•ExampleofaModelretrievedbyafile//ThelocationoftheRDFfileisspecifiedStringfileURI=“file:myRDF.rdf”;//AnemptyModeliscreatedModelmodelFromFile=ModelFactory.createDefaultModel();//TheModelretrievesthedefinitionsintheRDFfilemodelFromFile.read(fileURI);//ThedestinationandRDFdialectarespecifiedModel.write(System.out,“RDF/XML”)•ExampleofaModelbeingwrittentothestanadardoutputinRDF/XMLReadingfromdatabases•Thepackagecom.hp.hpl.jena.dbisusedtoprovidepersistentstorageofJenaModels•AccessingaModelinaMySQLDB:try{//LoadMySQLdriverClass.forName(com.mysql.jdbc.Driver);}catch(ClassNotFoundExceptione){...}//CreateadatabaseconnectionIDBConnectionconn=newDBConnection(jdbc:mysql://localhost/jenadb,“user”,“pass”,MySQL);ModelMakermaker=ModelFactory.createModelRDBMaker(conn);//RetrieveModelModeldbModel=maker.openModel(“);//ViewallthestatementsinthemodelastriplesStmtIteratoriter=dbModel.listStatements();while(iter.hasNext()){Statementstmt=(Statement)iter.next();System.out.println(stmt.asTriple().toString());}JenaOWLAPI•OWLisanextensiontoRDF.ThisrelationisreflectedintheJenaframework–OWLrelatedclasses/interfacesextendoruseclasses/interfacesoftheRDFAPI•PropertiesDatatypeproperties,Objectproperties,Symmetric,Functional,InverseFunctional…•ResourcesOntologyResourcesClasses,Individuals•Subclass-superclassrelations(fromRDFS)•Equivalency/Disjointness•Constraintsonproperties(AllValuesFrom,Min/MaxCardinalityrestrictions,etc)•TheOWLAPIofJenaprovidesclasses/interfacestorepresentallaspectsoftheOWLlanguage•Theseclasses/interfacesresideinthecom.hp.hpl.jena.ontologypackage•OntModelistheinterfacemostlyusedtomanageontologiesJenaOWLAPI•OntModel–Containsontologystatements–Canbeusedtoretrieveexistentresources(Classes,individuals,propertiesetc)orcreatenewones•ClassesarerepresentedbyOntClass–OntClassmethodscanbeusedtoviewtheinstances,superclasses,subclasses,restrictionsetcofaparticularclass•OntClassprovidesmethodsinordertoassertsubclass/superclassrelations,orclass/instancerelations•Classesmaybejust‘labels’underwhichindividualsarecategorized,buttheycanbemorecomplex,e.g.describedusingotherclassdefinitions–UnionClass,IntersectionClass,EnumeratedClass,ComplementClass,Restriction–TheOWLAPIprovideswaystodeterminewhetheraclassfallsononeoftheabovecategories–OntModelprovidesmethodstoconstructsuchcomplexdefinitionsJenaOWLAPI•PropertiesarerepresentedbyOntProperty–OntPropertyprovidesmethodstodefinethedomainsandrangesofproperties,aswellasdeterminethepropertytype–DatatypeProperty,ObjectProperty,SymmetricProperty,FunctionalPropertyetc–Subproperty/Superpropertyrelationscanbedefined•Propertiesaredefinedontheirown(i.e.,theyarenot‘tied’tocertainclasses,ashappensinframe-likesystems)•However,itisoftennecessarytoobtain‘thepropertiesofaspecificclass’.Thismeansfindingthepropertieswithadomain‘containing’thespecificclass.Jenaprovidesconveniencemethodsforsuchtasks.OWLAPIExample:Classes//CreateanemptyontologymodelOntModelontModel=ModelFactory.createOntologyModel();Stringns=newString(“”);StringbaseURI=newString(“”);Ontologyonto=ontModel.createOntology(baseURI);//Create‘Person’,‘MalePerson’and‘FemalePerson’classesOntClassperson=ontModel.createClass(ns+Person);OntClassmalePerson=ontModel.createClass(ns+MalePerson);OntClassfemalePerson=ontModel.
本文标题:Jena3
链接地址:https://www.777doc.com/doc-7174828 .html