简体   繁体   English

Protégé OWL API 编程

[英]Protégé OWL API programming

I have a problem with my code i'm working on an antologie file using Protege OWL API (3.4.8) and i want to have all the classes define by the user in the ontologie , the problem is i keep having errors in the for loop i can't fix those errors, is there any way to get the classes.我的代码有问题,我正在使用 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);
    }




  }

 }

您没有导入java.util.Iterator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM