Hi Emanuel,

Not with a direct method. You can obtain those sets with a modified version
of previous solution.

// create the ontology...
OntModel model = ModelFactory.createOntologyModel();
OntClass classA = model.createClass("http://bla.bla/A";);
OntClass classB = model.createClass("http://bla.bla/B";);
OntClass classC = model.createClass("http://bla.bla/C";);
OntClass classD = model.createClass("http://bla.bla/D";);

classA.addDisjointWith(classB);
classA.addDisjointWith(classC);

classC.addDisjointWith(classD);

// list disjoint sets...
ResIterator classesHasDisjoint = model
.listResourcesWithProperty(OWL.disjointWith);
while (classesHasDisjoint.hasNext()) {
OntClass cls = classesHasDisjoint.next().as(OntClass.class);
List<OntClass> disjointList = cls.listDisjointWith().toList();
disjointList.add(0, cls);
System.out.println(disjointList);
}

Console output:
[http://bla.bla/A, http://bla.bla/C, http://bla.bla/B]
[http://bla.bla/C, http://bla.bla/D]

Best,
Tayfun


2013/1/24 Emanuel Santos <[email protected]>

> Hi,
>
> Thanks for the reply!
>
> Maybe I was not clear.
>
> For instance, given these classes:
>
>     <owl:Class rdf:about="http://bla#A!>
>         <owl:disjointWith rdf:resource="http:/bla#B"/>
>         <owl:disjointWith rdf:resource="http:/bla#C"/>
>     </owl:Class>
>
>     <owl:Class rdf:about="http://bla#C";>
>         <owl:disjointWith rdf:resource="http:/bla#D"/>
>     </owl:Class>
>
> I want to obtain these sets : {A,B,C} and {C,D}.
> Only the direct classes.
>
> Thanks!
>
>
>
>
>
>
> On 24 January 2013 14:03, Fabio Aiub Sperotto <[email protected]>
> wrote:
>
> > Hi Emanuel,
> >
> > I don't know if I have a good solution for you (I'm not the best
> > programmer), but recently I made this: Search for all classes of
> ontology.
> > For each class X, return the set of classes that is disjoint with X:
> >
> >         model.read(new InputStreamReader(in), ""); //read the ontology
> >
> >         Iterator classes = model.listClasses(); //list all classes in
> > ontology
> >         while (classes.hasNext()){
> >             OntClass ontologyClass = (OntClass) classes.next(); //get one
> > class
> >
> >             //get list of disjoint classes from ontologyClass
> >             Iterator disjointClasses = ontologyClass.listDisjointWith();
> >
> >             while(disjointClasses.hasNext()){
> >             System.out.print("Class "+ontologyClass.getLocalName()+" is
> > disjoint with: ");
> >             System.out.println(disjointClasses.next());
> >             }
> >             System.out.println("");
> >
> >         }
> >
> > This will help? My some mistake?
> >
> >
> > 2013/1/24 Emanuel Santos <[email protected]>
> >
> > > Hi,
> > >
> > > I just started using Jena.
> > > Any easyway to get all set of classes "disjointWith" ?
> > >
> > > Thanks
> > >
> >
> >
> >
> > --
> > Fabio Aiub Sperotto
> > Mestrando em Modelagem Computacional
> > about.me/fabiosperotto
> > www.twitter.com/fabio_gk
> >
>

Reply via email to