How can I add qualified cardinality restriction in Jena? I can not use createCardinalityQRestriction
because the OntModelSpec
is for the first version of OWL, not OWL2. In ModelFactory's createOntologyModel, is there a way to create an OWL2 ontology? I need a class expression like
JeVysledkom exactly 1 Kolik_Fazovy
I've tried using this code:
OntModel ontModel = ModelFactory.createOntologyModel();
OntClass ret = ontModel.createCardinalityQRestriction(null, ontProperty, cardinality, ontClass2 );
ontClass.addSuperClass(ret);
but I get this exception:
com.hp.hpl.jena.ontology.ProfileException: Attempted to use language construct CARDINALITY_Q that is not supported in the current language profile: OWL Full
I actually just ran into this while handling another question, Adding more complicated subclass axiom. Creating this in Jena is a little bit tricky because support for the qualified cardinality restrictions is an OWL2 feature, and Jena has limited support for OWL2:
Additionally, the Javadoc for the OWL2 vocabulary class says:
You might also see a response that I posted to the Jena mailing list about a similar question, Re: Owl maxCardinality restriction.
But you want to create one anyway? Then you're one of those “users who are doing OWL2 work with the current OWL1 support and desire a suitable set of names.” To find out how the OWL2 construction should be serialized in RDF, we need to take a look at OWL 2 Web Ontology Language Mapping to RDF Graphs (Second Edition), particularly section 2 Mapping from the Structural Specification to RDF Graphs, which tells us that the class expression
is serialized as the following set of triples
where
_:x
is the resource that is the class. The non-qualified case, which Jena already handles, turnsinto
If we had one of the latter, we could replace its
owl:cardinality
property with anowl:qualifiedCardinality
property, and add the appropriateowl:onClass
property. Here's some Java code that does just that:Output:
In Protégé: