且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将类的每个实例与另一个类的每个实例相关联?

更新时间:2023-01-14 13:59:19

编码规则

您正确地注意到,如果单个 x p值y 的实例,那么您将推断断言 p(x,y).但是,简单地说 x p的一个实例,有些Y 不会(没有更多信息)不会让您推断 p(x, y i )用于任何特定的 y i ,即使 y i em>是您已声明的 Y 的唯一特定实例.这是因为OWL做出了开放世界假设;仅仅因为您没有说某件事是正确的(或错误的),并不表示它不可能是正确的(或错误的). (当然,您可能已经说了其他的话,可以让您确定是真还是假.)这在另一个问题

Encoding the rules

You correctly note that if an individual x is an instance of p value y, then you'll infer the assertion p(x,y). However, simply saying that x is an instance of p some Y doesn't (without some more information) won't let you infer that p(x,yi) for any particular yi, even if yi is the only particular instance of Y that you've declared. This is because OWL makes the open world assumption; just because you haven't said something is true (or false) yet doesn't mean that it couldn't be true (or false). (Of course, you might have already said other things that would let you figure out whether something is true or false.) This is described in more detail in another question, Why is this DL-Query not returning any individuals?

如果我对它的理解正确,那么您尝试做的就是这样:

If I've understood it correctly, what you're trying to do is say something like:

  1. 每一个车辆 hasAction 关联到每个 Action
  2. 每一个 Car 通过 hasAction 与每个 CarAction
  3. 相关
  4. 每一个 Truck hasAction 相关联,每个 TruckAction
  1. every Vehicle is related by hasAction to every Action
  2. every Car is related by hasAction to every CarAction
  3. every Truck is related by hasAction to every TruckAction

您可以通过以下两种方法执行此操作.最简单的方法是简单地使用一些SWRL规则,另一个称为 rolification .

There are a couple of ways that you could do this. The easiest is to simply use some SWRL rules, and the other is called rolification.

您可以编写与上述规则相对应的SWRL规则,并且它们很容易编写:

You can write SWRL rule counterparts of the rules above, and the they're pretty easy to write:

车辆(?v)∧动作(?a)→ hasAction(?v,?a)
汽车(?v)∧ CarAction(?a)→ hasAction(?v,?a)
卡车(?v)∧ TruckAction(?a)→ hasAction(?v,?a)

Vehicle(?v) ∧ Action(?a) → hasAction(?v,?a)
Car(?v) ∧ CarAction(?a) → hasAction(?v,?a)
Truck(?v) ∧ TruckAction(?a) → hasAction(?v,?a)

如果使用所有这些规则,则会发现每辆车的动作要多于您想要的动作,因为根据第一个规则,每辆车都与每个动作相关.例如,由于每个 TruckAction 也是 Action ,并且由于每个 Car Vehicle ,因此第一个规则将将每个 TruckAction 与每个 Car 相关联,而您并不是真的想要这样.即使这样,在这里使用一些规则也可能是最简单的选择.

If you use all of these rules, you'll find that each of your vehicles has more actions than you want it to, because, by the first rule, each vehicle is related to each action. E.g., since each TruckAction is also an Action, and since each Car is a Vehicle, the first rule will relate each TruckAction to each Car, and you didn't really want that. Even so, using some rules may well be the easiest option here.

如果您不想使用SWRL规则,那么另一个选择是 rolification .我已经在回答几个问题时描述了旋转,以及如何进行旋转,所以您应该看一下:

If you don't want to use SWRL rules, then another option is rolification. I've described rolification and how to do it in answers to a few questions, so you should have a look at:

  • OWL 2 rolification
  • OWL 2 reasoning with SWRL rules
  • How to infer isBrotherOf property between two individuals
  • Equal relationship between ontology properties

这些将为您提供有关rolification的更多详细信息.不过,要点是,我们获得了具有特殊行为的新属性,例如 R Car :它们仅将特定类的实例与该相同的实例相关联.例如, R Car 关联 Car 的每个实例 本身,并且不会做其他任何事情.它实际上是特定类上的等价关系.

Those will give you more details about rolification. The main point, though, is that we get new properties, e.g., RCar, that have a special behavior: they only relate instances of a particular class to that same instance. E.g., RCar relates each instance of Car to itself, and doesn't do anything else. It's effectively an equivalence relation on a particular class.

汽化在这里有什么用?这意味着我们可以使用子属性链公理来推断某些 hasAction 属性.例如

How is rolification useful here? It means that we can use subproperty chain axioms to infer some hasAction properties. E.g.,

hasAction⊑ R Car • topObjectProperty• R CarAction

hasAction ⊑ RCar • topObjectProperty • RCarAction

从本质上讲,这等效于SWRL规则( topObjectProperty 是OWL的内置属性,可将所有内容与所有内容相关联):

