RDF:ID, RDF:About RDF: Resource的区别

来源:互联网 发布:常用的c语言编程软件 编辑:程序博客网 时间:2024/05/18 01:13

Protege建立一个本体,关于Pizza的,有三个类,包括Pizza, PiazzaBasePizzaTopping,他们互相Disjointwith,我原以为这三个类既然是在层次上对等的,那代码也应该差不多。但是当我查看源代码时发现自动生成的代码中,这三个类是不一样的,主要是有些用的是rdf:ID,有些用的是rdf:about,还有用rdf:resource的,如下:

<?xml version="1.0"?>

<rdf:RDF

    xmlns:owl="http://www.w3.org/2002/07/owl#"

    xmlns="http://www.owl-ontologies.com/unnamed.owl#"

    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"

    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

  xml:base="http://www.owl-ontologies.com/unnamed.owl">

  <owl:Ontology rdf:about=""/>

  <owl:Class rdf:ID="PizzaBase">

    <owl:disjointWith>

      <owl:Class rdf:ID="Pizza"/>

    </owl:disjointWith>

    <owl:disjointWith>

      <owl:Class rdf:ID="PizzaTopping"/>

    </owl:disjointWith>

  </owl:Class>

  <owl:Class rdf:about="#Pizza">

    <owl:disjointWith rdf:resource="#PizzaBase"/>

    <owl:disjointWith>

      <owl:Class rdf:about="#PizzaTopping"/>

    </owl:disjointWith>

  </owl:Class>

  <owl:Class rdf:about="#PizzaTopping">

    <owl:disjointWith rdf:resource="#PizzaBase"/>

    <owl:disjointWith rdf:resource="#Pizza"/>

  </owl:Class>

</rdf:RDF>

同样的结构,为什么有些要用rdf:resource有些又用rdf:about,还有些用rdf:ID?这几个有什么区别呢?

一些网友的观点:

1.

1rdf:IDrdf:about的区别: 
rdf:about
的值是一个完整URIref,注意也可以是相对URI,(相对于xml:base;
rdf:ID
是对rdf:about的值的缩写,其值是一个“ XML Name”,所以,不能是数字开头,不能有“/”符号等。

例如:rdf:ID="PizzaBase" 等价于rdf:about="(xml:base)+#+PizzaBase "
这个xml:base的值可以在XML文件头声明,如你例子中的,xml:base="http://www.owl-ontologies.com/unnamed.owl" 如果没有声明,则其值是RDF文件所放在的位置uri

2)rdf:resource rdf:about

<owl:disjointWith rdf:resource="#PizzaBase"/> 

<owl:disjointWith >
   <rdf:Description rdf:about="#PizzaBase" />
</owl:disjointWith >
的缩写。这里必须没有对资源="#PizzaBase" 做进一步的说明。所以,rdf:resource只能出现在表示属性的节点中,如这里的owl:disjointWith节点。

  <owl:disjointWith>
             <owl:Class rdf:about="#PizzaTopping"/>
    </owl:disjointWith>
是等价于:
<owl:disjointWith >
   <rdf:Description rdf:about="#PizzaTopping" >
         <rdf:type rdf:resource="&rdfs;Class" />
   </rdf:Description>
</owl:disjointWith >

这里不能用rdf:resource了,因为声明了#PizzaTopping是一个类。

所以,我们可以看出:
说明了:  <owl:Class rdf:ID="PizzaBase">
以后,后面的都是用:
 <owl:disjointWith rdf:resource="#PizzaBase"/>
了。

2.其实我们可以把rdf:ID看作和rdf:about一样的东西,rdf:ID只是一个缩写而已。所以
  <owl:Class rdf:ID="PizzaBase">

    <owl:disjointWith>

      <owl:Class rdf:ID="Pizza"/>

    </owl:disjointWith>

    <owl:disjointWith>

      <owl:Class rdf:ID="PizzaTopping"/>

    </owl:disjointWith>

  </owl:Class>
中,把所有的rdf:ID="xxx"替换成rdf:about="#xxx"也是可以的,这是我的第一个理解。

第二,为什么这里不能用rdf:resource呢,是因为到目前为止,Pizza类和PizzaTopping类还没有被定义,需要在这里申明它是一个类。如果Pizza类在之前就已经定义了,那么这里也可以用rdf:resource来简写。

3.再补充一个rdf:IDrdf:about的区别:

