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.
- 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.
- 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.