简体   繁体   English

如何在 OWLAPI 中使用不同的词汇生成三元组

[英]How to produce triple with differentFrom vocab in OWLAPI

I tried to create different individual axiom using OWLAPI 5 in Java.我尝试在 Java 中使用 OWLAPI 5 创建不同的个人公理。 What I want is simple triple using vocab owl:differentFrom like:我想要的是使用 vocab owl:differentFrom 的简单三元组,例如:

test:A owl:differentFrom test:B

But what I get is triple using owl:AllDifferent:但我得到的是使用 owl:AllDifferent 的三倍:

_:genid234 rdf:type owl:AllDifferent
_:genid234 owl:distinctMembers _:genid236
_:genid236 rdf:rest _:genid235
_:genid236 rdf:rest rdf:nil
_:genid235 rdf:first test:A
_:genid235 rdf:type rdf:List
_:genid236 rdf:first test:B
_:genid236 rdf:type rdf:List

And the simple code is:简单的代码是:

OWLNamedIndividual op1 = factory.getOWLNamedIndividual(baseIRI + A);
OWLNamedIndividual op2 = factory.getOWLNamedIndividual(baseIRI + B);
ont.add(factory.getOWLDifferentIndividualsAxiom(op1, op2));

And I already tried it with Protege 5.5.0, it produce exactly the same triple as OWLAPI.我已经在 Protege 5.5.0 上尝试过,它产生的三元组与 OWLAPI 完全相同。

There is an alternative implementation of OWLAPI-v5 that provides a direct way to work with underlying RDF data - ONT-API (by the way, RDF based Protege version also exists). OWLAPI-v5 的替代实现提供了一种直接处理底层 RDF 数据的方法 - ONT-API (顺便说一下,基于 RDF 的 Protege 版本也存在)。 If working via OWLAPI interface for two operands it produces a single triple.如果通过 OWLAPI 接口为两个操作数工作,它会产生一个三元组。

Also it is possible to copy ontology between ont-api manager and owl-api-impl managers, if you prefer to store the data in the form of OWL axioms and need to solve only this particular problem with serialization.如果您更喜欢以 OWL 公理的形式存储数据并且只需要通过序列化解决这个特定问题,那么也可以在 ont-api 管理器和 owl-api-impl 管理器之间复制本体。

example:例子:

        String iri = "http://test#";
        OWLDataFactory factory = OntManagers.getDataFactory();
        Ontology ont = OntManagers.createManager().createOntology();
        ont.asGraphModel().setNsPrefix("test", iri);

        OWLNamedIndividual ia = factory.getOWLNamedIndividual(iri + "A");
        OWLNamedIndividual ib = factory.getOWLNamedIndividual(iri + "B");
        OWLNamedIndividual ic = factory.getOWLNamedIndividual(iri + "C");

        ont.add(factory.getOWLDifferentIndividualsAxiom(ia, ib, ic));

        ont.add(factory.getOWLDifferentIndividualsAxiom(ia, ic));

        OntModel g = ont.asGraphModel();

        g.createIndividual(iri + "D").addDifferentIndividual(g.createIndividual(iri + "C"));
        g.createDifferentIndividuals(g.createIndividual(iri + "e"), g.createIndividual(iri + "g"));

        g.write(System.out, "ttl");
        System.out.println("=".repeat(42));
        ont.axioms().forEach(System.out::println);

out:出去:

@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix test: <http://test#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

[ rdf:type     owl:AllDifferent ;
  owl:members  ( test:e test:g )
] .

test:g  rdf:type  owl:NamedIndividual .

test:B  rdf:type  owl:NamedIndividual .

[ rdf:type  owl:Ontology ] .

test:e  rdf:type  owl:NamedIndividual .

test:C  rdf:type  owl:NamedIndividual .

test:A  rdf:type           owl:NamedIndividual ;
        owl:differentFrom  test:C .

test:D  rdf:type           owl:NamedIndividual ;
        owl:differentFrom  test:C .

[ rdf:type             owl:AllDifferent ;
  owl:distinctMembers  ( test:A test:B test:C )
] .
==========================================
Declaration(NamedIndividual(test:g))
Declaration(NamedIndividual(test:e))
Declaration(NamedIndividual(test:D))
Declaration(NamedIndividual(test:C))
Declaration(NamedIndividual(test:B))
Declaration(NamedIndividual(test:A))
DifferentIndividuals(test:C test:D)
DifferentIndividuals(test:A test:C)
DifferentIndividuals(test:e test:g)
DifferentIndividuals(test:A test:B test:C)

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

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