0

I'm trying to build an OWL file programmatically from a data model, with OWL-API 3.5.0.

In general, the model follows the form of A -> B, where the relationship ("->") can be a subclass or a property.

I think I have the subclasses working, but I'm not sure how to add the following.

  1. Declarations. Protegé provides the following for IRIs:

<Declaration> <DataProperty IRI="#foo"/> </Declaration>

With OWL-API I don't see where this can happen at all.

  1. Cardinality and data type. I can get a reference to a cardinality, but I don't know what kind of Axiom to create such that I can add it to my ontology, and I'm not sure to what I should be adding it.

For a #Name, for example, I have a #firstName data property, and a #hasName as well. My current process is:

val topProperty = df.getOWLTopDataProperty val hasChild = df.getOWLDataProperty(exampleIRI + "#has" + concept.getName) val child = df.getOWLDataProperty(exampleIRI + "#" + concept.getName) m.applyChange(new AddAxiom(o, df.getOWLDeclarationAxiom(child))) val parentConcept = findConcept(concept.getRelated, concepts).get val parent = df.getOWLClass(exampleIRI + "#" + parentConcept.getName)

I try to set the data range with

val dataRange=df.getOWLDatatypeRestriction( df.getOWLDataType("string") val classExp = df.getOWLDataSomeValuesFrom(child, dataRange) m.applyChange(new AddAxiom(o, df.getOWLSubClassOfAxiom(parent, classExp)))

But this .. doesn't work properly. Protegé shows me that the cardinality is broken, and in protegé when I manually create the structure, it sets cardinality properly with a type of "&xsd;string", which my code does NOT replicate.

I think I understand how the ontologies are structured (and I'm painfully aware that I might not know how little I know), but I have a working OWL in Protegé (which can be converted to valid XSD, which is the end goal here); I just have no idea how to bridge the gaps between the Protegé-generated file and the OWL-API-generated content.

I tried using Jena, but it was even less clear to me, and Protegé supposedly has a client library that looks like it would be an excellent layer between OWL-API and my data model, but the Protegé library wouldn't build for me even from source, following their documentation.

Joseph Ottinger
  • 4,911
  • 1
  • 22
  • 23

1 Answers1

3

Declaration axioms

<Declaration>
   <DataProperty IRI="#foo"/>
</Declaration>

This kind of axiom is a declaration axiom. Have a look at OWLDeclarationAxiom and getOWLDeclarationAxiom(OWLEntity owlEntity). If you're already somewhat comfortable working with the OWLAPI, those links should be enough to get you going. Once you create the declaration axiom for the entity, you just add it to an ontology like any other axiom.

In fact, it looks like you're already doing this sort of stuff in your second Java code sample. If you're not getting the results that you expect, please provide a more concrete and minimal example of what's not working.

Cardinalities

I'm not quite sure what you're trying to accomplish here. That is, from your code, I'm not clear what axioms you're trying to end up with. It sounds like you've got something like a class Person and a property hasFirstName and you want to assert that

Person &sqsubseteq; =1 hasFirstName.String

in order to say that a Person has exactly one first name from the string datatype. There are two class expressions, Person and =1 hasFirstName.String, and then you just assert a subclass axiom between them. Getting a reference to the Person class and creating and adding the subclass axiom shouldn't be too hard, but the exact quantified cardinality restriction might be a bit tricky. For it, you'd use getOWLDataExactCardinality(cardinality, property, dataRange). You can get the datarange (xsd:string) that you need using either of the technique that Ignazio mentions in this answer:

OWLDatatype string = OWL2Datatype.XSD_STRING.getDatatype(df)
OWLDatatype string = df.getOWLDatatype(XSDVocabulary.parseShortName("xsd:string"));
Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • The declarations still aren't showing up even with adding the declaration axiom and applying it as a change. I'm going to create a github project and put the working files (and the OWL which I'm trying to recreate) in it, along with some other notes. – Joseph Ottinger Jan 10 '15 at 17:35
  • @JosephOttinger To be clear; after you created the declaration axiom, you did add it to the ontology, right? – Joshua Taylor Jan 10 '15 at 18:55
  • Yep, get the declaration, then apply changes via an AddAxiom. The github repo I'm using is: https://github.com/jottinger/ontology It does not use the datatypes yet, because of the cardinality and type issues I mentioned. The declarations are added, but not in the output. – Joseph Ottinger Jan 10 '15 at 20:22
  • I'm a beginner in Scala so I might have missed something, but in this file: https://github.com/jottinger/ontology/blob/master/src/main/scala/com/autumncode/ontology/Ontology.scala the only saveOntology call I see is in the toString method. Are you not seeing the declaration in the result of the toString call, or in an external file? – Ignazio Jan 11 '15 at 20:21