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 gmail.com
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
(hasFather,1,clsSon);
But  I get as error
Exception in thread "main" java.lang.IllegalArgumentException
        at java.net.URI.create(URI.java:842)
        at owl.Family.main(Family.java:44)
Caused by: java.net.URISyntaxException: Illegal character in fragment at
index 48: http://www.co-ode.org/ontologies/testont.owl#Son#hasFather
        at java.net.URI$Parser.fail(URI.java:2809)
        at java.net.URI$Parser.checkChars(URI.java:2982)
        at java.net.URI$Parser.parse(URI.java:3028)
        at java.net.URI.<init>(URI.java:578)
        at java.net.URI.create(URI.java:840)
        ... 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.net.URI;
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("
http://www.co-ode.org/ontologies/testont.owl");
            // 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
URI
            SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI,
physicalURI);
            manager.addURIMapper(mapper);

            // 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 +
"#Son"));
            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 =
factory.getOWLObjectSomeRestriction(hasFather,clsSon);
            OWLDescription hasOneMother =
factory.getOWLObjectSomeRestriction(hasMother,clsSon);
            *
            // 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 =
factory.getOWLSubClassAxiom(clsSon,
hasOneFather);
            OWLSubClassAxiom restrictionMother =
factory.getOWLSubClassAxiom(clsSon,
hasOneMother);

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


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


             // 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
(ontology);
            System.out.println("Superclasses of " + clsSon + ":");
            for(OWLDescription desc : superClasses) {
                System.out.println(desc);
            }

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

        }
        catch (OWLException e) {
            e.printStackTrace();
        }
    }


Thanks a lot for the patience and sorry if I posted to the wrong list,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20071018/5b605b93/attachment.html>


More information about the protege-discussion mailing list