当前位置: 首页 > 知识库问答 >
问题:

保存本体后出现owl API错误

章锦
2023-03-14

输出给我抛出了这个错误:

Avertissement:   StandardWrapperValve[SearchPatient]: Servlet.service() for servlet SearchPatient threw exception
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at model.Ontology.lambda$null$6(Ontology.java:450)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at model.Ontology.lambda$searchPatient$7(Ontology.java:449)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at model.Ontology.searchPatient(Ontology.java:449)
at model.Ontology.getPatientInOntology(Ontology.java:144)
at com.mycompany.mavenwebapphadbpm.SearchPatient.processRequest(SearchPatient.java:57)
at com.mycompany.mavenwebapphadbpm.SearchPatient.doGet(SearchPatient.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:748)

我已经尝试按照OWL API示例中的说明进行保存,所以我不知道我的错误在哪里。

这是我用来保存本体的代码:

onto.saveOntology(onto.getFormat(), man.getOntologyDocumentIRI(onto));
public ArrayList<AddAxiom> addDataProperties(ArrayList<Info> data, OWLIndividual patient) {
    ArrayList<AddAxiom> axioms = new ArrayList<>();
    OWLDataFactory df = man.getOWLDataFactory();

    for (Info dp : data) {
        OWLDataProperty hasProp = df.getOWLDataProperty(IRI.create(owlIRI + "#" + dp.getRelation()));
        OWLDataPropertyAssertionAxiom axiom = null;
        System.out.println("Relation : " + dp.getRelation() + " valeur : " + dp.getValue());
        switch (dp.getType()) {
            case "String":
                axiom = df.getOWLDataPropertyAssertionAxiom(hasProp, patient, dp.getValue());
                break;
            case "int":
                axiom = df.getOWLDataPropertyAssertionAxiom(hasProp, patient, Integer.parseInt(dp.getValue()));
                break;
            case "float":
                axiom = df.getOWLDataPropertyAssertionAxiom(hasProp, patient, Float.parseFloat(dp.getValue()));
                break;
            case "boolean":
                if (dp.getValue() == null) {
                    axiom = df.getOWLDataPropertyAssertionAxiom(hasProp, patient, false);
                } else {
                    axiom = df.getOWLDataPropertyAssertionAxiom(hasProp, patient, true);
                }
                break;
        }
        AddAxiom addAxiom = new AddAxiom(onto, axiom);
        axioms.add(addAxiom);

    }

    return axioms;
}
public void addPatientIndividual(ArrayList<Info> data, String name) {
    OWLDataFactory df = man.getOWLDataFactory();

    // Actor's IRI
    OWLClass actorIRI = df.getOWLClass(IRI.create(owlIRI + "#Patient"));

    // Patient individual
    OWLIndividual patient = df.getOWLNamedIndividual(IRI.create(owlIRI + "#" + name));

    // Create a link between the class patient and the individual
    OWLClassAssertionAxiom type = df.getOWLClassAssertionAxiom(actorIRI, patient);
    // Create the axiom corresponding to the link between the patient and the
    // individual
    AddAxiom axiomType = new AddAxiom(onto, type);
    // Add the former link to the ontology
    man.applyChange(axiomType);

    // Disease individual
    OWLIndividual disease = df.getOWLNamedIndividual(owlIRI + "#" + ((Info) data.get(0)).getValue());
    // Create the property which is already in the owl the name of the patient to
    // the individual
    OWLObjectProperty hasDisease = df.getOWLObjectProperty(owlIRI + "#hasDisease");
    // Link the disease to the patient
    OWLObjectPropertyAssertionAxiom axiomHasDisease = df.getOWLObjectPropertyAssertionAxiom(hasDisease, patient,
            disease);
    // Create the axiom
    AddAxiom addAxiomHasDisease = new AddAxiom(onto, axiomHasDisease);
    // Apply the axiom to the ontology
    man.applyChange(addAxiomHasDisease);

    // Delete the axiom of the disease
    data.remove(data.get(0));

    for (AddAxiom axiom : addDataProperties(data, patient)) {
        man.applyChange(axiom);
    }

    // Save the ontology
    try {
        //System.out.println("coucou");
        //this.onto.saveOntology(); // PLENTE
        //this.getOntology().saveOntology(); // PLENTE
        //this.getOntology().saveOntology(this.getOntology().getFormat()); // PLENTE
        //manager.saveOntology(onto); // NE FAIS RIENT
        //onto.getOWLOntologyManager().saveOntology(onto); // Enregistre puis lecture impossible
        //onto.saveOntology(onto.getFormat(), manager.getOntologyDocumentIRI(onto));
        //System.out.println(manager.getOntologyDocumentIRI(this.getOntology()));
        //System.out.println(owlIRI);
        //System.out.println(onto.getOntologyID().getVersionIRI());
        //man.saveOntology(onto, onto.getFormat().asPrefixOWLDocumentFormat()); // MARCHE TOUJOURS PAS
        //man.saveOntology(onto);
        //this.getOntology().saveOntology(); // MARCHE PAS
        onto.saveOntology(onto.getFormat(), man.getOntologyDocumentIRI(onto));
        System.out.print("Sauvegarde ?????");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("-/-/-/-/-/-/-/-/-/-/-/-PLENTE-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-");
    }

} 
public Patient searchPatient(String id, OWLReasoner reasoner) {
    Patient pat = new Patient();
    onto.individualsInSignature().forEach(i -> onto.dataPropertiesInSignature().forEach(p -> {
        if (i.getIRI().getRemainder().get().equals(id)) {
            pat.setId(id);

            Set<OWLLiteral> prop = reasoner.getDataPropertyValues(i, p);
            Set<OWLLiteral> values = asUnorderedSet(prop.parallelStream());

            for (OWLLiteral v : values) {
                if (p.getIRI().getRemainder().get().equals("hasFirstName")) {
                    pat.setHasFirstName(v.getLiteral());
                }
                if (p.getIRI().getRemainder().get().equals("hasName")) {
                    pat.setHasName(v.getLiteral());
                }
            }

        }

    }));
    return pat;
}

