知识图谱 Protege 本体构建

知识图谱 Protege 本体构建

Protege 相关资源

  • Protege OWL Tutorial 官方教程 : http://owl.cs.manchester.ac.uk/publications/talks-and-tutorials/protg-owl-tutorial/
  • Protege Wiki 相关说明:https://protegewiki.stanford.edu/wiki/Main_Page

Protege 使用 Manchester syntax

描述逻辑 (DL, Description Logic)

逻辑连接词:用于将多个原子命题组合成复合命题

在这里插入图片描述
量词:表示个体数量属性的词

在这里插入图片描述

网络本体语言 (OWL, Web Ontology Language)

​ OWL 是 W3C 开发的一种网络本体语言,用于对本体进行语义描述。OWL 通过提供更多具有形式语义的词汇,使之在Web内容的机器可理解性方面要强于XML、RDF和RDF Schema(RDF-S)。OWL 可以当作是 RDFS 的一个扩展,添加了额外的预定义词汇,提供快速、灵活的数据建模能力,高效的自动推理。

OWL 描述属性特征的词汇

在这里插入图片描述
OWL 本体映射词汇

在这里插入图片描述

Protege 使用 Manchester syntax

​ DL OWL 和 Manchester 语法对应关系如下表:

在这里插入图片描述

Protege 本体构建实践

​ 针对一个游戏信息关系构建实体,具体设计的游戏名称、类型、难度和关系等内容如下表所示:
在这里插入图片描述

定义本体 IRI 前缀

​ 在 Ontology IRI 定义本体的前缀,如图中被选中内容所示

在这里插入图片描述

创建类

​ 创建的所有类都是 Thing 的子类,所以先选中 Thing 类,然后在菜单栏中找到 Tools 下的 Create class ... 进行批量类的创建。
在这里插入图片描述

​ 输入类的层次和属性,使用 tabs 缩进表示层级关系。

在这里插入图片描述

​ 通过上面编码的方式可以批量创建具有层级关系的类,创建完成结果如下图所示,Entity 页面中包含了初始化类的层次结构、同层级类的关系以及单个类的具体描述。
在这里插入图片描述

增加类的关系

​ 属性(property) 是知识图谱中的边:

  • Object property:对象属性连接的节点都有唯一的标志

  • Data property:数据类型属性的主语是具有唯一标志的节点,而连接的另外一个节点是XML的一些基础数据类型

​ 创建对象属性的过程和创建类的方式相似,也可以批量创建如下图所示:

在这里插入图片描述

​ 在对象属性的描述 (Description) 中可以定义:描述是公理,对象属性的取值范围

  • Domains:对象属性的主语的类型
  • Ranges:对象属性的宾语的类型

在这里插入图片描述

​ 另外,对象属性也可以设置特性 (Characteristics) : 特性是一些推理机制Functional, Inverse functional, Transitive, Symmetric, Asymmetric, Reflexive, Irreflexive

添加公理

​ 除了直接在对象属性中定义公理,也可以在类上添加一些公理。如下图示例中,在subclass 中定义 Chess 可以在 Linux WindowsPlatform 上运行,还可以进行 MultiPlayerGenre

在这里插入图片描述
在这里插入图片描述

本体保存

Save as 可以将本体保存,可以选择 Turtle Syntax 格式保存,保存后的owl 文件是一个 RDF 格式的文件。

在这里插入图片描述

使用构建的本体进行推理

​ 在菜单栏中找打 Reasoner 选择一个推理器,并点击 Configure 确定如下图所示:

在这里插入图片描述

​ 然后,再在 Reasoner 中开始推理,如下图所示,最终可以看到 MultiPlayerGame 多出一级 Chess 说明推理出了 Chess 是多人游戏。

在这里插入图片描述

本体保存RDF源码

@prefix : <http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1> .

<http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1> rdf:type owl:Ontology .

#################################################################
#    Object Properties
#################################################################

###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#hasDifficulty
:hasDifficulty rdf:type owl:ObjectProperty ;
               rdfs:subPropertyOf owl:topObjectProperty ;
               rdfs:domain :Game ;
               rdfs:range :DifficultyValuePartition .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#hasGenre
:hasGenre rdf:type owl:ObjectProperty ;
          rdfs:subPropertyOf owl:topObjectProperty ;
          rdfs:domain :Game ;
          rdfs:range :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#hasPlatform
:hasPlatform rdf:type owl:ObjectProperty ;
             rdfs:subPropertyOf owl:topObjectProperty ;
             rdfs:domain :Game ;
             rdfs:range :Platform .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Chess
:Chess rdf:type owl:Class ;
       rdfs:subClassOf :NameGame ,
                       [ rdf:type owl:Restriction ;
                         owl:onProperty :hasGenre ;
                         owl:someValuesFrom :MultiPlayer
                       ] ,
                       [ rdf:type owl:Restriction ;
                         owl:onProperty :hasPlatform ;
                         owl:someValuesFrom :Linux
                       ] ,
                       [ rdf:type owl:Restriction ;
                         owl:onProperty :hasPlatform ;
                         owl:someValuesFrom :Windows
                       ] .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#DifficultyValuePartition
:DifficultyValuePartition rdf:type owl:Class ;
                          owl:equivalentClass [ rdf:type owl:Class ;
                                                owl:unionOf ( :Easy
                                                              :Hard
                                                              :Normal
                                                            )
                                              ] ;
                          rdfs:subClassOf :ValuePartition .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Easy
