Alex He

...永远保持希望与激情...约会未来更强大的自己...

 

语义WEB之RDF[A Semantic Web Primer阅读笔记]

1. RDF数据模型的基本单位是object-attribute-value三元组(也称为一个声明)。XML Schema限制了XML文档的结构,但是RDF Schema定义了RDF数据模型中使用的词汇(vocabulary)。

In RDFS we can define the vocabulary, specify which properties apply to which kinds of objects and what values they can take, and describe the relationships between objects.

RDFS让语义信息机器可读。

2. RDF中的基本概念就是资源,属性和声明。

资源Resources

每个资源都有一个URI,注意一个URI并不一定要有对应的可访问的资源。

属性Properties

属性描述资源间的关系,也是一个资源。

声明Statements

声明就是一个由资源,属性和值组成的三元组,其中值也可以是一个资源或文字literals。

在XML文档中,使用rdf:RDF标签表示RDF文档元素。元素内容表示一个描述,使用rdf:Description标签表示。

一个例子

<?xml version="1.0" encoding="UTF-16"?>

<rdf:RDF

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

     xmlns:mydomain="http://www.mydomain.org/my-rdf-ns">

     <rdf:Description rdf:about="http://www.cit.gu.edu.au/~db">

          <mydomain:site-owner rdf:resource="#DavidBillington"/>

     </rdf:Description>

</rdf:RDF>

数据类型

(#DavidBillington, http://www.mydomain.org/age,

"27"^http://www.w3.org/2001/XMLSchema#integer )

3. RDF Style XML中的几大元素

rdf:Description

rdf:about

rdf:resource

rdf:type

三个容器元素

rdf:Bag

rdf:Seq

rdf:Alt

实际上如下的RDF描述表示的就是下面的三元组(主语谓词宾语)声明

<rdf:Description rdf:about="949352">

     <uni:name>Grigoris Antoniou</uni:name>

</rdf:Description>

<rdf:Statement rdf:about="StatementAbout949352">

     <rdf:subject rdf:resource="949352"/>

     <rdf:predicate rdf:resource="&uni;name"/>

     <rdf:object>Grigoris Antoniou</rdf:object>

</rdf:Statement>

4. RDF Schema:基本概念

属性(谓词)有两个限制,前面的主语有domain限制(也就是定义域限制),后面的宾语有range限制(也就是值域限制)。

类别间有层次和继承关系。

同面向对象编程一样,这里也有类,属性继承等概念;但与之不同的是,在RDFS中,属性的定义是全局性的,在类的定义中不包括属性定义;也就是说填写了属性还是同一个类;而OO里面,对一个类添加了属性就是另一个类了。

属性也有层次关系。

一个例子

Image(21)

5. RDF Schema:语言描述

核心类Core Classes

rdfs:Resource,所有资源的类别

rdfs:Class,所有类别的类别

rdfs:Literal,所有文字(字符串)的类别

rdfs:Property,所有属性的类别

rdfs:Statement,所有具体化的声明的类别

比如lecturer类别的定义如下

<rdfs:Class rdf:ID="lecturer">

     . . .

</rdfs:Class>

定义关系的核心属性Core Properities

rdf:type,which relates a resource to its class. 

rdfs:subClassOf, which relates a class to one of its superclasses.

rdfs:subPropertyOf, which relates a property to one of its superproperties.

限制性属性的核心关系Core Properties for Restricting Properties

rdfs:domain

rdfs:range

<rdf:Property rdf:ID="phone">

     <rdfs:domain rdf:resource="#staffMember"/>

     <rdfs:range rdf:resource="&rdf;Literal"/>

</rdf:Property>

具体化的有用属性Useful Properties for Reification

rdf:subject

rdf:preficate

rdf:object

容器类别

rdf:Bag

rdf:Seq

rdf:Alt

rdfs:Container

工具属性

rdfs:seeAlso,relates a resource to another resource that explains it.

rdfs:isDefinedBy

rdfs:comment

rdfs:label

一个例子

Image(22)

<rdf:RDF

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

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

     <rdfs:Class rdf:ID="motorVehicle"/>

     <rdfs:Class rdf:ID="van">

          <rdfs:subClassOf rdf:resource="#motorVehicle"/>

     </rdfs:Class>

     <rdfs:Class rdf:ID="truck">

          <rdfs:subClassOf rdf:resource="#motorVehicle"/>

     </rdfs:Class>

     <rdfs:Class rdf:ID="passengerVehicle">

          <rdfs:subClassOf rdf:resource="#motorVehicle"/>

     </rdfs:Class>

     <rdfs:Class rdf:ID="miniVan">

          <rdfs:subClassOf rdf:resource="#passengerVehicle"/>

          <rdfs:subClassOf rdf:resource="#van"/>

     </rdfs:Class>

</rdf:RDF>

6. RDF和RDFS的公理化语义An Axiomatic Semantics for RDF and RDF Schema

基本属性

PropVal(P,R, V )表示谓词P,资源R,值V

Type(R, T), 即 PropVal(type,R, T)

使用谓词逻辑表示语义。

7. RDF和RDFS中一些直接的推理规则

比如:三元组谓词的类别是rdf:property

IF E contains the triple (?x, ?p, ?y)

THEN E also contains the triple (?p, rdf : type, rdf : property)

比如:子类的传递性

IF E contains the triples (?u, rdfs : subClassOf, ?v) and (?v, rdfs : subclassOf, ?w)

THEN E also contains the triple (?u, rdfs : subClassOf, ?w)

等等规则

这些规则不是特别对,不需要特别难的理论证明就能够在实践中应用。

8. 使用SPARQL进行查询

基本查询

SPARQL查询语言是基于图模式匹配的。比如,

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?c

WHERE

{

     ?c rdf:type rdfs:Class .

}

注意,SPARQL没有显示的支持RDFS语义,也就是说查询语句说检索出所有的鸟,它是不能够找到所有的鸟的子类的。是否能支持RDFS语义,则依赖于具体的查询系统。

SELECT-FROM-WHERE结构

SPARQL查询基于的是SELECT-FROM-WHERE结构:

SELECT specifies the projection: the number and order of retrieved data.

FROM is used to specify the source being queried. This clause is optional; when it is not specified, we can simply assume we are querying the knowledge base of a particular system.

WHERE imposes constraints on possible solutions in the form of graph pattern templates and boolean constraints.

posted on 2013-02-21 09:09  Alex木头  阅读(808)  评论(0编辑  收藏  举报

导航