使用Jena的OWL本体谓词逻辑 [英] OWL Ontology Predicate Logic with Jena

查看:89
本文介绍了使用Jena的OWL本体谓词逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在本体论中表达以下情况:

I'm having trouble expressing the following situation in my Ontology:

假设我有四人投票和四票(因此,投票和选民之间是一对一的映射).人们可以投票赞成或反对.如果我知道三人投票的结果,我应该能够推断出第四人的投票.

Suppose I have four people voting and four votes (so there is a one-to-one mapping between vote and voter). People can either vote yes or no. If I know the outcome of three people's votes, I ought to be able to deduce the fourth person's vote.

重申一下:约翰,鲍勃,玛丽和卡罗尔各投一票.由于有四个人,所以有四票.投票的结果是平局(2赞成和2反对).后来,推理机确定鲍勃和约翰投了反对票.然后,推理机应该能够推断出玛丽和卡罗尔投了赞成票.

So to reiterate: John, Bob, Mary, and Carol each vote. Since there are four people there are four votes. The outcome of the vote is a tie (2 yes, and 2 no). Later on the reasoner determines that Bob and John voted no. The reasoner should then be able to deduce that Mary and Carol voted yes.

目前,我正在使用Jena的Java API构建本体,并使用Jena推理程序进行推理,所以我宁愿使用Jena支持的规则/语义.

Currently I am building my ontology using Jena's java api and am inferencing with a Jena reasoner, so I'd rather use rules/semantics supported by Jena.

推荐答案

Antoine Zimmerman的答案就是这样的事物在OWL中是可表示的,但是它比您预期的需要更多的工作,因为您正在尝试强制使用封闭世界推理和默认推理,而OWL使开放世界假设,如果您不了解某些内容,则不能假定它是对还是错,只是未知.但是,一旦闭合公理到位,就很难编写一个方案了.我认为有必要逐步解决此问题,以查看进行推理所需的所有公理,并在OWL DL中进行.您没有提到Protégé,但这是一个非常方便的OWL编辑器,使编写这些公理变得更加容易.我还将在最后显示最终的OWL(在RDF/XML和Turtle中).

Antoine Zimmerman's answer is right in that this kind of thing is expressible in OWL, but that it requires a bit more work than you might expect, because you're trying to enforce a type of closed world reasoning and default reasoning, whereas OWL makes the open world assumption in which if you don't know something, it's not presumed to be either true or false, just unknown. Once the closure axioms are in place though, this isn't too hard of a scenario to write. I think it's worth working through this problem step by step to see all the axioms that need to be present in order to make this inference, and to do this in OWL DL. You didn't mention Protégé, but it's a very convenient OWL editor, and makes writing these axioms much easier. I'll show the final OWL (in RDF/XML and Turtle) at the end, too.

仅代表一个实例,我将声明一个类的Voters,成员是Alice,Bill,Cindy和Dan,然后断言这些人是不同的:

To represent just one instance, I'd declare a class Voters which has Alice, Bill, Cindy, and Dan as members, and then assert that those individuals are distinct:

现在,要将每个选民与他们的投票联系起来,我们可以引入一个具有Voter域的hasVote属性,该枚举范围包含字符串"yes"和"no".

Now, to relate each Voter to their vote, we can introduce a hasVote property with domain Voter and the enumerated range containing the strings, "yes", and "no".

我们仍然需要与四个选民有关的某事,以将它们绑在一起.从概念上讲,这是投票事件,其中唯一的参与者是爱丽丝(Alice),比尔(Bill),辛迪(Cindy)和丹(Dan),并且每个选民只有一票.让我们介绍一个类VotingEvent和一个对象属性hasVoter,它将VotingEvent与其参与者相关联.现在,有一些投票事件,为此我们将介绍一个单独的votingEvent1.我们断言其参与者是爱丽丝,比尔,辛迪和丹,而且只有这些参与者,而且此事件中的每个投票者都只有一票.我们还添加了两个类型约束,它们表示事件恰好有2个是"选民.这是足够的,因为这样的要求是只有四个枚举的选民,他们必须是不同的,每个选民只有一票,并且每个选票是是"或否",并且隐含的知识是是".和否"是不同的字符串,足以确保其余两票必须是否"票.

We still need something that relates to the four Voters, to tie them together. Conceptually, this is the voting event in which the only participants were Alice, Bill, Cindy, and Dan, and in which each voter has only one vote. Let's introduce a class VotingEvent and an object property hasVoter which relates a VotingEvent to its participants. Now, there is some voting event, for which we'll introduce an individual votingEvent1. We'll assert that its participants are Alice, Bill, Cindy, and Dan, and only those, and that every voter in this event has exactly one vote. We also add two type constraints that say that the event has exactly 2 "yes" voters. This is sufficient, since the requirements that there are only the four enumerated voters, that they are distinct, that each has exactly one vote, and that each vote is either "yes" or "no", and the implicit knowledge that "yes" and "no" are distinct strings, is enough to ensure that the remaining two votes must be "no" votes.

