May I know if Apahe JENA supports OWL 2 syntax in Java? It does mentioned that in the documentation (https://jena.apache.org/documentation/ontology/) it only provide limited cardinality restrictions. I would like to confirm this from the experts.
UPDATE
Starting version 5.1.0 Jena does support OWL2. See jena-ontapi The example of how to work with this API remains the same, with the exception of imports.
PREVIOUS ANSWER
Apache Jena does not support OWL2, only OWL11 through org.apache.jena.ontology.OntModel interface. See also documentation.
But you still can work with OWL2 in Jena using some external jena-based APIs and tools, e.g. ONT-API, that is OWL-API-api(v5) impl over Jena.
In ONT-API there are two main OWL2 view of data, which encapsulate the same RDF Graph: com.github.owlcs.ontapi.jena.model.OntModel
and com.github.owlcs.ontapi.Ontology
(in older versions (ONT-API:v1.x.x) these classes have names ru.avicomp.ontapi.jena.model.OntGraphModel
and ru.avicomp.ontapi.OntologyModel
respectively).
The com.github.owlcs.ontapi.jena.model.OntModel view is a full analogue of Jena org.apache.jena.ontology.OntModel
, it is the facility to work with triples.
And the com.github.owlcs.ontapi.Ontology view is an extended org.semanticweb.owlapi.model.OWLOntology
, the facility to work with axiomatic data, that is backed by the com.github.owlcs.ontapi.jena.model.OntModel
view and vice-versa.
For example, the following snippet:
String uri = "https://stackoverflow.com/questions/54049750";
String ns = uri + "#";
OntModel m = OntModelFactory.createModel()
.setNsPrefixes(OntModelFactory.STANDARD).setNsPrefix("q", ns);
m.setID(uri);
OntClass c = m.createOntClass(ns + "c");
OntObjectProperty p = m.createObjectProperty(ns + "p");
OntIndividual i = c.createIndividual(ns + "i");
m.createObjectComplementOf(m.createObjectUnionOf(c, m.getOWLThing(),
m.createObjectSomeValuesFrom(p, m.createObjectOneOf(i))));
m.write(System.out, "ttl");
will produce the following ontology:
@prefix q: <https://stackoverflow.com/questions/54049750#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<https://stackoverflow.com/questions/54049750>
a owl:Ontology .
q:c a owl:Class .
q:p a owl:ObjectProperty .
q:i a owl:NamedIndividual , q:c .
[ a owl:Class ;
owl:complementOf [ a owl:Class ;
owl:unionOf ( q:c owl:Thing
[ a owl:Restriction ;
owl:onProperty q:p ;
owl:someValuesFrom [ a owl:Class ;
owl:oneOf ( q:i )
]
]
)
]
] .