知识图谱基础组件RDF、RDFS、OWL

2019-03-04  本文已影响3人  Miridescent

1.RDF——知识图谱基石

1.什么是一条知识

在知识图谱中,一个语句可以看做是一个知识
举个例子:猫是哺乳动物

2.怎么描述一条知识

每条知识标识为一个SPO三元组(Subject-Predicate-Object)
Subject : 主语
Predicate: 谓词
Object :宾语
在“猫是哺乳动物”这条知识中
猫:主语
是:谓词 用来描述或判定客体性质、特征或者客体之间关系的词项
动物:宾语

3.如何将知识规范化

RDF(Resource Description Framework),资源描述框架,其本质是一个数据模型(Data Model)。它提供了一个统一的标准,用于描述实体/资源。RDF的作用就是描述上面提到的SPO三元组

SPO三元组.jpg
怎么描述一个三元组,前面已经介绍了,看文章知识图谱概览

2.RDF序列化

将知识规范化之后,就是存储和传输的问题
目前,RDF序列化的方式主要有:RDF/XML,N-Triples,Turtle,RDFa,JSON-LD等几种。
下面介绍一种使用的最多的方式Turtle
以伪满皇宫博物院知识图谱为例,网上有很多例子,自行参考

伪满皇宫博物院
@prefix scenic: <http://www.kg.com/scenic/> .  
@prefix scenicIntro: <http://www.kg.com/scenicIntro/>  
@prefix : <http://www.kg.com/ontology/> .

#scenic:1代表一个景点的实体
scenic:1 :name "长春市伪满皇宫博物院"^^string.
scenic:1 :id "271098"^^string.
scenic:1 :location "吉林”"^^string.
scenic:1 :level "5A"^^string.
scenic:1 :validTime "2007"^^string. 
scenic:1 :hasIntroIn scenicIntro:1.

#scenicIntro:1代表一个景点简介的实体
scenicIntro:1 :updateAt "1551408059023"^^long.
scenicIntro:1 : createAt "1551408059023"^^long.
scenicIntro:1 : scenicName "长春市伪满皇宫博物院"^^string. 
scenicIntro:1 : scenicId "271098"^^string.
scenicIntro:1 : content "伪满皇宫博物院"^^string.
scenicIntro:1 : title "中文名称"^^string.

同一个实体的多个属性可以紧凑表示,注意每一条后面末尾分号;和逗号.的区别

@prefix scenic: <http://www.kg.com/scenic/> .   
@prefix scenicIntro: <http://www.kg.com/scenicIntro/>
@prefix : <http://www.kg.com/ontology/> .

scenic:1 :name "长春市伪满皇宫博物院"^^string.
               :id "271098"^^string;
               :location "吉林”"^^string;
               :level "5A"^^string;
               :validTime "2007"^^string;
                :hasIntroIn scenicIntro:1.
scenicIntro:1 :updateAt "1551408059023"^^long;
                     : createAt "1551408059023"^^long;
                     : scenicName "长春市伪满皇宫博物院"^^string; 
                     : scenicId "271098"^^string;
                     : content "伪满皇宫博物院"^^string;
                     : title "中文名称"^^string;

3.RDFS序列化

在第一篇文章中说过,RDF在使用的时候还有很多局限性,这种局限体现在对事物的抽象能力上,举个例子
猫是哺乳动物,这个知识在不同的语境中有不同的意思

这个时候简单的

猫 :type "哺乳动物"^^string

无法具体的区分要表示的是哪种意思
这时候就需要扩展规则RDFS

还是以上面伪满皇宫博物院为例
此时,我们就要区分实体和类的不同了,用RDFS描述下上面的知识图谱

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.kg.com/ontology/> .

#定义两个类,分别是景点类scenic和景点简介类scenicIntro
:Scenic rdf:type rdfs:Class.
:ScenicIntro rdf:type rdfs:Class.

: name rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .

: id rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .
        
: location rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .
        
: level rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .

: validTime rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .
        
: hasIntroIn rdf:type rdf:Property;
        rdfs:domain :Scenic;
        rdfs:range : scenicIntro .
        
: updateAt rdf:type rdf:Property;
        rdfs:domain : scenicIntro;
        rdfs:range xsd:long .
        
: createAt rdf:type rdf:Property;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:long .

: scenicName rdf:type rdf:Property;
        rdfs:domain :scenicIntro;
        rdfs:range : xsd:string .

: scenicId rdf:type rdf:Property;
        rdfs:domain :scenicIntro;
        rdfs:range : xsd:string .

: content rdf:type rdf:Property;
        rdfs:domain :scenicIntro;
        rdfs:range : xsd:string .

: title rdf:type rdf:Property;
        rdfs:domain :scenicIntro;
        rdfs:range : xsd:string .

 

介绍下其中的几个关键字

RDFS中还有很多关键字,如rdfs:subClassOf等,详细可以参考W3C文档

4.OWL序列化

相对于RDFS,可以更加细化图谱中的关系
例如:其中wwww.kg.com/persion/1可以看做是一个实体罗纳尔多,www.kg.com/place/10086也是一个实体,代表罗纳尔多的出生地,但是他是一个实体,不是罗纳尔多实体的属性,所以,数据之间有两种关系

另外延伸想象,是不是可以让数据具有推理能力,举几个例子

经过这样的一些逻辑定义,就使得数据具有了逻辑推理能力,这些功能的扩展,可以通过OWL完成,具体的属性见W3C文档
这样经过修改后,上面的知识图谱可以表示为

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.kg.com/ontology/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

### 这里我们用词汇owl:Class定义了“景点”和“景点简介”这两个类。
:Scenic rdf:type owl:Class.
:ScenicIntro rdf:type owl:Class.

### owl区分数据属性和对象属性(对象属性表示实体和实体之间的关系)。词汇owl:DatatypeProperty定义了数据属性,owl:ObjectProperty定义了对象属性。
: name rdf:type owl:DatatypeProperty;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .

: id rdf:type owl:DatatypeProperty;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .
        
: location rdf:type owl:DatatypeProperty;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .

: level rdf:type owl:DatatypeProperty;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .
        
: validTime rdf:type owl:DatatypeProperty;
        rdfs:domain :Scenic;
        rdfs:range xsd:string .

: hasIntroIn rdf:type owl:ObjectProperty;
        rdfs:domain : Scenic;
        rdfs:range : scenicIntro .
        
: updateAt rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:long .
        
: createAt rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:long .

: scenicName rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:string .

: scenicId rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:string .

: content rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:string .

: title rdf:type owl:DatatypeProperty;
        rdfs:domain :scenicIntro;
        rdfs:range xsd:string .

上例子中数据属性和实体属性分别用owl:DatatypePropertyowl:ObjectProperty表示
OWL中还有很多其他适用于推理的字段,下面列举几个

在融合数据的时候,OWL也可以去到很好的作用,例如:A的数据中定义的一个Person1,B的数据中定义了一个Person2,假如这两个数据中定义的Person是一样的,那么当A数据和B数据融合的时候,就可以使用OWL很好的融合,避免数据的重复定义

<http://www.A.com/ontology/Person1> rdf:type owl:Class .
<http://www.B.com/ontology/Person2> rdf:type owl:Class .
<http://www.A.com/ontology/Person> owl:equivalentClass <http://www.B.com/ontology/Person> .

本体映射主要有以下三种

OWL中这种关系描述的属性定义,可以大大的增加推理机制,使海量的数据再处理的时候,不用一个一个的补全之间的关系,只要定义属性关系就好

上一篇 下一篇

猜你喜欢

热点阅读