实体链接标注平台搭建与使用

JuTzungKuei 发表于 2022/08/19 14:33:43 2022/08/19
【摘要】 从零到一构建实体链接标注平台,并初步使用。

实体链接标注平台搭建与使用

0、准备环境

Windows 10
Python 3
Java 8

1、标注工具 INCEpTION

2、准备数据

  • 待标注数据,demo.txt
完颜康的妻子是谁?
曾阿牛会哪些武功?
小龙女喜欢过儿。
  • 图谱数据,person.nt
<http://www.example.org/3> <http://www.w3.org/2000/01/rdf-schema#label> "张君宝" .
<http://www.example.org/1> <http://www.w3.org/2000/01/rdf-schema#label> "张无忌" .
<http://www.example.org/5> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/实体> .
<http://www.example.org/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/实体> .
<http://www.example.org/4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/实体> .
<http://www.example.org/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/实体> .
<http://www.example.org/2> <http://www.w3.org/2000/01/rdf-schema#label> "郭靖" .
<http://www.example.org/实体> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://www.example.org/4> <http://www.w3.org/2000/01/rdf-schema#label> "杨过" .
<http://www.example.org/3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/实体> .
<http://www.example.org/5> <http://www.w3.org/2000/01/rdf-schema#label> "杨康" .
  • 图谱数据构建脚本
# 安装:python -m pip instal rdflib
from rdflib import Graph, URIRef, Literal

BASE_PREFIX = "http://www.example.org/{}"
CLASS_IRI = "http://www.w3.org/2000/01/rdf-schema#Class"           # 概念
TYPE_IRI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"       # 类型
LABEL_IRI = "http://www.w3.org/2000/01/rdf-schema#label"           # 概念实例

def create_hwkg_rdf():
    g = Graph()
    concept = URIRef(BASE_PREFIX.format("实体"))               # 概念id
    g.add((concept, URIRef(TYPE_IRI), URIRef(CLASS_IRI)))      # 概念id的type是概念

    entity_list = ["张无忌", "郭靖", "张君宝", "杨过", "杨康"]
    for idx, ent in enumerate(entity_list, 1):
        ent_iri = URIRef(BASE_PREFIX.format(str(idx)))
        g.add((ent_iri, URIRef(TYPE_IRI), concept))        # 实体id的type是概念id
        g.add((ent_iri, URIRef(LABEL_IRI), Literal(ent)))  # 实体id的labe是xx文本

    g.serialize('person.nt', format='nt', encoding='utf-8')

if __name__ == "__main__":
    create_hwkg_rdf()

3、使用教程

  • 1、左上角点击Create new project,输入项目名“实体链接”,右下角点击Save

  • 2、点击Knowledge Bases,点击Create,填写参数“Name”、“Base Prefix”、“Type”,点击Next。选择本地图谱数据文件,点击Next,参数“IRI Schema”选择RDF,点击Finish。左下角会显示创建图谱成功,导入数据成功。

  • 3、点击Layers,选择“Named entity”,参数“Granularity”选择Character-level,点击Save。点击Features里面的identifier[],配置参数,“Allowed values”选择instances only,“Knowledge base”选择刚刚创建的person,点击Save

  • 4、点击Documents,选择本地待标注数据demo.txt,“Format”选择Plain text (one sentence per line),点击Import,左下角会显示导入成功。

  • 5、点击左上角Dashboard,选择Annotation,选择相关用户、文件,点击Open,进入到标注页面。

  • 6、右上角“Layer”选择Named entity,开始标注。框选文本,右侧identifier可以搜索候选实体名

  • 7、导出数据,标注页面,点击左上角左起第二个图标,“Format”选择UIMA CAS JSON,点击Export,完成导出。

4、参考链接

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请发送邮件至:cloudbbs@huaweicloud.com;如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。