【知识图谱】构建红楼梦知识图谱
在b站看到有人用知识图谱构建红楼梦的人物关系的知识图谱,跟着做了一遍,在这里记录。1、安装neo4j具体见:https://blog.csdn.net/Zhouzi_heng/article/details/1109489972、为python安装py2neo4jpy2neo是一个社区第三方库,通过它可以更为便捷地使用python来操作neo4j这里需要进入python的安装目录下,再进入Scri
在b站看到有人用知识图谱构建红楼梦的人物关系的知识图谱,跟着做了一遍,在这里记录。
1、安装neo4j
具体见:https://blog.csdn.net/Zhouzi_heng/article/details/110948997
2、为python安装py2neo4j
py2neo是一个社区第三方库,通过它可以更为便捷地使用python来操作neo4j
这里需要进入python的安装目录下,再进入Scripts里面
在dos界面下输入
pip install py2neo
出现错误
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'd:\\python\\lib\\site-packages\\~ywin32_system32\\pywintypes36.dll'
Consider using the `--user` option or check the permissions.
【解决】
加上--user即可
pip install --user py2neo
再次安装,成功。
3、安装Jupyter Notebooks
Jupyter Notebook是一个Web应用程序,允许您创建和共享包含实时代码,方程,可视化和说明文本的文档。 用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等。
Notebooks其实就像是你的python笔记本一样,不仅可以运行书写的python代码,同时还支持markdown格式的文本显示。在Notebooks中不仅可以运行python,它还支持R、Julia 和 JavaScript等其他40余种语言。
这里使用pip安装
pip install jupyter
正常安装即可。
完成后打开命令提示窗,切换到python3.6的安装目录下的Scripts
文件夹。执行如下命令
jupyter notebook
出现如下提示,启动成功,并且浏览器自动打开notebook窗口。此时显示的是Script
文件夹下的文件目录。
会自己打开notebook窗口
对这里简单介绍一下
第一部分介绍:
Files:列出所有文件
Running:展示你当前打开的终端和笔记本
Clusters:由 IPython 并行提供的
第二部分介绍:
点击右侧的New
按钮可展开如图的下拉列表按钮,其内包括了可创建的四种工作环境:
Python3:创建一个可以执行python代码的文件
Text File:创建文本类型的文件,后缀名为.txt
Folder:创建一个文件夹
Teminal:在浏览器中打开一的命令窗口
我们这里用选的是python3
4、构建红楼梦知识图谱
基础代码
#导入包
import csv
import py2neo
from py2neo import Graph,Node,Relationship,NodeMatcher
#账号密码改为自己的即可
g=Graph('http://localhost:7474',user='neo4j',password='neo4j')
with open('/Users/ren/Desktop/triples.csv','r',encoding='utf-8') as f:
reader=csv.reader(f)
for item in reader:
if reader.line_num==1:
continue
print("当前行数:",reader.line_num,"当前内容:",item)
start_node=Node("Person",name=item[0])
end_node=Node("Person",name=item[1])
relation=Relationship(start_node,item[3],end_node)
g.merge(start_node,"Person","name")
g.merge(end_node,"Person","name")
g.merge(relation,"Person","name")
数据集
"head","tail","relation","label"
"贾代善","贾源","son","子"
"娄氏","贾源","daughter_in_law_of_grandson","重孙媳妇"
"贾母","贾代善","wife","妻"
"老姨奶奶","贾代善","concubine","妾"
"贾敏","贾代善","daughter","女"
"嫣红","贾赦","concubine","妾"
"翠云","贾赦","concubine","妾"
"娇红","贾赦","concubine","妾"
"贾迎春","贾赦","daughter","女"
"赵姨娘","贾政","concubine","妾"
"周姨娘","贾政","concubine","妾"
"贾珠","贾政","son","子"
"尤二姐","贾琏","concubine","妾"
"秋桐","贾琏","concubine","妾"
"平儿","贾琏","concubine","妾"
"薛宝衩","贾宝玉","wife","妻"
"花袭人","贾宝玉","concubine","妾"
"贾桂","贾宝玉","son","子"
"贾菌","娄氏","son","子"
"周秀才","贾巧姐","brother_in_law","姐夫"
"周财主","周秀才","father","父亲"
"周妈妈","周秀才","mother","母亲"
"孙亲太太","孙绍祖","mother","母亲"
"刑大舅二姐","邢夫人","younger_sister","妹"
"邢德全","邢夫人","younger_brother","弟"
"张大老爷","邢夫人","old_relatives","老亲"
"邢忠","邢夫人","elder_brother","兄"
"张大老爷之女","张大老爷","daughter","女"
"刑秞烟","邢忠","daughter","女"
"李婶","李守中","sister_in_law","弟媳"
"李婶之弟","李婶","younger_brother","弟"
"李纹","李婶","daughter","女"
"甄宝玉","李绮","husband","夫"
"甄应嘉","甄宝玉祖母","son","子"
"甄夫人","甄应嘉","wife","妻"
"大姑娘","甄应嘉","daughter","女"
"二姑娘","甄应嘉","daughter","女"
"三姑娘","甄应嘉","daughter","女"
"袭人之母","袭人","mother","母亲"
"花自芳","袭人","elder_brother","兄"
"周琼之子","贾探春","husband","夫"
"林如海之父","林如海","father","父亲"
"林如海之祖","林如海","grandfather","祖父"
"林如海之子","林如海","son","子"
"李妈","贾巧姐","nurser","乳母"
"昭儿","贾琏","servant","奴仆"
"兴儿","贾琏","servant","奴仆"
"隆儿","贾琏","servant","奴仆"
"庆儿","贾琏","servant","奴仆"
"赵嬷嬷","贾琏","nurser","乳母"
"赵天梁","赵嬷嬷","son","子"
"赵天栋","赵嬷嬷","son","子"
"王信","贾琏","servant","奴仆"
"王信媳妇","贾琏","servant","奴仆"
"鲍二","贾琏","servant","奴仆"
"善姐","尤二姐","servant_girl","丫鬟"
"迎春乳母","贾迎春","nurser","乳母"
"王住儿媳妇","迎春乳母","daughter_in_law","子媳"
"绣桔","贾迎春","servant_girl","丫鬟"
"莲花儿","贾迎春","servant_girl","丫鬟"
"秦思祺","贾迎春","servant_girl","丫鬟"
"潘又安","秦思祺","boy_friend","男友"
"贾琮奶妈","贾琮","nurser","乳母"
"篆儿","刑秞烟","servant_girl","丫鬟"
"新进来的奶子","贾兰","nurser","奶妈"
"素云","李纨","servant_girl","丫鬟"
"碧月","李纨","servant_girl","丫鬟"
"抱琴","贾元春","servant_girl","丫鬟"
"李嬷嬷","贾宝玉","nurser","乳母"
"赵嬷嬷","贾宝玉","nurser","乳母"
"张嬷嬷","贾宝玉","nurser","乳母"
"宋嬷嬷","贾宝玉","servant","奴仆"
"叶茗烟","贾宝玉","servant","奴仆"
"锄药","贾宝玉","servant","奴仆"
"扫红","贾宝玉","servant","奴仆"
"墨雨","贾宝玉","servant","奴仆"
"引泉","贾宝玉","servant","奴仆"
"扫花","贾宝玉","servant","奴仆"
"挑云","贾宝玉","servant","奴仆"
"伴鹤","贾宝玉","servant","奴仆"
"双瑞","贾宝玉","servant","奴仆"
"双寿","贾宝玉","servant","奴仆"
"老叶妈","叶茗烟","mother","母亲"
"李贵","李嬷嬷","son","子"
"李嬷嬷孙子","贾宝玉","servant","奴仆"
"王荣","贾宝玉","servant","奴仆"
"张若锦","贾宝玉","servant","奴仆"
"赵亦华","贾宝玉","servant","奴仆"
"周瑞","王夫人","servant","奴仆"
"周瑞女儿","周瑞","daughter","女"
"冷子兴","周瑞","son_in_law","女婿"
"周嫂子的儿子","周瑞","son","子"
"何三","周瑞","adopted_son","干儿子"
"白金钏","王夫人","servant_girl","丫鬟"
"白玉钏","王夫人","servant_girl","丫鬟"
"彩云","王夫人","servant_girl","丫鬟"
"彩鸾","王夫人","servant_girl","丫鬟"
"绣鸾","王夫人","servant_girl","丫鬟"
"绣凤","王夫人","servant_girl","丫鬟"
"白老媳妇","白金钏","mother","母亲"
"白老媳妇","白玉钏","mother","母亲"
"彩霞之母","彩霞","mother","母亲"
"小霞","彩霞","younger_sister","妹"
"小鹊","赵姨娘","servant_girl","丫鬟"
"小吉祥","赵姨娘","servant_girl","丫鬟"
"赵国基","赵姨娘","elder_brother","兄"
"钱槐","赵姨娘","elder_male_cousin","表兄"
"钱槐","贾环","servant","奴仆"
"雪雁","林黛玉","servant_girl","丫鬟"
"王嬷嬷","林黛玉","nurser","乳母"
"紫鹊","林黛玉","servant_girl","丫鬟"
"春纤","林黛玉","servant_girl","丫鬟"
"藕官","林黛玉","servant_girl","丫鬟"
"赖嬷嬷","赖大","mother","母亲"
"赖尚荣","赖大","son","子"
"赖大的女儿","赖大","daughter","女"
"来旺儿","王熙凤","servant","奴仆"
"旺儿媳妇","王熙凤","servant_girl","丫鬟"
"来喜家的","王熙凤","servant","奴仆"
"丰儿","王熙凤","servant_girl","丫鬟"
"彩明","王熙凤","servant_girl","丫鬟"
"林红玉","王熙凤","servant_girl","丫鬟"
"林之孝","林红玉","father","父亲"
"王善保","邢夫人","servant","奴仆"
"费婆子","邢夫人","servant_girl","丫鬟"
"金鸳鸯","贾母","servant_girl","丫鬟"
"琥珀","贾母","servant_girl","丫鬟"
"鹦鹉","贾母","servant_girl","丫鬟"
"珍珠","贾母","servant_girl","丫鬟"
"翡翠","贾母","servant_girl","丫鬟"
"玻璃","贾母","servant_girl","丫鬟"
"文官","贾母","servant_girl","丫鬟"
"傻大姐的娘","傻大姐","mother","母亲"
"金彩","鸳鸯","father","父亲"
"金文翔","鸳鸯","elder_brother","兄"
"多官","晴雯","elder_male_cousin","表哥"
"多浑虫父亲","晴雯","mothers_brother","舅"
"多姑娘儿","多官","wife","妻"
"吴贵","晴雯","elder_male_cousin","表兄"
"花芳官","贾宝玉","servant_girl","丫鬟"
"媚人","贾宝玉","servant_girl","丫鬟"
"麝月","贾宝玉","servant_girl","丫鬟"
"茜雪","贾宝玉","servant_girl","丫鬟"
"秋纹","贾宝玉","servant_girl","丫鬟"
"绮霞","贾宝玉","servant_girl","丫鬟"
"碧痕","贾宝玉","servant_girl","丫鬟"
"檀云","贾宝玉","servant_girl","丫鬟"
"四儿","贾宝玉","servant_girl","丫鬟"
"佳蕙","贾宝玉","servant_girl","丫鬟"
"坠儿","贾宝玉","servant_girl","丫鬟"
"紫绡","贾宝玉","servant_girl","丫鬟"
"良儿","贾宝玉","servant_girl","丫鬟"
"何春燕","贾宝玉","servant_girl","丫鬟"
"厨房中的柳家媳妇","柳五儿","mother","母亲"
"柳二媳妇的妹子","柳五儿","younger_sister","妹"
"哥嫂侄儿","柳五儿","nephew","侄"
"侍书","贾探春","servant_girl","丫鬟"
"翠墨","贾探春","servant_girl","丫鬟"
"艾官","贾探春","servant_girl","丫鬟"
"小蝉","贾探春","servant_girl","丫鬟"
"何婆","何春燕","mother","母亲"
"何婆","芳官","adopted_mother","干娘"
"小鸠儿","何春燕","younger_sister","妹"
"夏婆子","何春燕","maternal_aunt","姨妈"
"夏婆子","藕官","adopted_mother","干娘"
"夏婆子","小蝉","grandmother","外祖母"
"蒋玉菡","贾宝玉","friend","朋友"
"通判傅试","贾政","pupil","门生"
"傅秋芳","傅试","younger_sister","妹"
"太祖皇帝","先皇","father","父亲"
"太上皇","先皇","son","子"
"皇太后","太上皇","wife","妻"
"太妃","太上皇","kings_concubine","嫔妃"
"皇帝","太上皇","son","子"
"贾元春","皇帝","imperial_concubine","妃"
"吴贵妃","皇帝","imperial_concubine","妃"
"周贵人","皇帝","imperial_concubine","妃"
"周贵人父亲","周贵人","father","父亲"
"吴天佑","吴贵妃","father","父亲"
"戴权","皇帝","minister","臣"
"夏守忠","皇帝","minister","臣"
"贾代化","贾演","son","子"
"焦大","贾演","servant","奴仆"
"贾敷","贾代化","son","子"
"贾敬","贾代化","son","子"
"贾惜春","贾敬","daughter","女"
"史湘云爷爷","史侯","son","子"
"史鼐","史湘云爷爷","son","子"
"史鼎","史湘云爷爷","son","子"
"湘云母","史湘云爷爷","daughter_in_law","儿媳"
"史鼎的夫人","史鼎","wife","妻"
"史湘云","湘云母","daughter","女"
"卫若兰","史湘云","husband","夫"
"翠缕","史湘云","servant_girl","丫鬟"
"葵官","史湘云","servant_girl","丫鬟"
"周奶妈","史湘云","nurser","乳母"
"凤姐之祖王夫人之父","王公","son","子"
"王夫人之大兄凤姐之父","凤姐之祖王夫人之父","son","子"
"王子腾","凤姐之祖王夫人之父","son","子"
"王子胜","凤姐之祖王夫人之父","son","子"
"王夫人","凤姐之祖王夫人之父","daughter","女"
"薛姨妈","凤姐之祖王夫人之父","daughter","女"
"王成父","凤姐之祖王夫人之父","nephew","侄"
"老舅太太","王夫人之大兄凤姐之父","wife","妻"
"王仁","王夫人之大兄凤姐之父","son","子"
"王熙凤","王夫人之大兄凤姐之父","daughter","女"
"王子腾夫人","王子腾","wife","妻"
"王子腾之女","王子腾","daughter","女"
"保宁侯之子","王子腾之女","husband","夫"
"王成","王成父","son","子"
"王狗儿","王成","son","子"
"刘氏","王狗儿","wife","妻"
"王青儿","王狗儿","daughter","女"
"王板儿","王狗儿","son","子"
"刘姥姥","刘氏","mother","母亲"
"宝钗祖父","薛公","son","子"
"薛公之孙","宝钗祖父","son","子"
"薛宝琴父","宝钗祖父","son","子"
"薛姨妈","薛公之孙","wife","妻"
"薛宝钗","薛公之孙","daughter","女"
"薛蟠","薛公之孙","son","子"
"同喜","薛姨妈","servant_girl","丫鬟"
"同贵","薛姨妈","servant_girl","丫鬟"
"莺儿","薛宝钗","servant_girl","丫鬟"
"文杏","薛宝钗","servant_girl","丫鬟"
"喜儿","薛宝钗","servant_girl","丫鬟"
"蕊官","薛宝钗","servant_girl","丫鬟"
"夏金桂","薛蟠","wife","妻"
"老苍头","薛蟠","meme_ama","乳父"
"宝蟾","夏金桂","servant_girl","丫鬟"
"小舍儿","夏金桂","servant_girl","丫鬟"
"夏奶奶","夏金桂","mother","母亲"
"夏三","夏奶奶","son","子"
"臻儿","香菱","servant_girl","丫鬟"
"薛宝琴母","薛宝琴父","wife","妻"
"薛蝌","薛宝琴父","son","子"
"薛宝琴","薛宝琴父","daughter","女"
"邢岫烟","薛蝌","wife","妻"
"梅翰林之子","薛宝琴","husband","夫"
"小螺","薛宝琴","servant_girl","丫鬟"
"荳官","薛宝琴","servant_girl","丫鬟"
"梅翰林","梅翰林之子","father","父亲"
"贾瑞之父","贾代儒","son","子"
"贾瑞之母","贾瑞之父","wife","妻"
"贾瑞","贾瑞之父","son","子"
"贾琼","贾琼之母","son","子"
"贾四姐","贾琼之母","daughter","女"
"贾王扁","贾王扁之母","son","子"
"贾喜鸾","贾王扁之母","daughter","女"
"贾芸","五嫂子卜氏","son","子"
"卜世仁","五嫂子卜氏","brother","兄弟"
"小丫头子","贾芸","servant_girl","丫鬟"
"倪儿娘子","倪二","wife","妻"
"倪二女儿","倪二","daughter","女"
"马贩子王短腿","倪二","friend","友人"
"卜世仁娘子","卜世仁","wife","妻"
"卜银姐","卜世仁","daughter","女"
"王奶奶","卜世仁","neighbour","邻居"
"卜世仁店里伙计","卜世仁","partner","伙计"
"贾芹","周氏","son","子"
"金氏","贾璜","wife","妻"
"胡氏","金氏","elder_sister_in_law","嫂"
"金荣","胡氏","son","子"
"娇杏","贾化","wife","妻"
"贾雨村子","贾化","son","子"
"应天府门子","贾化","son","子"
"张如圭","贾化","friend","友人"
"王老爷","贾化","friend","友人"
"天子之妻","应天府门子","wife","妻"
"东安郡王穆莳拜","东平郡王","son","子"
"南安王太妃","南安郡王","wife","妻"
"南安郡王之孙","南安郡王","grandson","孙子"
"西宁郡王之孙","西宁郡王","grandson","孙子"
"西宁郡王妃","西宁郡王","wife","妻"
"北静王太妃","北静郡王","daughter_in_law","儿媳"
"北静王少妃","水溶","wife","妻"
"北静郡王长府官","水溶","minister","臣"
"镇国公诰命","牛清","wife","妻"
"镇国公诰命长男","牛清","son","子"
"牛继宗","牛清","grandson","孙子"
"柳芳","柳彪","grandson","孙子"
"陈瑞文","陈翼","grandson","孙子"
"马尚","马魁","grandson","孙子"
"侯孝康","侯明","grandson","孙子"
"缮国公诰命","缮国公","wife","妻"
"石光珠","缮国公","grandson","孙子"
"蒋子宁","平原侯","grandson","孙子"
"谢鲸","定城侯","grandson","孙子"
"戚建辉","襄阳侯","grandson","孙子"
"裘良","景田侯","grandson","孙子"
"锦乡侯诰命","锦乡侯","wife","妻"
"韩奇","锦乡侯","son","子"
"冯紫英","神武将军冯唐","son","子"
"锦田侯诰命","马道婆","donor","施主"
"蕊官","地藏庵的圆心","pupil","徒弟"
"藕官","圆心","pupil","徒弟"
"智能儿","净虚","pupil","徒弟"
"智善","净虚","pupil","徒弟"
"智通","净虚","pupil","徒弟"
"于老爷","净虚","donor","施主"
"胡老爷","净虚","donor","施主"
"胡老爷太太","净虚","donor","施主"
"胡老爷公子","净虚","donor","施主"
"张大财主","净虚","donor","施主"
"花芳官","智能","pupil","徒弟"
"张金哥","张大财主","daughter","女"
"李公子","张金哥","employer","雇主"
"长安原任守备","李公子","father","父亲"
"李衙内","长安府府太爷","mothers_brother","小舅子"
"贾代化","贾演","son","子"
"焦大","贾演","servant","奴仆"
"贾敷","贾代化","son","子"
"贾敬","贾代化","son","子"
"尤氏","尤老娘","daughter","女"
"贾蔷","贾演","great_great_grandson","玄孙"
"龄官","贾蔷","girl_friend","女友"
"佩凤","贾珍","concubine","妾"
"偕鸾","贾珍","concubine","妾"
"文花","贾珍","concubine","妾"
"茄官","尤氏","servant_girl","丫鬟"
"银蝶","尤氏","servant_girl","丫鬟"
"炒豆儿","尤氏","servant_girl","丫鬟"
"秦可卿","贾蓉","wife","妻"
"胡氏","贾蓉","step_wife","续弦"
"许氏","贾蓉","step_wife","续弦"
"入画","贾惜春","servant_girl","丫鬟"
"彩屏","贾惜春","servant_girl","丫鬟"
"彩儿","贾惜春","servant_girl","丫鬟"
"瑞珠","秦可卿","servant_girl","丫鬟"
"宝珠","秦可卿","servant_girl","丫鬟"
"秦钟","秦业","son","子"
"智能儿","秦钟","girl_friend","女友"
"净虚","智能儿","master","师父"
"智善","净虚","pupil","徒弟"
"智通","净虚","pupil","徒弟"
"喜儿","贾珍","servant","奴仆"
"寿儿","贾珍","servant","奴仆"
"尤三姐","柳湘莲","girl_friend","女友"
"杏奴","柳湘莲","servant","奴仆"
"尤二姐","贾琏","concubine","妾"
"善姐","尤二姐","servant_girl","丫鬟"
"甄宝玉","李绮","husband","夫"
"贾演","贾源","elder_brother","兄"
"贾赦","贾代善","son","子"
"贾政","贾代善","son","子"
"贾敏","贾政","younger_sister","妹"
"邢夫人","贾赦","wife","妻"
"贾琏","贾赦","son","子"
"贾琮","贾赦","son","子"
"王夫人","贾政","wife","妻"
"贾元春","贾政","daughter","女"
"贾宝玉","贾政","son","子"
"贾探春","贾政","daughter","女"
"贾环","贾政","son","子"
"王熙凤","贾琏","wife","妻"
"贾巧姐","贾琏","daughter","女"
"贾兰","贾珠","son","子"
"李纨","贾珠","wife","妻"
"孙绍祖","贾迎春","husband","夫"
"李守中","李纨","father","父亲"
"李绮","李婶","daughter","女"
"甄宝玉","甄应嘉","son","子"
"林如海","贾敏","husband","夫"
"林黛玉","林如海","daughter","女"
"王嬷嬷","贾宝玉","nurser","乳母"
"彩霞","王夫人","servant_girl","丫鬟"
"傻大姐","贾母","servant_girl","丫鬟"
"晴雯","贾宝玉","servant_girl","丫鬟"
"篆儿","贾宝玉","servant_girl","丫鬟"
"柳五儿","贾宝玉","servant_girl","丫鬟"
"贾珍","贾敬","son","子"
"贾母","史侯","daughter","女"
"香菱","薛蟠","concubine","妾"
"倪二","贾芸","friend","友人"
"水溶","北静郡王","grandson","孙子"
"尤氏","贾珍","wife","妻"
"尤二姐","尤老娘","daughter","女"
"尤三姐","尤老娘","daughter","女"
"贾蓉","贾珍","son","子"
"秦可卿","秦业","daughter","女"
效果
参考:
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)