ProtégéOWLAPI编程

时间:2015-09-26 20:08:40

标签: java jena owl protege owl-api

我的代码有问题我正在使用Protege OWL API(3.4.8)处理antologie文件,我希望用户在本体中定义所有类,问题是我一直有错误在for循环中我无法修复这些错误,有没有办法获得类。

 package Test;
 import java.util.Collection;
 import javax.swing.text.html.HTMLDocument.Iterator;
 import antlr.collections.List;
 import edu.stanford.smi.protege.model.Cls;
 import edu.stanford.smi.protegex.owl.ProtegeOWL;
 import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
 import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
 import edu.stanford.smi.protegex.owl.model.OWLIndividual;
 import edu.stanford.smi.protegex.owl.model.OWLModel;
 import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
 import edu.stanford.smi.protegex.owl.model.OWLObjectProperty;
 import edu.stanford.smi.protegex.owl.model.RDFSClass;
 public class Class4 {


 public static JenaOWLModel owlModel =null;
 public static String scorKos_Uri="C:/Users/souad/Desktop/SCOR-KOS.owl";
 //where  my ontologie file exist
 //change the URI by this       
 "http://protege.cim3.net/file/pub/ontologies/travel/travel.owl"; to have a    
  OWL file 



  /**
   * @param args
   */
   public static void main(String[] args) {
    /**
     * ontologie
     */

    try {
        owlModel=ProtegeOWL.createJenaOWLModelFromURI(scorKos_Uri);

        System.out.println("Worked");

        Collection classes = owlModel.getUserDefinedOWLNamedClasses();
        for (Iterator it = classes.iterator(); it.hasNext();) {
            OWLNamedClass cls = (OWLNamedClass) it.next();
            Collection instances = cls.getInstances(false);
            System.out.println("Class " + cls.getBrowserText() + " (" +                    
               instances.size() + ")");
            for (Iterator jt = instances.iterator(); jt.hasNext();) {
                OWLIndividual individual = (OWLIndividual) jt.next();
                System.out.println(" - " + individual.getBrowserText());
            }
        }

    }catch (Exception exception) {  
        System.out.println("Error can't upload the ontologie ");

        System.exit(1);
    }




  }

 }

1 个答案:

答案 0 :(得分:0)

您未导入java.util.Iterator