HugeGraph图数据库构建红楼梦人物关系知识图谱实例

本文介绍使用HugeGraph图数据库及其可视化工具HugeGraph-Studio,通过执行Gremlin语句构建《红楼梦》中贾府人物关系的知识图谱。详细步骤包括定义属性、顶点类型、边类型,添加人物节点和关系边,最终形成可视化的家族网络。

HugeGraph是一款易用、高效、通用的开源图数据库系统(Graph Database,GitHub项目地址), 实现了Apache TinkerPop3框架及完全兼容Gremlin查询语言, 具备完善的工具链组件,助力用户轻松构建基于图数据库之上的应用和产品。

HugeGraph-Studio:HugeGraph-Studio是HugeGraph的Web可视化工具,可用于执行Gremlin语句及展示图。

本文详细介绍在HugeGraph-Studio可视化界面上执行Gremlin语句构建红楼梦贾府人物关系知识图谱的实例。

1、添加属性:人物的姓名、性别、备注,根源的名称

graph.schema().propertyKey("姓名").asText().ifNotExist().create()
graph.schema().propertyKey("性别").asText().ifNotExist().create()
graph.schema().propertyKey("备注").asText().ifNotExist().create()
graph.schema().propertyKey("名称").asText().ifNotExist().create()

2、添加顶点类型VertexLabel:人物类型、根源类型

person = graph.schema().vertexLabel("人物").properties("姓名", "性别", "备注").primaryKeys("姓名").ifNotExist().create()
root = graph.schema().vertexLabel("根源").properties("名称", "备注").primaryKeys("名称").ifNotExist().create()

3、添加边类型(EdgeLabel):人物关系:夫妻、子女、小妾、丫鬟等,根源关系:继承

spouse = graph.schema().edgeLabel("夫妻").sourceLabel("人物").targetLabel("人物").ifNotExist().create()
children = graph.schema().edgeLabel("子女").sourceLabel("人物").targetLabel("人物").ifNotExist().create()
concubine = graph.schema().edgeLabel("小妾").sourceLabel("人物").targetLabel("人物").ifNotExist().create()
servant = graph.schema().edgeLabel("丫鬟").sourceLabel("人物").targetLabel("人物").ifNotExist().create()
extend = graph.schema().edgeLabel("继承").sourceLabel("根源").targetLabel("人物").ifNotExist().create()

4、添加顶点Vertex:根源、人物

jiajia = graph.addVertex(T.label, "根源", "名称", "贾家", "备注", "贾家血缘")
jia

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值