[Pellet-users] listEquivalentClasses()

Evren Sirin evren at clarkparsia.com
Thu Mar 6 20:03:24 UTC 2008


On 3/5/08 11:16 PM, Anitha wrote:
>  HI Pellet Users,
>     I am using jena api and  edu.stanford.smi.protegex.owl.model.OWLModel 

In the below example, Protege OWLModel is not used at all but the 
problem has nothing to do with it anyway (see below).
> to extract the equivalent clasess from owl file
>
> My program:
> import java.io.*;
> import java.util.ArrayList;
> import java.util.HashSet;
> import java.util.List;
> import java.util.Iterator;
> import java.util.Map;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Set;
> import com.hp.hpl.jena.ontology.*;
> import com.hp.hpl.jena.rdf.model.*;
> import com.hp.hpl.jena.util.iterator.ExtendedIterator;
> import edu.stanford.smi.protegex.owl.model.OWLModel;
> public class test {
>  public static void main(String[] args) throws IOException,
>    InterruptedException {
>        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
>        String fname = "http://www.berkeleybop.org/ontologies/owl/bfo.owl";
>         m.read(fname);
>    for(Iterator i=m.listClasses();i.hasNext()){        
>     OntClass prop = i.next();
>        List<String> eqiclasses = new ArrayList<String>();
>        Iterator j1 = prop.listEquivalentClasses();
>           while( j1.hasNext() ) {
>                 OntClass equivClass = (OntClass) j1.next();
>                 eqiclasses.add(equivClass.getLocalName());
>           }
>         System.out.println("Class"+ prop.getLocalName() + " EQ:" + eqiclasses  + "from prop" + prop.listEquivalentClasses().toList());
>    }
>   
> }
>
>
> The output of this program.  returns the  following
> Class:ConnectedSpatiotemporalRegion EQ:[null] from prop [-391a75f9:1188239ebcb:-7fe3]
>
> I mean the classes Connected Spatio.. return some equivalent class list but when I try through the iterator it returns null. please help me to get all equivalent clasess
>   

Note that the iterator does not return null. Calling getLocalName on the 
resource returned by the iterator returns null because the resource is a 
bnode. It does not have a URI thus it cannot have a local name. If you 
don't want bnodes in your results you can filter them out completely 
(Resource.isAnon() will tell you if a resource is anonymous or not).

Also note that this is a Jena specific question and has nothing to do 
with Pellet. In this mailing list we provide support for Pellet. There 
is a Jena mailing list [1] for Jena questions.

Cheers,
Evren

[1] http://jena.sourceforge.net/support.html

> regards
> anitha
>
>
>       ____________________________________________________________________________________
> Looking for last minute shopping deals?  
> Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> _______________________________________________
> Pellet-users mailing list
> Pellet-users at lists.owldl.com
> http://lists.owldl.com/mailman/listinfo/pellet-users
> _______________________________________________
>
> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
>   



More information about the Pellet-users mailing list