Search Mailing List Archives

Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-discussion] Unable to use OWLObjectExactCardinalityRestriction

Victor Silva vfbsilva at
Thu Oct 18 09:27:09 PDT 2007

Well I'm not sure if this is the exact list to ask but I'm quite sure you
can help me on this one.
I was trying the tutorial and I decided to modify the class hierarchy
example to modelate a family but I'm having problems to set up the relations
among the members.
The problem is I believe in the bold lines I don't want to use
SomeObjectRestriction what I do need, at least I think so, is
getOWLObjectExactCardinalityRestriction which the cardinality set to 1. But
this doesn't not compile here.
I tried
OWLDescription hasOneFather =factory.getOWLObjectExactCardinalityRestriction
But  I get as error
Exception in thread "main" java.lang.IllegalArgumentException
        at owl.Family.main(
Caused by: Illegal character in fragment at
index 48:
        ... 1 more
Java Result: 1

My source is:
import org.semanticweb.owl.model.*;
import org.semanticweb.owl.util.SimpleURIMapper;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.util.*;

import java.util.Set;

public class Family {

    public static void main(String[] args) {
        try {
            // We first need to obtain a copy of an OWLOntologyManager,
which, as the
            // name suggests, manages a set of ontologies.  An ontology is
unique within
            // an ontology manager.  To load multiple copies of an ontology,
multiple managers
            // would have to be used.
            OWLOntologyManager manager = OWLManager.createOWLOntologyManager

            URI ontologyURI = URI.create("");
            // Create a physical URI which can be resolved to point to where
our ontology will be saved.
            URI physicalURI = URI.create("file:/tmp/MyOnt.owl");
            // Set up a mapping, which maps the ontology URI to the physical
            SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI,

            // Now create the ontology - we use the ontology URI (not the
physical URI)
            OWLOntology ontology = manager.createOntology(ontologyURI);

            OWLDataFactory factory = manager.getOWLDataFactory();
            // Get hold of references to class SOn and class Father.  Note
that the ontology does not
            // contain class A or classB, we simply get references to
objects from a data factory that represent
            // class Son and class Father
            OWLClass clsSon = factory.getOWLClass(URI.create(ontologyURI +
            OWLClass clsFather = factory.getOWLClass(URI.create(ontologyURI
+ "#Father"));
            OWLClass clsMother = factory.getOWLClass(URI.create(ontologyURI
+ "#Mother"));
            // Now create the axiom
            OWLAxiom axiom = factory.getOWLSubClassAxiom(clsSon, clsFather);

            //Stating that each person must have a father and a mother
            OWLObjectProperty hasFather = factory.getOWLObjectProperty(
URI.create(clsSon.getURI() + "#hasFather"));
            OWLObjectProperty hasMother = factory.getOWLObjectProperty(
URI.create(clsSon.getURI() + "#hasMother"));
            OWLDescription hasOneFather =
            OWLDescription hasOneMother =
            // We now add the axiom to the ontology, so that the ontology
states that
            // Son is a subclass of Father.  To do this we create an
AddAxiom change object.
            OWLSubClassAxiom restrictionFather =
            OWLSubClassAxiom restrictionMother =

            AddAxiom addAxiom = new AddAxiom(ontology, axiom);
            // We now use the manager to apply the change

            axiom = factory.getOWLSubClassAxiom(clsSon, clsMother);
            addAxiom = new AddAxiom(ontology, axiom);

             // The ontology will now contain references to class Son and
class Father - let's
            // print them out
            for(OWLClass cls : ontology.getReferencedClasses()) {
                System.out.println("Referenced class: " + cls);
            // We should also find that Father and Mother are a superclasses
of son
            Set<OWLDescription> superClasses = clsSon.getSuperClasses
            System.out.println("Superclasses of " + clsSon + ":");
            for(OWLDescription desc : superClasses) {

            // Now save the ontology.  The ontology will be saved to the
location where
            // we loaded it fromé, in the default ontology format

        catch (OWLException e) {

Thanks a lot for the patience and sorry if I posted to the wrong list,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the protege-discussion mailing list