rdf:ID是用来定义一个资源,或者说引入一个新的资源名称;
rdf:about
除了也可用来定义资源外,还可用来扩展对这个资源的定义(这可以出现在其他本体文件中)

如果Pizza是用rdf:ID定义的,那么要增加对Pizza的描述,就必须用rdf:about。因为同一个RDF文档中,不能出现两个rdf:ID="Pizza",否则RDF Parser就会报错。参见:

{{//RDF Primer. Section 3.2 的第4段中间

 However, using rdf:ID provides an additional check when assigning a set of distinct names, since a given value of the rdf:ID attribute can only appear once relative to the same base URI (the catalog document, in this example).

4.Have you looked at the RDF Primer (and specifically, Example 4 in
Section 3.1 and its explanation, which is where this is discussed)?
Basically, rdf:about is for expressing the *subject* of an RDF statement
in RDF/XML.  rdf:resource is for expressing the *object* of an RDF
statement in RDF/XML, when the object is another resource rather than a
literal value.  Does that help?  If you have some particular example in
mind that you are trying to express, could you provide it?

--Frank

按照Frank的说法,rdf:about用来表示statement的主体,rdf:resourcestatement的客体是一个资源而不是文字值时用来表示客体

5.在RDF primer的第三章有解释:http://www.w3.org/TR/rdf-primer/
其中的对rdf:ID的解释:
An important difference from previous examples is that, in line 5, the rdf:Description element has an rdf:ID attribute instead of an rdf:about attribute. Using rdf:ID specifies a fragment identifier, given by the value of the rdf:ID attribute (item10245 in this case, which might be the catalog number assigned by example.com), as an abbreviation of the complete URIref of the resource being described. The fragment identifier item10245 will be interpreted relative to a base URI, in this case, the URI of the containing catalog document. The full URIref for the tent is formed by taking the base URI (of the catalog), and appending the character "#" (to indicate that what follows is a fragment identifier) and then item10245 to it, giving the absolute URIref http://www.example.com/2002/04/products#item10245.

The rdf:ID attribute is somewhat similar to the ID attribute in XML and HTML, in that it defines a name which must be unique relative to the current base URI (in this example, that of the catalog). In this case, the rdf:ID attribute appears to be assigning a name (item10245) to this particular kind of tent. Any other RDF/XML within this catalog could refer to the tent by using either the absolute URIref http://www.example.com/2002/04/products#item10245, or the relative URIref #item10245. The relative URIref would be understood as being a URIref defined relative to the base URIref of the catalog. Using a similar abbreviation, the URIref of the tent could also be given by specifying rdf:about="#item10245" in the catalog entry (i.e., by specifying the relative URIref directly) instead of rdf:ID="item10245" . As an abbreviation mechanism, the two forms are essentially synonyms: the full URIref formed by RDF/XML is the same in either case: http://www.example.com/2002/04/products#item10245. However, using rdf:ID provides an additional check when assigning a set of distinct names, since a given value of the rdf:ID attribute can only appear once relative to the same base URI (the catalog document, in this example). Using either form, example.com would be giving the URIref for the tent in a two-stage process, first assigning the URIref for the whole catalog, and then using a relative URIref in the description of the tent in the catalog to indicate the URIref that has been assigned to this particular kind of tent. Moreover, this use of a relative URIref can be thought of either as being an abbreviation for a full URIref that has been assigned to the tent independently of the RDF, or as being the assignment of the URIref to the tent within the catalog.

 

 

 

 

 

总结:

 

rdf:ID是用来定义一个资源,或者说引入一个新的资源名称<br />rdf:about除了也可用来定义资源外(引入一个新的资源名称),还可用来扩展对这个资源的定义(这可以出现在其他本体文件中)。<br />如果Pizza是用rdf:ID定义的,那么要增加对Pizza的描述,就必须用rdf:about。因为同一个RDF文档中,不能出现两个rdf:ID="Pizza"。<br />rdf:resource只用于属性是对一个对象的引用时,可以是在前面或后面定义过的;也可以使引用未定义的,那样就会生成blank node。

rdf:NodeID仅当前文档唯一,仅用于将某一元素与其3元组分开定义时。如
<a>
<b>
1
</b>
</a>
可改为
<a rdf:NodeID = "s1"/>
<rdf:Description rdf:nodeID="s1">
<b>
1
</b>
</rdf:Description>

原创粉丝点击