From: Stian Soiland-R. <soi...@cs...> - 2012-12-12 12:23:14
|
On Wed, Nov 21, 2012 at 10:50 AM, Stian Soiland-Reyes <soi...@cs...> wrote: > I can try to make a first cut, and then you can massage it to fit the > style of the OWL API. A "slightly less OO" approach with a separate > Builder class might be the way to go; I don't really want to wrap > OWLOntology and OWLIndividual etc. Here's my first attempt: https://github.com/myGrid/owl-individuals You can see how it works in this test: https://github.com/myGrid/owl-individuals/blob/master/owl-individuals-impl/src/test/java/uk/org/mygrid/owlindividuals/impl/TestFOAFPROV.java ..which replicates the use-case I said above using OWL API natively or through the "Individuals" builder class. For example: Individuals individuals = new IndividualsImpl(); individuals.setStrict(true); individuals.importOntology("prov", "http://www.w3.org/ns/prov#"); individuals.importOntology("foaf", "http://xmlns.com/foaf/0.1/"); OWLNamedIndividual index = individuals.createIndividual("<index.html>" ,"prov:Entity" ,"foaf:Document"); OWLNamedIndividual me = individuals.createIndividual( "<http://soiland-reyes.com/stian/#me>" ,"prov:Agent", "foaf:Person"); individuals.addObjectProperty(index, "prov:wasAttributedTo", me); individuals.addDataPropertyPlain(me, "foaf:givenName", "Soiland-Reyes"); testFile = Files.createTempFile("prov", ".ttl"); try (OutputStream outputStream = Files.newOutputStream(testFile)) { individuals.saveOntology(outputStream); } This produces: [ rdf:type owl:Ontology ; owl:imports <http://www.w3.org/ns/prov-o#> , foaf:null ] . <http://soiland-reyes.com/stian/#me> rdf:type owl:NamedIndividual , prov:Agent , foaf:Person ; foaf:givenName "Soiland-Reyes" . <index.html> rdf:type owl:NamedIndividual , prov:Entity , foaf:Document ; prov:wasAttributedTo <http://soiland-reyes.com/stian/#me> . If you enable a reasoner and use the fillInOntology() then additional clever things are included in the RDF saved, for instance you don't need to declare (all) the classes of the individuals as those would be evident from the domains and ranges. The strict-mode will bail out if you try to use properties and classes that don't exist. I've been considering adding a domain/range-super-strict option as well, forcing you to have declared the appropriate classes in advance and catching uses of wrong properties - this does however require a decent reasoner to be set - and as we know this does make the Maven dependencies a bit messier. I've tried to reduce the reasoned 'noise' so that you only get the reasoned information from your invididuals rather than what you could tell from the imported ontologies anyway. I did not call it *Builder - as it can also be used to retrieve properties - although it might make sense to split it into three (IndividualsBuilder, IndividualsReader and OntologyHelper or something). Another idea I had is to make a method: public OWLAnonymousIndividual addObjectProperty(OWLIndividual subject, String predicateCurie() ; to support anonymous nodes, for instance: individuals.addDatatProperty(individuals.addObjectProperty(s1, "p:p1"), "foaf:firstName", "Fred"); to form: :s1 p:p1 [ foaf:firstName "Fred" ] The actual builder is really just one file, plus the exceptions: https://github.com/myGrid/owl-individuals/blob/master/owl-individuals-impl/src/main/java/uk/org/mygrid/owlindividuals/impl/IndividualsImpl.java I've done an API/Impl split here as I intend to use this within an OSGi environment, but this is not really necessary - so if something like this was to be integrated into say owlapi-tools, then it could probably collapse to just a single class without interface. Any feedback and comments welcome. -- Stian Soiland-Reyes, myGrid team School of Computer Science The University of Manchester |