现在,如果我们最终断言爱丽丝和比尔投了赞成票,

Now, if we finally assert that Alice and Bill cast "yes" votes,

有足够的推理能力来推断辛迪和丹投否定票,正如我们在Protégé中运行DL查询所看到的那样:

there is enough to infer with a reasoner that Cindy and Dan cast "no" votes, as we can see by running a DL query in Protégé:

Turtle和RDF/XML序列化都不是特别好看,但为了方便复制和粘贴,我将它们附加在最后.现在,这是单个投票事件的合适表示形式,但是请注意,我们引入了投票事件是为了使某物加上我们对四个选民及其投票价值的限制.但是,如果有多个投票事件,并且有些选民参加了一个以上的事件,那么简单的限制是选民只能拥有一票,这是有问题的,因为选民可能会在一个事件中投票是"而在另一个事件中投票否". 事件 z 中的投票人 x 投了 y 的票"是三级关系,如果有多个事件,则确实需要这样表示将要出席. W3C工作组说明,在语义网上定义N元关系描述了一些方法,但是基本思想是定义一个类,该类的成员代表个人投票,并且与投票事件,投票者和投票有关.您仍然可以为这种推理编写适当的限制,尽管它们会稍微复杂一些,可能涉及属性链或嵌套的类表达式.

Neither the Turtle nor RDF/XML serializations are particularly nice to look at, but I've attached them at the end, for easy copying and pasting. Now, this is a suitable representation for a single voting event, but note that we introduced a voting event in order to have something to which we added the restrictions about the four voters and the values of their votes. However, if there were multiple voting events, and some voters participated in more than one event, the simple restriction that a voter has exactly one vote is problematic because the voter might vote "yes" in one event and "no" in another. The "Voter x cast a vote of y in event z" is a tertiary relation, and really needs to be represented as such if multiple events are going to be present. The W3C Working Group Note, Defining N-ary Relations on the Semantic Web describes some approaches for this, but the basic idea is that you'd define a class whose members represent individuals cast votes, and are related to the voting event, the voter, and the vote cast. You can still write the appropriate restrictions for this kind of reasoning, though they'll be a little bit more complicated, probably involving property chains or nested class expressions.

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

voters:Voter  a  owl:Class .

voters:VotingEvent  a  owl:Class .

voters:hasVote  a    owl:DatatypeProperty ;
        rdfs:domain  voters:Voter ;
        rdfs:range   [ a          rdfs:Datatype ;
                       owl:oneOf  [ a          rdf:List ;
                                    rdf:first  "no" ;
                                    rdf:rest   [ a          rdf:List ;
                                                 rdf:first  "yes" ;
                                                 rdf:rest   ()

                                               ]
                                  ]
                     ] .

voters:Dan  a   owl:NamedIndividual , voters:Voter .

<http://example.org/voters>
        a       owl:Ontology .

voters:Alice  a         owl:NamedIndividual , voters:Voter ;
        voters:hasVote  "yes" .

voters:Bill  a          owl:NamedIndividual , voters:Voter ;
        voters:hasVote  "yes" .

voters:Cindy  a  owl:NamedIndividual , voters:Voter .

voters:hasVoter  a   owl:ObjectProperty ;
        rdfs:domain  voters:VotingEvent ;
        rdfs:range   voters:Voter .

voters:votingEvent1  a   owl:NamedIndividual , voters:VotingEvent ;
        a                [ a                         owl:Restriction ;
                           owl:onClass               [ a               owl:Restriction ;
                                                       owl:hasValue    "yes" ;
                                                       owl:onProperty  voters:hasVote
                                                     ] ;
                           owl:onProperty            voters:hasVoter ;
                           owl:qualifiedCardinality  "2"^^xsd:nonNegativeInteger
                         ] ;
        a                [ a                  owl:Restriction ;
                           owl:allValuesFrom  [ a          owl:Class ;
                                                owl:oneOf  ( voters:Dan voters:Bill voters:Cindy voters:Alice )
                                              ] ;
                           owl:onProperty     voters:hasVoter
                         ] ;
        a                [ a                  owl:Restriction ;
                           owl:allValuesFrom  [ a                         owl:Restriction ;
                                                owl:onDataRange           xsd:string ;
                                                owl:onProperty            voters:hasVote ;
                                                owl:qualifiedCardinality  "1"^^xsd:nonNegativeInteger
                                              ] ;
                           owl:onProperty     voters:hasVoter
                         ] ;
        voters:hasVoter  voters:Alice , voters:Bill , voters:Cindy , voters:Dan .