:Easy rdf:type owl:Class ;
      rdfs:subClassOf :DifficultyValuePartition .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Game
:Game rdf:type owl:Class .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Genre
:Genre rdf:type owl:Class .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Hard
:Hard rdf:type owl:Class ;
      rdfs:subClassOf :DifficultyValuePartition .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Linux
:Linux rdf:type owl:Class ;
       rdfs:subClassOf :Platform .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#LoL
:LoL rdf:type owl:Class ;
     rdfs:subClassOf :NameGame .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#MacOSX
:MacOSX rdf:type owl:Class ;
        rdfs:subClassOf :Platform .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#MultiPlayer
:MultiPlayer rdf:type owl:Class ;
             rdfs:subClassOf :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#MultiPlayerGame
:MultiPlayerGame rdf:type owl:Class ;
                 owl:equivalentClass [ owl:intersectionOf ( :Game
                                                            [ rdf:type owl:Restriction ;
                                                              owl:onProperty :hasGenre ;
                                                              owl:someValuesFrom :MultiPlayer
                                                            ]
                                                          ) ;
                                       rdf:type owl:Class
                                     ] .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#NameGame
:NameGame rdf:type owl:Class ;
          rdfs:subClassOf :Game .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Normal
:Normal rdf:type owl:Class ;
        rdfs:subClassOf :DifficultyValuePartition .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Online
:Online rdf:type owl:Class ;
        rdfs:subClassOf :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Platform
:Platform rdf:type owl:Class .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Puzzle
:Puzzle rdf:type owl:Class ;
        rdfs:subClassOf :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#RolePlayGame
:RolePlayGame rdf:type owl:Class ;
              rdfs:subClassOf :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#SinglePlayer
:SinglePlayer rdf:type owl:Class ;
              rdfs:subClassOf :Genre .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Sudoku
:Sudoku rdf:type owl:Class ;
        rdfs:subClassOf :NameGame .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#ValuePartition
:ValuePartition rdf:type owl:Class .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#Windows
:Windows rdf:type owl:Class ;
         rdfs:subClassOf :Platform .


###  http://www.semanticweb.org/kg/ontologies/2021/2/ganme-ontology-1#WoW
:WoW rdf:type owl:Class ;
     rdfs:subClassOf :NameGame .


#################################################################
#    General axioms
#################################################################

[ rdf:type owl:AllDisjointClasses ;
  owl:members ( :Chess
                :LoL
                :Sudoku
                :WoW
              )
] .


[ rdf:type owl:AllDisjointClasses ;
  owl:members ( :Easy
                :Hard
                :Normal
              )
] .


[ rdf:type owl:AllDisjointClasses ;
  owl:members ( :Game
                :Genre
                :Platform
                :ValuePartition
              )
] .


[ rdf:type owl:AllDisjointClasses ;
  owl:members ( :Linux
                :MacOSX
                :Windows
              )
] .


[ rdf:type owl:AllDisjointClasses ;
  owl:members ( :MultiPlayer
                :Online
                :Puzzle
                :RolePlayGame
                :SinglePlayer
              )
] .


###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi
### 如何使用 Protege 构建知识图谱本体 #### 工具简介 Protege 是一款由斯坦福大学开发的开源工具,用于构建和管理基于OWL(Web Ontology Language)的知识图谱本体。它支持通过Manchester Syntax描述逻辑来定义类、属性及其关系[^1]。 #### 下载与安装 可以从官方网站下载最新版本的 Protege: [https://protege.stanford.edu/](https://protege.stanford.edu/) 完成安装后即可启动软件并开始构建本体[^3]。 #### 类定义 在 Protege 中,可以通过 `Classes` 面板定义实体类别。例如,在医疗领域中可以定义 `Patient`, `Doctor`, 和 `Disease` 等类。这些类之间的层次结构可以用父类-子类的关系表示。例如,`HumanBeing` 可以作为 `Patient` 的父类[^2]。 #### 属性定义 除了类之外,还需要定义对象属性(Object Properties)和数据属性(Data Properties)。对象属性用来表达两个类之间的关系,比如 `treatedBy` 表达患者被医生治疗的关系;而数据属性则用来连接类与其具体的数据值,如患者的年龄或体重[^4]。 #### 推理机配置 为了验证本体的一致性和完备性,可以在 Protege 中启用推理器(Reasoner),如 HermiT 或 Pellet。这有助于自动推导隐含的信息,并检测潜在冲突[^5]。 #### 小型 Demo 实践 以下是简单的步骤指南: 1. 创建一个新的 OWL 文件项目; 2. 添加顶层概念 Class 并逐步细化其子类; 3. 设计 Object Property 来关联不同类型的 Classes; 4. 测试 Reasoner 功能确认模型无误; 5. 导出最终成果为 RDF/XML 或其他兼容格式保存分享给团队成员进一步扩展优化。 ```python # 示例 Python 脚本展示如何加载本地 owl 文件并通过 rdflib 库解析部分信息 from rdflib import Graph, URIRef def load_and_query_ontology(owl_file_path): g = Graph() result = g.parse(owl_file_path) query = """ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?subject ?predicate ?object WHERE { ?subject rdf:type ?object . } """ qres = g.query(query) for row in qres: print(f"{row.subject} is a type of {row.object}") load_and_query_ontology('example.owl') ```
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王清欢Randy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值