和getPatient的代码

public ArrayList<Patient> getPatientInOntology(OWLReasoner reasoner, String individualName) {
    ArrayList<Patient> pats = new ArrayList<>();
    //ArrayList<String> liste = new ArrayList<>();
    onto.classesInSignature().forEach(c -> {
        if (c.getIRI().getFragment().equals(individualName)) {
            patient = c;
        }
    });

    // Display all the individual
    for (OWLNamedIndividual cls : reasoner.getInstances(patient).getFlattened()) {
        //liste.add(cls.getIRI().getRemainder().get());
        //pats.add()

        //System.out.println("cls : " + cls.getIRI().getRemainder().get());
        pats.add(searchPatient(cls.getIRI().getRemainder().get(), reasoner));
    }

    return pats;
}

共有1个答案

殷安顺
2023-03-14

我知道我的案子哪里出错了。

事实上,问题是我使用的方法。在新的owl API中,.getRemaider().get()取代了不推荐使用的.getFragment()。

在我的代码中,行:

pats.add(searchPatient(cls.getIRI().getRemainder().get(), reasoner));
pats.add(searchPatient(cls.getIRI().getFragment(), reasoner));
 类似资料:
  • 我正在为一个项目使用OWLAPI,我需要比较两个本体之间的差异。这将忽略空节点,例如,我可以确定两个本体中是否存在相同的OWL限制。我不仅需要知道是否存在差异,而且需要找出那些差异是什么。OWLAPI和oz中是否存在这样的功能,有没有一个相对简单的方法来实现这一点?

  • 我将OWLAPI与HermiT一起使用,除非在创建了推理器之后尝试修改本体,否则它是有效的。

  • 在这个问题中,我正在使用Hibernate 4.3.4。最终和SpringORM 4.1.2。释放。 我有一个User类,它包含这样的一组Card实例: 我有几种类型的卡,每种都分别扩展Card基类和CardInstance基类,如下所示: 如果我将UnitCardInstance或HeroCardInstance添加到cards集合并保存实体,则一切正常。但是,如果我向集合中添加AbilityC

  • applyChange()方法总是返回“unsuccessful”,我找不到任何关于注释删除不起作用的文档。 注:在http://sourceforge.net/p/owlapi/mailman/message/28203984/here似乎起作用

  • 我得到这样的错误消息:线程“awt-eventqueue-0”org.apache.jena.riot.riotexception:[line:1,col:1]Prolog中不允许内容。当我试图通过NetBeans用java加载本地本体文件时?请问这是什么意思,我该怎么做?

  • 我正在开发一个maven插件来使用OWL-APIV3.4.3和HermiT 1.3.8.4验证OWL本体。一些OWL本体是专有的,因此在Web上不可用。 查看文档,我正在使用加载OWL文件以执行验证: 当本体不导入任何专有本体,但否则返回error时,此操作很好。我见过有人使用在本体URI和定义实体的物理文件之间创建链接,但我认为这在我的情况下行不通(主要是因为文件名未知)。 有没有办法告诉OWL