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

编程入门 行业动态 更新时间:2024-10-15 04:28:06
本文介绍了如何将类的每个实例与另一个类的每个实例相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Protégé4.3开发一个简单的本体,并尝试创建一个模型,使类 C 的每个实例都具有特定的值 v ,该值是给定属性 p 的类 V 的实例.我可以使用一个公理得到这个推论

I'm working on a simple ontology, using Protégé 4.3 and trying to create a model such that every instance of a class C has some particular value v, which is an instance of a class V, for a given property p. I can get this inference using an axiom

C subClassOf (p 值 v)

但是我想我希望能够更像a

but I think I want to be able to state this more along the lines of a

C subClassOf (p 一些 V)

因为我实际上希望每个 C 实例都与 V 的每个 实例相关.

because I'd actually like each instance of C to be related to every instance of V.

我的示例是汽车和动作-我想为汽车创建一组动作.当我创建汽车的新实例时,我希望每个实例都有一套动作.如果我添加了新的动作实例,我希望所有汽车实例都能反映出它们所有相关的动作.

My example is automobiles and actions — I want to create a set of actions for automobiles. When I create new instances of automobiles I want each to have a set of actions. If I add new instances of actions I want all the instances of automobiles to reflect all their related actions.

为了添加更多细节,我定义了 Auto 类和两个子类: Car 和 Truck .我还定义了一个 Action 类和一个子类 TruckAction .我定义了一个 hasAction 属性,其域为 Auto ,范围为 Action ,用于关联自动操作和操作.我进一步创建了几个不同类型的人:

To add further detail, I have defined the Auto class and two subclasses: Car and Truck. I have also defined an Action class and a subclass, TruckAction. I have defined a hasAction property with domain Auto and range Action to relate autos and actions. I have further created several individuals of different types:

  • 自动
    • 卡车{F150}
    • 汽车{ChevyMalibu}
    • Auto
      • Truck {F150}
      • Car {ChevyMalibu}
      • TruckAction {LoadCargo}

      当我将 Car 设为(具有动作值Accelerate)的子类时,我可以看到 ChevyMalibu 具有推断的对象属性 hasAction Accelerate ,但这似乎类似于对对象属性声明进行硬编码.我想为 ChevyMalibu 推断出 all 的汽车动作,同样也为 F150 推断出 all 的TruckActions.我不太确定为什么做诸如使 Car 成为(具有Action动作)的子类之类的事情不会使我失望的原因.

      When I make Car a subclass of (hasAction value Accelerate), I can see that ChevyMalibu has the inferred object property hasAction Accelerate, but this seems akin to hard-coding the object property assertion. I would like to have all car actions inferred for the ChevyMalibu and likewise all TruckActions inferred for F150. I'm not quite sure why doing something like making Car a subclass of (hasAction some Action) won't get me there.

      我认为对 OWL类型推断有限制的雄辩答案与我的问题有关,但我不能完全将其加起来.

      I think that the eloquent answer to OWL type inference with a restriction is related to my question, but I can't quite add this up.

      推荐答案

      编码规则

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

      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:

    • 每一个车辆与 hasAction 关联到每个 Action
    • 每一个 Car 通过 hasAction 与每个 CarAction
    • 相关
    • 每一个 Truck 与 hasAction 相关联,每个 TruckAction
    • every Vehicle is related by hasAction to every Action
    • every Car is related by hasAction to every CarAction
    • 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漫游
      • 带有SWRL规则的OWL 2推理
      • 如何推断两个人之间的isBrotherOf属性
      • 本体属性之间的平等关系
      • 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)

      尽管有两个优点:

    • 子财产链公理不需要推理程序来获得SWRL支持;和
    • 次财产链公理适用于所有个人,但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 : <stackoverflow/q/21512765/1281433/cars#> . @prefix rdfs: <www.w3/2000/01/rdf-schema#> . @prefix swrl: <www.w3/2003/11/swrl#> . @prefix owl: <www.w3/2002/07/owl#> . @prefix xsd: <www.w3/2001/XMLSchema#> . @prefix swrlb: <www.w3/2003/11/swrlb#> . @prefix rdf: <www.w3/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 . <stackoverflow/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 : <stackoverflow/q/21512765/1281433/cars#> . @prefix rdfs: <www.w3/2000/01/rdf-schema#> . @prefix owl: <www.w3/2002/07/owl#> . @prefix xsd: <www.w3/2001/XMLSchema#> . @prefix rdf: <www.w3/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 . <stackoverflow/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 ] .

更多推荐

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

本文发布于:2023-11-28 14:10:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   相关联   如何将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!