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

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

被折叠的 条评论
为什么被折叠?