That's essentially equivalent to the SWRL rule (topObjectProperty is a built in property of OWL that relates everything to everything):

R Car (?c,?c)∧ topObjectProperty(?c,?a)∧ R CarAction (?a,?a)→ hasAction(?c,?a)

RCar(?c,?c) ∧ topObjectProperty(?c,?a) ∧ RCarAction(?a,?a) → hasAction(?c,?a)

尽管有两个优点:

  1. 子财产链公理不需要推理程序来获得SWRL支持;和
  2. 次财产链公理适用于所有个人,但SWRL规则仅适用于具名个人,因此您可以获得更好的覆盖范围.

尽管如此,您仍然会遇到与SWRL规则的特殊性相同的问题;如果您说每个车辆 hasAction 的每个 Action 相关,那么该子财产链也将适用于车辆的子类和动作的子类

You'll still have the same issue that you did with the specificity of the SWRL rules, though; if you say that every Vehicle is related to every Action by hasAction, then that subproperty chain will also apply to subclasses of vehicle and subclasses of action.

但是,这有一个明显的缺点:对于您要在这些规则"之一中使用的每个类,您都需要一个新属性和一个等效的类公理,这会有些乏味.

There's a significant disadvantage, though: for each class that you want to use in one of these "rules," you need a new property and an equivalent class axiom, and that gets to be sort of tedious.

因为SWRL规则方法和带有滚动化方法的子属性链都存在以下问题:将每个车辆与每个动作相关联的通用规则将捕获 Action 子类中的所有动作以及子类中的车辆的 Vehicles 中,您可能需要稍微调整一下其中的一个层次结构.我建议不要

Because both the SWRL rule approach and the subproperty chain with rolification approaches have the problem that the generic rule that relates each vehicle to each action will capture all the actions from subclasses of Action and vehicles from subclasses of Vehicles, you may need to restructure one of your hierarchies a bit. I'd suggest that rather than

Action
  CarAction
  TruckAction

您使用的

Action
  VehicleAction
  CarAction
  TruckAction

,而不是反映车辆"下的层次结构.这样,您可以编写以下形式的规则:

and not mirror the hierarchy that you have under Vehicle. This way you can write rules of the form:

每个车辆 hasAction
的每个 GenericAction 相关 hasAction
,每个 Car 与每个 CarAction 相关 每个 Truck 与每个 TruckAction 通过 hasAction

every Vehicle is related to every GenericAction by hasAction
every Car is related to every CarAction by hasAction
every Truck is related to every TruckAction by hasAction

使用SWRL规则

如果您使用SWRL规则执行此操作,则它看起来像这样:

With SWRL rules

If you do this with SWRL rules, it looks like this:

(Protégé的默认布局可能未包括编辑SWRL规则的位置.请参阅我对Protégé-中的 Ontology属性定义的回答OWL/SWRL 获取获取说明.这只是一个较小的界面调整;您无需下载或安装任何东西.)这将产生如下结果:

(The default layout for Protégé might not include a place to edit SWRL rules though. See my answer to Ontology property definition in Protégé-OWL / SWRL for instructions on getting one. It's just a minor interface tweak; you don't need to download or install anything.) This produces results like this:

您可以复制并粘贴此本体:

You can copy and paste this ontology:

@prefix :      <https://***.com/q/21512765/1281433/cars#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix swrl:  <http://www.w3.org/2003/11/swrl#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix swrlb: <http://www.w3.org/2003/11/swrlb#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:Action  a      owl:Class .

<urn:swrl#a>  a  swrl:Variable .

:DodgeRam  a    owl:NamedIndividual , :Truck .

:Truck  a                owl:Class ;
        rdfs:subClassOf  :Vehicle .

:Car    a                owl:Class ;
        rdfs:subClassOf  :Vehicle .

<urn:swrl#v>  a  swrl:Variable .

:LoadCargo  a   owl:NamedIndividual , :TruckAction .

[ a          swrl:Imp ;
  swrl:body  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#a> ;
                            swrl:classPredicate  :GenericAction
                          ] ;
               rdf:rest   [ a          swrl:AtomList ;
                            rdf:first  [ a                    swrl:ClassAtom ;
                                         swrl:argument1       <urn:swrl#v> ;
                                         swrl:classPredicate  :Vehicle
                                       ] ;
                            rdf:rest   ()

                          ]
             ] ;
  swrl:head  [ a          swrl:AtomList ;
               rdf:first  [ a                       swrl:IndividualPropertyAtom ;
                            swrl:argument1          <urn:swrl#v> ;
                            swrl:argument2          <urn:swrl#a> ;
                            swrl:propertyPredicate  :hasAction
                          ] ;
               rdf:rest   ()

             ]
] .

:Accelerate  a  owl:NamedIndividual , :GenericAction .

