添加更复杂的子类公理 [英] Adding more complicated subclass axiom

查看:87
本文介绍了添加更复杂的子类公理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了另一个问题...

I have stumbled upon another problem...

我想要达到类似的效果:

I want to achieve something similar to this:

我想使用RDFList这样做,将必要的属性添加到列表然后调用方法createUnionClass(或createIntersectionClass)并将它们组合在一起。然后,使用addSuperClass()将此方法的结果添加到特定的ontClass。

I wanted to do so using RDFList, adding the necessary properties in to the list and then call method createUnionClass (or createIntersectionClass) and combine it together. Then, the result of this method would be added to particular ontClass with addSuperClass().

这是错误的吗?我已经开始使用非常简单的东西,例如:

Is this wrong? I have started with something really simple, like:

RDFList rdfList = ontModel.createList();
rdfList.addProperty(ExampleResource1);
rdfList.addProperty(ExampleResource2); 
UnionClass uc = ontModel.createUnionClass(null, rdfList);
ExampleClass.addSuperClass(uc);

但结果不是之前所述的两个联合的subClassOf,而只是subClassOf为零。

But the result was not the subClassOf the union of both stated before, but only subClassOf nil.

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

在耶拿创建有点棘手,因为支持合格的基数限制是一个OWL2功能,而Jena对OWL2的支持有限:

Creating this in Jena is a little bit tricky because support for the qualified cardinality restrictions is an OWL2 feature, and Jena has limited support for OWL2:


Jena Ontology API



请注意,at目前,Jena本体API仅对OWL2的合格基数限制(即cardinalityQ,
minCardinalityQ和maxCardinalityQ)提供有限的支持
。合格的基数
限制封装在接口
CardinalityQRestriction,MinCardinalityQRestriction和
CardinalityQRestriction中。 OntModel还提供了创建
和访问限定基数限制的方法。由于它们不是OWL 1.0语言定义的
部分,因此OWL本体不支持合格的基数
限制。 OWL 2更新中添加了合格的
基数限制。 Jena的OWL2支持
将在适当的时候添加。

Jena Ontology API

Note that, at present, the Jena ontology API has only limited support for OWL2's qualified cardinality restrictions (i.e. cardinalityQ, minCardinalityQ and maxCardinalityQ). Qualified cardinality restrictions are encapsulated in the interfaces CardinalityQRestriction, MinCardinalityQRestriction and CardinalityQRestriction. OntModel also provides methods for creating and accessing qualified cardinality restrictions. Since they are not part of the OWL 1.0 language definition, qualified cardinality restrictions are not supported in OWL ontologies. Qualified cardinality restrictions were added to the OWL 2 update. OWL2 support in Jena will be added in due course.

您可能还会看到我发布到Jena邮件的回复关于类似问题的列表, Re:Owl maxCardinality限制

You might also see response that I posted to the Jena mailing list about a similar question, Re: Owl maxCardinality restriction.

但是,您可以使用以下Java代码。 3。是我们希望能够编写的代码,但我们最终不得不使用 3a。相反。你可以去开始挖掘RDF序列化,从而获得真正的合格限制。我已经向您展示了如何在相关问题中执行此操作:如何在JENA中添加合格的基数

You can come pretty close with the following Java code, though. 3. is the code that we'd like to be able to write, but we end up having to use 3a. instead. You could go and start digging around in RDF serialization and thereby get yourself a genuine qualified restriction. I've shown how you can do that in a related question: How to add qualified cardinality in JENA.

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;

public class UnionClassExample {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        String NS = "https://stackoverflow.com/q/20561994/1281433/";
        OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
        model.setNsPrefix( "so", NS );

        OntClass a = model.createClass( NS+"A" );
        OntClass b = model.createClass( NS+"B" );
        OntClass c = model.createClass( NS+"C" );

        OntProperty p = model.createObjectProperty( NS+"p" );
        OntProperty q = model.createObjectProperty( NS+"q" );

        // 1. B or C
        OntClass b_or_c = model.createUnionClass( null, model.createList( new RDFNode[] { b, c } ));

        // 2. p only (B or C)
        OntClass p_only_b_or_c = model.createAllValuesFromRestriction( null, p, b_or_c );

        // 3. q exactly 1 C
        // OntClass q_exactly_1_C = model.createCardinalityQRestriction( null, q, 1, c );

        // 3a. q exactly 1
        OntClass q_exactly_1 = model.createCardinalityRestriction( null, q, 1 );

        // (2) and (3a)
        OntClass _2_and_3a = model.createIntersectionClass( null, model.createList( new RDFNode[] { p_only_b_or_c, q_exactly_1 } ));

        // a subClassOf ((p only (B or C)) and (q exactly 1))
        a.addSuperClass( _2_and_3a );

        model.write( System.out, "RDF/XML-ABBREV" );
    }
}

输出:

<rdf:RDF
    xmlns:so="https://stackoverflow.com/q/20561994/1281433/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Class rdf:about="https://stackoverflow.com/q/20561994/1281433/A">
    <rdfs:subClassOf>
      <owl:Class>
        <owl:intersectionOf rdf:parseType="Collection">
          <owl:Restriction>
            <owl:allValuesFrom>
              <owl:Class>
                <owl:unionOf rdf:parseType="Collection">
                  <owl:Class rdf:about="https://stackoverflow.com/q/20561994/1281433/B"/>
                  <owl:Class rdf:about="https://stackoverflow.com/q/20561994/1281433/C"/>
                </owl:unionOf>
              </owl:Class>
            </owl:allValuesFrom>
            <owl:onProperty>
              <owl:ObjectProperty rdf:about="https://stackoverflow.com/q/20561994/1281433/p"/>
            </owl:onProperty>
          </owl:Restriction>
          <owl:Restriction>
            <owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
            >1</owl:cardinality>
            <owl:onProperty>
              <owl:ObjectProperty rdf:about="https://stackoverflow.com/q/20561994/1281433/q"/>
            </owl:onProperty>
          </owl:Restriction>
        </owl:intersectionOf>
      </owl:Class>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>

加载到Protégé:

Loaded into Protégé:

这篇关于添加更复杂的子类公理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