我可以为 rdf:List 成员指定一个范围吗? [英] Can I specify a range for rdf:List members?

查看:45
本文介绍了我可以为 rdf:List 成员指定一个范围吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想说某个东西的标题应该是一个 rdfs:Literal,我这样做:

If I want to say that the title of something should be an rdfs:Literal, I do this:

example:title a owl:DatatypeProperty ;
    rdfs:range rdfs:Literal .

现在我想表达一个东西有一个有序的标题列表:

Now I want to express that something has an ordered list of titles:

example:titles a rdf:List .

如何指定列表的成员应该是什么?我需要继承 rdf:List 吗?

How do I specify what the members of the list should be? Do I need to subclass rdf:List?

更新:如果可能,我想继续使用 rdf:List,根据 Joshua 的回答,我认为以下说明任何只有 rdfs:Literal 值的 rdf:List 都是一个示例:ListOfLiterals,然后我可以使用作为一个范围.

UPDATE: I would like to keep using rdf:List if possible, based on the answer by Joshua I think the following says that any rdf:List with only rdfs:Literal values is an example:ListOfLiterals, and I can then use that as a range.

@prefix entity: <http://example.com/stuff/> .
@prefix example: <http://example.com/my/term/> .
@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#> .

example:ListOfLiterals a owl:Class ;
    owl:equivalentClass [
        a owl:Class ;
        owl:intersectionOf (
            rdf:List
            [
                a owl:Restriction ;
                owl:allValuesFrom rdfs:Literal ;
                owl:onProperty rdf:first
            ]
            [
                a owl:Restriction ;
                owl:allValuesFrom example:ListOfLiterals ;
                owl:onProperty rdf:rest
            ] )
    ] .

example:Book a owl:Class .

example:titles a owl:DatatypeProperty ;
    rdfs:domain example:Book ;
    rdfs:range example:ListOfLiterals .

entity:somebook a example:Book ;
    example:titles ( "Book Title"@en "Second Book Title"@en ) .

这是否有意义,还是我误解了什么?

Does that make any sense, or did I misunderstand something?

推荐答案

首先,请注意,在您的 OWL 代码中使用 rdf:Lists 意味着您将处于 OWL Full 状态,而许多推理器旨在与 OWL DL 一起使用.你可能会接受这个,如果你是,那就太好了.如果您需要继续使用 OWL DL,那么您必须使用自己的词汇表来表示列表,例如,类 warp:List 和属性 warp:firstwarp:rest,并使用它们代替 RDF 对应物.

First, note that using rdf:Lists in your OWL code means that you're going to be in OWL Full, whereas many of the reasoners are designed to work with OWL DL. You might be OK with this, and if you are, then great. If you need to remain in OWL DL, then you'll have to use your own vocabulary for lists, e.g., a class warp:List and properties warp:first and warp:rest, and use those instead of their RDF counterparts.

无论如何,一旦你决定了你的 List 类和你的 firstrest 属性,你可以定义一个列表类型ListOfElements 只能包含具有以下限制的某个类 Element 的成员:

At any rate, once you've decided on your List class and your first and rest properties, you can define a list type ListOfElements that can only contain members of some class Element with the following restriction:

ElementList ⊑列表and(第一个only Element)and(其余only ElementList)

ElementList ⊑ List and (first only Element) and (rest only ElementList)

这意味着 ElementList 是: (i) List;(ii) 具有 first 属性的值,它是一个 Element;(iii) 有一个 ElementList 作为它的 rest,这意味着 List 中的其余部分也必须是 Element s.无论 nil 对象是什么,都应该已经声明为 List,但您可能还想包括:

This means that an ElementList is: (i) a List; (ii) has an value for the first property that is an Element; and (iii) has an ElementList as its rest, which means that the rest of the things in the List must also be Elements. Whatever the nil object is should already be declared as a List, but you may also want to include:

nil a ElementList

nil a ElementList

但这不一定那么重要.对于您的情况,您需要以类似的方式定义一个 TitleList 类,然后将您的属性范围声明为 TitleList.

