用Protege建立一个本体,关于Pizza的,有三个类,包括Pizza, PiazzaBase和PizzaTopping,他们互相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. 1)rdf:ID和rdf:about的区别: 例如:rdf:ID="PizzaBase" 等价于rdf:about="(xml:base)+‘#’+‘PizzaBase’ " 2)rdf:resource 和rdf:about <owl:disjointWith rdf:resource="#PizzaBase"/> 是 <owl:disjointWith > 而 <owl:disjointWith> 这里不能用rdf:resource了,因为声明了#PizzaTopping是一个类。 所以,我们可以看出: 2.其实我们可以把rdf:ID看作和rdf:about一样的东西,rdf:ID只是一个缩写而已。所以 <owl:disjointWith> <owl:Class rdf:ID="Pizza"/> </owl:disjointWith> <owl:disjointWith> <owl:Class rdf:ID="PizzaTopping"/> </owl:disjointWith> </owl:Class> 第二,为什么这里不能用rdf:resource呢,是因为到目前为止,Pizza类和PizzaTopping类还没有被定义,需要在这里申明它是一个类。如果Pizza类在之前就已经定义了,那么这里也可以用rdf:resource来简写。 3.再补充一个rdf:ID和rdf:about的区别: rdf:ID是用来定义一个资源,或者说引入一个新的资源名称; 如果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 --Frank 按照Frank的说法,rdf:about用来表示statement的主体,rdf:resource在statement的客体是一个资源而不是文字值时用来表示客体 5.在RDF primer的第三章有解释:http://www.w3.org/TR/rdf-primer/ 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>