实体链接标注平台搭建与使用
实体链接标注平台搭建与使用
0、准备环境
Windows 10
Python 3
Java 8
1、标注工具 INCEpTION

-
工具下载:https://github.com/inception-project/inception/releases
-
推荐Java8最后一个版本【第6页】:
0.17.3,即:inception-app-standalone-0.17.3.jar,其他高版本须Java11 -
启动命令:
java -jar inception-app-standalone-0.17.3.jar

-
浏览器访问:
http://localhost:8080/,初始账号/密码:admin/admin

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、参考链接
- 实体链接(EL)标注器使用(避坑)指南:https://zhuanlan.zhihu.com/p/267044346
- 知识推理之基于rdflib的RDF文件构建与使用(二):https://bbs.huaweicloud.com/blogs/281757
- 点赞
- 收藏
- 关注作者


评论(0)