How to add qualified cardinality in JENA

Viewed 1647

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

3 Answers

Now there is also ONT-API, which is Jena extension for OWL2:

    String ns = "https://stackoverflow.com/q/20562107/1281433/";
    OntModel model = OntModelFactory.createModel()
            .setNsPrefixes(OntModelFactory.STANDARD)
            .setNsPrefix("test", ns);

    OntClass c = model.createOntClass(ns + "Kolik_Fazovy");
    OntObjectProperty p = model.createObjectProperty(ns + "JeVysledkom");
    model.createOntClass(ns + "Test").addSuperClass(model.createObjectCardinality(p, 1, c));

    // list all class expressions (2 owl classes, 1 restriction):
    Assert.assertEquals(3, model.ontObjects(OntClass.class).count());
    // print model
    model.write(System.out, "ttl");

The output:

@prefix test:  <https://stackoverflow.com/q/20562107/1281433/> .
@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#> .

test:Kolik_Fazovy  a  owl:Class .

test:JeVysledkom  a  owl:ObjectProperty .

test:Test  a             owl:Class ;
        rdfs:subClassOf  [ a                         owl:Restriction ;
                           owl:onClass               test:Kolik_Fazovy ;
                           owl:onProperty            test:JeVysledkom ;
                           owl:qualifiedCardinality  "1"^^xsd:nonNegativeInteger
                         ] .
Related