but this isn't necessarily as important. For your case, you'd want to define a class TitleList in a similar fashion, and then declare the range of your property as TitleList.

这是一个示例本体,它只包括定义了这些类型的 List 类和一个 ElementList 类(在人类可读的 Turtle 中):

Here's an example ontology that includes just defines these type of List class and an ElementList class (in human readable Turtle):

@prefix :      <http://stackoverflow.com/a/19480798/1281433/code#> .
@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#> .

:rest   a            owl:ObjectProperty ;
        rdfs:domain  :List ;
        rdfs:range   :List .

:List   a       owl:Class .

:nil    a       owl:NamedIndividual , :ElementList , :List .

:ElementList  a          owl:Class ;
        rdfs:subClassOf  [ a                   owl:Class ;
                           owl:intersectionOf  ( :List [ a                  owl:Restriction ;
                                                         owl:allValuesFrom  :Element ;
                                                         owl:onProperty     :first
                                                       ] [ a                  owl:Restriction ;
                                                           owl:allValuesFrom  :ElementList ;
                                                           owl:onProperty     :rest
                                                         ] )
                         ] .

:Element  a     owl:Class .

:first  a            owl:ObjectProperty ;
        rdfs:domain  :List .

<http://stackoverflow.com/a/19480798/1281433/code>
        a       owl:Ontology .

[ a                      owl:Axiom ;
  rdfs:comment           "It's probably a good idea to specify that nil is an ElementList.  This could also be inferred, though, if there is a nil-terminated List that is known to be an ElementList." ;
  owl:annotatedProperty  rdf:type ;
  owl:annotatedSource    :nil ;
  owl:annotatedTarget    :ElementList
] .

为全面起见,我定义了一个新的 List 类、firstrest 属性,以及一个单独的 nil,但是如果 OWL Full 对你没问题,那么你可以只使用 rdf:List 等.为了完整起见,这里是 RDF/XML 中的相同本体:

For full generality, I've defined new a new List class, first and rest properties, and an individual nil, but if OWL Full is OK with you, then you can just use rdf:List, etc. For completeness, here's the same ontology in 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="http://stackoverflow.com/a/19480798/1281433/code#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://stackoverflow.com/a/19480798/1281433/code"/>
  <owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#List"/>
  <owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#ElementList">
    <rdfs:subClassOf>
      <owl:Class>
        <owl:intersectionOf rdf:parseType="Collection">
          <owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#List"/>
          <owl:Restriction>
            <owl:onProperty>
              <owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#first"/>
            </owl:onProperty>
            <owl:allValuesFrom>
              <owl:Class rdf:about="http://stackoverflow.com/a/19480798/1281433/code#Element"/>
            </owl:allValuesFrom>
          </owl:Restriction>
          <owl:Restriction>
            <owl:onProperty>
              <owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#rest"/>
            </owl:onProperty>
            <owl:allValuesFrom rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
          </owl:Restriction>
        </owl:intersectionOf>
      </owl:Class>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#rest">
    <rdfs:range rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
    <rdfs:domain rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://stackoverflow.com/a/19480798/1281433/code#first">
    <rdfs:domain rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
  </owl:ObjectProperty>
  <owl:Axiom>
    <rdfs:comment>It's probably a good idea to specify that nil is an ElementList.  This could also be inferred, though, if there is a nil-terminated List that is known to be an ElementList.</rdfs:comment>
    <owl:annotatedTarget rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
    <owl:annotatedSource>
      <owl:NamedIndividual rdf:about="http://stackoverflow.com/a/19480798/1281433/code#nil">
        <rdf:type rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#ElementList"/>
        <rdf:type rdf:resource="http://stackoverflow.com/a/19480798/1281433/code#List"/>
      </owl:NamedIndividual>
    </owl:annotatedSource>
    <owl:annotatedProperty rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"/>
  </owl:Axiom>
</rdf:RDF>

这篇关于我可以为 rdf:List 成员指定一个范围吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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