【知识图谱】构建红楼梦知识图谱
在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: continueprint("當前行數:",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","女"效果
參考:
1、https://blog.csdn.net/RHJlife/article/details/108586578
2、https://blog.csdn.net/qq_33619378/article/details/83037106?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160760510919724816676406%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160760510919724816676406&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-1-83037106.pc_search_result_no_baidu_js&utm_term=jupter&spm=1018.2118.3001.4449
3、https://blog.csdn.net/weixin_45663905/article/details/107916234?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160760560519215668853228%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160760560519215668853228&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-3-107916234.pc_search_result_no_baidu_js&utm_term=no%20module%20named%20pip&spm=1018.2118.3001.4449
4、https://blog.csdn.net/kyle870322/article/details/88643018?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160760655519726885896346%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160760655519726885896346&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-1-88643018.pc_search_result_no_baidu_js&utm_term=Consider%20using%20the%20`--user`%20option%20or%20check%20the%20permissions.&spm=1018.2118.3001.4449
總結
以上是生活随笔為你收集整理的【知识图谱】构建红楼梦知识图谱的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 渗透测试入门19之渗透测试工具2
- 下一篇: 血战麻将算法