:F150   a       owl:NamedIndividual , :Truck .

:FordFocusZX5  a  owl:NamedIndividual , :Car .

[ a          swrl:Imp ;
  swrl:body  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#c> ;
                            swrl:classPredicate  :Car
                          ] ;
               rdf:rest   [ a          swrl:AtomList ;
                            rdf:first  [ a                    swrl:ClassAtom ;
                                         swrl:argument1       <urn:swrl#a> ;
                                         swrl:classPredicate  :CarAction
                                       ] ;
                            rdf:rest   ()

                          ]
             ] ;
  swrl:head  [ a          swrl:AtomList ;
               rdf:first  [ a                       swrl:IndividualPropertyAtom ;
                            swrl:argument1          <urn:swrl#c> ;
                            swrl:argument2          <urn:swrl#a> ;
                            swrl:propertyPredicate  :hasAction
                          ] ;
               rdf:rest   ()

             ]
] .

:Brake  a       owl:NamedIndividual , :GenericAction .

:hasAction  a   owl:ObjectProperty .

:GenericAction  a        owl:Class ;
        rdfs:subClassOf  :Action .

<https://***.com/q/21512765/1281433/cars>
        a       owl:Ontology .

:Vehicle  a     owl:Class .

<urn:swrl#c>  a  swrl:Variable .

:ChevyMalibu  a  owl:NamedIndividual , :Car .

<urn:swrl#t>  a  swrl:Variable .

:CarAction  a            owl:Class ;
        rdfs:subClassOf  :Action .

[ a          swrl:Imp ;
  swrl:body  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#t> ;
                            swrl:classPredicate  :Truck
                          ] ;
               rdf:rest   [ a          swrl:AtomList ;
                            rdf:first  [ a                    swrl:ClassAtom ;
                                         swrl:argument1       <urn:swrl#a> ;
                                         swrl:classPredicate  :TruckAction
                                       ] ;
                            rdf:rest   ()

                          ]
             ] ;
  swrl:head  [ a          swrl:AtomList ;
               rdf:first  [ a                       swrl:IndividualPropertyAtom ;
                            swrl:argument1          <urn:swrl#t> ;
                            swrl:argument2          <urn:swrl#a> ;
                            swrl:propertyPredicate  :hasAction
                          ] ;
               rdf:rest   ()

             ]
] .

:TruckAction  a          owl:Class ;
        rdfs:subClassOf  :Action .

有气化作用

如果您使用rolification进行此操作,则如下所示:

With rolification

If you do this with rolification, it looks like this:

您将获得预期的结果:

您可以复制并粘贴此本体:

You can copy and paste this ontology:

@prefix :      <https://***.com/q/21512765/1281433/cars#> .
@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#> .

:GenericAction  a            owl:Class ;
        rdfs:subClassOf      :Action ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_GenericAction
                             ] .

:Car    a                    owl:Class ;
        rdfs:subClassOf      :Vehicle ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_Car
                             ] .

:CarAction  a                owl:Class ;
        rdfs:subClassOf      :Action ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_CarAction
                             ] .

:R_TruckAction  a  owl:ObjectProperty .

:R_Car  a       owl:ObjectProperty .

:Truck  a                    owl:Class ;
        rdfs:subClassOf      :Vehicle ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_Truck
                             ] .

:Brake  a       owl:NamedIndividual , :GenericAction .

:hasAction  a                   owl:ObjectProperty ;
        owl:propertyChainAxiom  ( :R_Vehicle owl:topObjectProperty :R_GenericAction ) ;
        owl:propertyChainAxiom  ( :R_Car owl:topObjectProperty :R_CarAction ) ;
        owl:propertyChainAxiom  ( :R_Truck owl:topObjectProperty :R_TruckAction ) .

:R_CarAction  a  owl:ObjectProperty .

:R_Truck  a     owl:ObjectProperty .

:F150   a       owl:NamedIndividual , :Truck .

:Accelerate  a  owl:NamedIndividual , :GenericAction .

:Action  a      owl:Class .

:ChevyMalibu  a  owl:NamedIndividual , :Car .

:R_Vehicle  a   owl:ObjectProperty .

:FordFocusZX5  a  owl:NamedIndividual , :Car .

:R_GenericAction  a  owl:ObjectProperty .

:TruckAction  a              owl:Class ;
        rdfs:subClassOf      :Action ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_TruckAction
                             ] .

:DodgeRam  a    owl:NamedIndividual , :Truck .

<https://***.com/q/21512765/1281433/cars>
        a       owl:Ontology .

:LoadCargo  a   owl:NamedIndividual , :TruckAction .

:Vehicle  a                  owl:Class ;
        owl:equivalentClass  [ a               owl:Restriction ;
                               owl:hasSelf     true ;
                               owl:onProperty  :R_Vehicle
                             ] .