【问题标题】:Protégé OWL API programmingProtégé OWL API 编程
【发布时间】:2015-09-26 20:08:40
【问题描述】:

我的代码有问题,我正在使用 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);
    }




  }

 }

【问题讨论】:

  • 添加 exception.printStackTrace() 会有所帮助
  • 我什至无法编译我在 (Iterator it = classes.iterator(); it.hasNext();) 中有错误的代码,建议将 hasNext 更改为 next(),我也这里有一个错误 (OWLNamedClass cls = (OWLNamedClass) it.next();) 我认为是演员表的问题,但我不能把它转换成别的东西

标签: java jena owl protege owl-api


【解决方案1】:

您没有导入java.util.Iterator。

【讨论】:

    猜你喜欢
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多