美文网首页
知识图谱基础组件RDF、RDFS、OWL

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

作者: Miridescent | 来源:发表于2019-03-04 11:36 被阅读3次

    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在使用的时候还有很多局限性,这种局限体现在对事物的抽象能力上,举个例子
    猫是哺乳动物,这个知识在不同的语境中有不同的意思

    • 语境1:指着一只实体猫说这句话的时候,猫是一个实体(object),就是眼前的这只猫
    • 语境2:当你和别人阐述猫这个物种是哺乳动物的时候,猫不是一个客观实体,而是一种抽象类型(class

    这个时候简单的

    猫 :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:Class:定义一个类
    • rdf:Property:定义这是一个属性
    • rdfs:domain:定义该属性属于哪个类别
    • rdfs:range:定义取值范围,上面的例子中类型有引用的stringdate以及我们自定义的PersonPlace

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

    • 注意 其实在RDFS中rdf:Propertyrdfs:Property是一样的,因为RFDS是RFD的扩展

    4.OWL序列化

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

    • 1.数据属性(data property),比如上图中的kg:career,就是实体(IRI)与字面量(literal)之间的关系
    • 2.实体属性(object property),比如上图中的kg:hasBirthPlace,就是实体与实体之间的关系

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

    • 对称关系:A认识B,则可以推断出B认识A
    • 相反关系:A是B的母亲,则B是A的孩子
    • 传递关系:A位于B,B位于C,则A位于C

    经过这样的一些逻辑定义,就使得数据具有了逻辑推理能力,这些功能的扩展,可以通过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中还有很多其他适用于推理的字段,下面列举几个

      1. owl:TransitiveProperty. 表示该属性具有传递性质。例如,我们定义“位于”是具有传递性的属性,若A位于B,B位于C,那么A肯定位于C。
      1. owl:SymmetricProperty. 表示该属性具有对称性。例如,我们定义“认识”是具有对称性的属性,若A认识B,那么B肯定认识A。
      1. owl:FunctionalProperty. 表示该属性取值的唯一性。 例如,我们定义“母亲”是具有唯一性的属性,若A的母亲是B,在其他地方我们得知A的母亲是C,那么B和C指的是同一个人。
      1. owl:inverseOf. 定义某个属性的相反关系。例如,定义“父母”的相反关系是“子女”,若A是B的父母,那么B肯定是A的子女。

    在融合数据的时候,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> .
    

    本体映射主要有以下三种

      1. owl:equivalentClass. 表示某个类和另一个类是相同的。
      1. owl:equivalentProperty. 表示某个属性和另一个属性是相同的。
      1. owl:sameAs. 表示两个实体是同一个实体。

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

    相关文章

      网友评论

          本文标题:知识图谱基础组件RDF、RDFS、OWL

          本文链接:https://www.haomeiwen.com/subject/rcwgyqtx.html