[ a                    owl:AllDifferent ;
  owl:distinctMembers  ( voters:Alice voters:Bill voters:Cindy voters:Dan )
] .

RDF/XML序列化

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:voters="http://example.org/voters#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://example.org/voters"/>
  <owl:Class rdf:about="http://example.org/voters#Voter"/>
  <owl:Class rdf:about="http://example.org/voters#VotingEvent"/>
  <owl:ObjectProperty rdf:about="http://example.org/voters#hasVoter">
    <rdfs:range rdf:resource="http://example.org/voters#Voter"/>
    <rdfs:domain rdf:resource="http://example.org/voters#VotingEvent"/>
  </owl:ObjectProperty>
  <owl:DatatypeProperty rdf:about="http://example.org/voters#hasVote">
    <rdfs:domain rdf:resource="http://example.org/voters#Voter"/>
    <rdfs:range>
      <rdfs:Datatype>
        <owl:oneOf>
          <rdf:List>
            <rdf:first>no</rdf:first>
            <rdf:rest>
              <rdf:List>
                <rdf:first>yes</rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
              </rdf:List>
            </rdf:rest>
          </rdf:List>
        </owl:oneOf>
      </rdfs:Datatype>
    </rdfs:range>
  </owl:DatatypeProperty>
  <owl:AllDifferent>
    <owl:distinctMembers rdf:parseType="Collection">
      <owl:NamedIndividual rdf:about="http://example.org/voters#Alice">
        <rdf:type rdf:resource="http://example.org/voters#Voter"/>
        <voters:hasVote>yes</voters:hasVote>
      </owl:NamedIndividual>
      <owl:NamedIndividual rdf:about="http://example.org/voters#Bill">
        <rdf:type rdf:resource="http://example.org/voters#Voter"/>
        <voters:hasVote>yes</voters:hasVote>
      </owl:NamedIndividual>
      <owl:NamedIndividual rdf:about="http://example.org/voters#Cindy">
        <rdf:type rdf:resource="http://example.org/voters#Voter"/>
      </owl:NamedIndividual>
      <owl:NamedIndividual rdf:about="http://example.org/voters#Dan">
        <rdf:type rdf:resource="http://example.org/voters#Voter"/>
      </owl:NamedIndividual>
    </owl:distinctMembers>
  </owl:AllDifferent>
  <owl:NamedIndividual rdf:about="http://example.org/voters#votingEvent1">
    <rdf:type rdf:resource="http://example.org/voters#VotingEvent"/>
    <rdf:type>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://example.org/voters#hasVoter"/>
        <owl:onClass>
          <owl:Restriction>
            <owl:onProperty rdf:resource="http://example.org/voters#hasVote"/>
            <owl:hasValue>yes</owl:hasValue>
          </owl:Restriction>
        </owl:onClass>
        <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >2</owl:qualifiedCardinality>
      </owl:Restriction>
    </rdf:type>
    <rdf:type>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://example.org/voters#hasVoter"/>
        <owl:allValuesFrom>
          <owl:Class>
            <owl:oneOf rdf:parseType="Collection">
              <owl:NamedIndividual rdf:about="http://example.org/voters#Dan"/>
              <owl:NamedIndividual rdf:about="http://example.org/voters#Bill"/>
              <owl:NamedIndividual rdf:about="http://example.org/voters#Cindy"/>
              <owl:NamedIndividual rdf:about="http://example.org/voters#Alice"/>
            </owl:oneOf>
          </owl:Class>
        </owl:allValuesFrom>
      </owl:Restriction>
    </rdf:type>
    <rdf:type>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://example.org/voters#hasVoter"/>
        <owl:allValuesFrom>
          <owl:Restriction>
            <owl:onProperty rdf:resource="http://example.org/voters#hasVote"/>
            <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
            >1</owl:qualifiedCardinality>
            <owl:onDataRange rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
          </owl:Restriction>
        </owl:allValuesFrom>
      </owl:Restriction>
    </rdf:type>
    <voters:hasVoter rdf:resource="http://example.org/voters#Alice"/>
    <voters:hasVoter rdf:resource="http://example.org/voters#Bill"/>
    <voters:hasVoter rdf:resource="http://example.org/voters#Cindy"/>
    <voters:hasVoter rdf:resource="http://example.org/voters#Dan"/>
  </owl:NamedIndividual>
</rdf:RDF>

这篇关于使用Jena的OWL本体谓词逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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