From: Ignazio P. <ipa...@gm...> - 2012-11-20 17:27:27
|
On Nov 20, 2012 5:17 PM, "Stian Soiland-Reyes" < soi...@cs...> wrote: > > Hi! > > Do anyone know of any extension or wrapper of the OWL API for working > with individuals? > > My use case is to build some RDF documents using the OWL API that > defines individuals; as we've already got a set of (for this purpose > considered static) vocabularies defined in OWL. > > Think of it as making the RDF, and where the ontologies play the role of RDFS. > > > I've found that the OWL API is fast, lightweight, supports relative > URI references (!) and gives me quite good looking and complete RDF > documents. Doing anything similar with Jena or Sesame means I have to > 'unroll' the ontology in my head and state all the boring things.. > > > However, the OWL API is quite verbose in how you do something simple > like making: > > <index.html> a prov:Entity; > prov:wasAttributedTo <http://soiland-reyes.com/stian/#me> . > > <http://soiland-reyes.com/stian/#me> a foaf:Person, prov:Agent ; > foaf:name "Stian Soiland-Reyes" . > > > .. as I have to make a new individual, find the predicates (which > could accidentally create them), form a new axiom, and finally add it > to the ontology. Thanks to domain and ranges I often don't have to > specify the class(es) of the individuals, but it still ends up as what > looks like boilerplate code. > > > So I'm wondering if anyone has made or seen some kind of practical > "working with OWL individuals" API that wraps these kind of > operations? I'm picturing something like (pseudocode): > > > Ontology ontology = > makeAnonymousOntologyWithImports("http://www.w3.org/ns/prov#", > "http://xmlns.com/foaf/0.1/"); > // prefix manager populated with the prefixes used in imports by default > Individual index = ontology.makeIndividual("<index.html>", "prov:Entity"); > Individual me = > ontology.makeIndividual("<http://soiland-reyes.com/stian/#me>"); > index.addObjectProperty("prov:wasAttributedTo", me); > // set* as opposed to add* will remove any old foaf:name > me.setDataProperty("foaf:name", "Stian Soiland-Reyes"); > ontology.write(new File("prov.ttl"), "text/turtle"); > > This would raise RuntimeExceptions if I try to use classes or > properties that are not already defined in the imported ontologies, > rather than making new properties or classes, for instance because I > misspelt a term: > Welcome to the world of one's gold in another's compile error :-) that was considered a feature in the specs - up to a point, declarations of entities are elastic. But I'm still surprised you can create some by accident : do you have an example for that? > try { > ontology.makeIndividual("<text>", "prov:Enntity"); > } catch (UnknownClassException ex) { > // my N key is stuck! > } > > try { > index.addObjectProperty("foaf:wasAttributedTo", me); > } catch (UnknownPropertyException ex) { > // Args, should have been prov: prefix > } > > > However, I would not miss out on the inference of types for the > individual, so here it does not bail out because 'me' is not already a > prov:Agent, but simply adds this fact. > > index.addObjectProperty("prov:wasAttributedTo", me); > Well that would be a convenience wrapper around a data factory ; if you can fill in a feature request, we might be able to fit something in, like a builder class. I. > (But I can see some people might want that kind of 'strict' mode as well) > > > And for looking up: > ontology = loadOntology(new File("prov.ttl")); > for (Individual entity : ontology.getIndividualsOfClass("prov:Entity")) { > assertEquals("index.html", entity.getURI().asText()); > Invididual me = entity.getObjectProperty("prov:wasAttributedTo"); > > // Singular getters retrieve first and only individual (or null) > assertEquals("Stian Soiland-Reyes", me.getDataProperty("foaf:name")); > // while plural getters you get a (possibly empty) > list/set/collection back > assertEquals(Arrays.asList("Stian Soiland-Reyes"), > me.getDataProperties("foaf:name")); > } > > Similar to how you can add properties to an individual which is not > (yet) of the class of the property's domain, when retrieving I can ask > (wrongly or not) about properties of which domain this individual is > not an instance of - I would simply get null. (A 'strict' mode could > ensure that the individual was of a certain class, and only accept > properties which somewhat applied to individuals of that class). > > > I know some of these functions are already provided by the OWL API in > slightly different form, but often requiring you to also retrieve say > the class or the property as an object from the ontology first - and > easily accidentally making it. > > > > The reason I am asking, is that if there isn't anything like this, > then I'll likely write something like the above - and would welcome > any feedback, suggestions or other ways to do it. > > > > For reference, here is how I think I have to do the above using the > OWL API today: > > https://gist.github.com/4118712 > > As you see it is quite a bit more verbose than the pseudocode before I > refactor out commonalities. > > > Feel free to correct my code as I might have misunderstood something! > > > ( I also spent one hour struggling with foaf:name.. ;-) ) > > > -- > Stian Soiland-Reyes, myGrid team > School of Computer Science > The University of Manchester > > ------------------------------------------------------------------------------ > Monitor your physical, virtual and cloud infrastructure from a single > web console. Get in-depth insight into apps, servers, databases, vmware, > SAP, cloud infrastructure, etc. Download 30-day Free Trial. > Pricing starts from $795 for 25 servers or applications! > http://p.sf.net/sfu/zoho_dev2dev_nov > _______________________________________________ > Owlapi-developer mailing list > Owl...@li... > https://lists.sourceforge.net/lists/listinfo/owlapi-developer |