使用 Protege API 编译代码时出错

发布于 2024-08-25 21:50:34 字数 2939 浏览 7 评论 0原文

我是 Protege API 的新手,我刚刚在 Eclipse 上创建了一个使用外部 OWL 文件的小型应用程序。我还导入了所有必要的库。

import java.util.Collection;
import java.util.Iterator;

import edu.stanford.smi.protege.exception.OntologyLoadException;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.*;

public class Trial {
    public static void main(String[] args) throws OntologyLoadException {
        String uri = "C:/Documents and Settings/Anto/Desktop/travel.owl";
        OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
        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());

            }
        }
    }
}

然而,当我编译时,我收到以下错误:

WARNING: [Local Folder Repository] The specified file must be a directory.      
(C:\Documents and Settings\Anto\My Documents\Eclipse 
Workspace\ProtegeTrial\plugins\edu.stanford.smi.protegex.owl) 
LocalFolderRepository.update()
SEVERE: Exception caught -- java.net.URISyntaxException: Illegal character in path at 
index 12: C:/Documents and Settings/CiuffreA/Desktop/travel.owl
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3066)
at java.net.URI$Parser.parse(URI.java:3014)
at java.net.URI.<init>(URI.java:578)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.getFileURI(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Trial.main(Trial.java:14)


Exception in thread "main" java.lang.NullPointerException
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Trial.main(Trial.java:14)

有人知道问题出在哪里吗?

I am new to Protege API and I have just created on Eclipse a small application which uses an external OWL file. Also I did import all the necessary libraries.

import java.util.Collection;
import java.util.Iterator;

import edu.stanford.smi.protege.exception.OntologyLoadException;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.*;

public class Trial {
    public static void main(String[] args) throws OntologyLoadException {
        String uri = "C:/Documents and Settings/Anto/Desktop/travel.owl";
        OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
        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());

            }
        }
    }
}

When I do compile however I get the following errors:

WARNING: [Local Folder Repository] The specified file must be a directory.      
(C:\Documents and Settings\Anto\My Documents\Eclipse 
Workspace\ProtegeTrial\plugins\edu.stanford.smi.protegex.owl) 
LocalFolderRepository.update()
SEVERE: Exception caught -- java.net.URISyntaxException: Illegal character in path at 
index 12: C:/Documents and Settings/CiuffreA/Desktop/travel.owl
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3066)
at java.net.URI$Parser.parse(URI.java:3014)
at java.net.URI.<init>(URI.java:578)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.getFileURI(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Trial.main(Trial.java:14)


Exception in thread "main" java.lang.NullPointerException
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Trial.main(Trial.java:14)

Does anyone have an idea on where the problem should be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕梦 2024-09-01 21:50:34

替换

String uri = "C:/Documents and Settings/Anto/Desktop/travel.owl";

String uri = "file:///C:/Documents and Settings/Anto/Desktop/travel.owl"; 

Replace

String uri = "C:/Documents and Settings/Anto/Desktop/travel.owl";

with

String uri = "file:///C:/Documents and Settings/Anto/Desktop/travel.owl"; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文