neo4j是我们实训才接触到的,作为一个初学者,在初步了解过后总想着去摸索其它的玩儿意,想着自己太喜欢玩王者荣耀了,就根据王者的阵营,用neo4j自己做了个图。

首先要用python连接neo4j的数据库

from py2neo import Node,Graph,Relationship,NodeMatcher
test2= Graph('http://localhost:7474',username='neo4j',password='neo4j')

创建节点

test_node_1 = Node("长安",name="武则天")
test_node_2 = Node("长安",name="上官婉儿")
test_node_3 = Node("长安",name="狄仁杰")
test_node_4 = Node("长安",name="李白")
test_node_5 = Node("长安",name="程咬金")
test_node_6 = Node("长安",name="明世隐")
test_node_7 = Node("长安",name="云樱")
test_node_8 = Node("长安",name="姜子牙")
test2.create(test_node_1)
test2.create(test_node_2)
test2.create(test_node_3)
test2.create(test_node_4)
test2.create(test_node_5)
test2.create(test_node_6)
test2.create(test_node_7)
test2.create(test_node_8)

创建武则天的人物关系

node_1_call_node_2 = Relationship(test_node_1,'主仆',test_node_2)
node_1_call_node_6 = Relationship(test_node_1,'谋士',test_node_6)
node_1_call_node_5 = Relationship(test_node_1,'臣子',test_node_5)
node_1_call_node_8 = Relationship(test_node_1,'徒弟',test_node_8)
node_1_call_node_4 = Relationship(test_node_1,'良才',test_node_4) test2.create(node_1_call_node_2)
test2.create(node_1_call_node_6)
test2.create(node_1_call_node_5)
test2.create(node_1_call_node_8)
test2.create(node_1_call_node_4)

创建狄仁杰的人物关系

node_3_call_node_1 = Relationship(test_node_3,'臣子',test_node_1)
node_3_call_node_7 = Relationship(test_node_3,'助手',test_node_7)
node_3_call_node_4 = Relationship(test_node_3,'逮捕对象',test_node_4)
node_3_call_node_2 = Relationship(test_node_3,'同盟',test_node_2)
node_3_call_node_6 = Relationship(test_node_3,'疑犯',test_node_6)test2.create(node_3_call_node_1)
test2.create(node_3_call_node_7)
test2.create(node_3_call_node_4)
test2.create(node_3_call_node_2)
test2.create(node_3_call_node_6)

添加新的节点

test_node_9 = Node("长安",name="裴擒虎")
test_node_10 = Node("长安",name="司空震")
test_node_11 = Node("长安",name="杨玉环")
test_node_12 = Node("长安",name="公孙离")
test_node_13 = Node("长安",name="奕星")
test_node_14 = Node("长安",name="苏烈")test2.create(test_node_9)
test2.create(test_node_10)
test2.create(test_node_11)
test2.create(test_node_12)
test2.create(test_node_13)
test2.create(test_node_14)

创建李白人物关系

node_4_call_node_3 = Relationship(test_node_4,'治安官',test_node_3)
node_4_call_node_14 = Relationship(test_node_4,'好友',test_node_14)test2.create(node_4_call_node_3)
test2.create(node_4_call_node_14)

创建杨玉环人物关系

node_11_call_node_9 = Relationship(test_node_11,'同伴',test_node_9)
node_11_call_node_12 = Relationship(test_node_11,'同伴',test_node_12)
node_11_call_node_13 = Relationship(test_node_11,'同伴',test_node_13)
node_11_call_node_6 = Relationship(test_node_11,'首领',test_node_6)test2.create(node_11_call_node_9)
test2.create(node_11_call_node_12)
test2.create(node_11_call_node_13)
test2.create(node_11_call_node_6)

创建裴擒虎人物关系

node_9_call_node_6 = Relationship(test_node_9,'首领',test_node_6)
node_9_call_node_12 = Relationship(test_node_9,'同伴',test_node_12)
node_9_call_node_13 = Relationship(test_node_9,'同伴',test_node_13)
node_9_call_node_11 = Relationship(test_node_9,'同伴',test_node_11)
node_9_call_node_7 = Relationship(test_node_9,'不打不相识',test_node_7)test2.create(node_9_call_node_6)
test2.create(node_9_call_node_12)
test2.create(node_9_call_node_13)
test2.create(node_9_call_node_11)
test2.create(node_9_call_node_7)

创建云樱人物关系

node_7_call_node_5 = Relationship(test_node_7,'忘年交',test_node_5)
node_7_call_node_10 = Relationship(test_node_7,'世叔',test_node_10)
node_7_call_node_3 = Relationship(test_node_7,'老大',test_node_3)
node_7_call_node_9 = Relationship(test_node_7,'不打不相识',test_node_9)test2.create(node_7_call_node_5)
test2.create(node_7_call_node_10)
test2.create(node_7_call_node_3)
test2.create(node_7_call_node_9)

最后就是我本次做的一个总体图

我是刚开始接触这个,所以写的代码比较复杂,也是想让我这样的初学者能够慢慢的看懂。有改进的地方请多指教。

neo4j-python案例王者人物关系相关推荐

  1. Python来袭,教你用Neo4j构建“复联4”人物关系图谱!没有剧透!【文末赠书】...

    讲技术之前先引个好玩的热点话题,带你与时代接轨~ 漫威系列电影<复仇者联盟4>上映 你去看了吗? 小编就盼着周末去好好享受 谁剧透,跟谁急! 复仇者联盟 之 绝对不剧透 漫威英雄们为了不让 ...

  2. python 红楼梦 人物关系_用Python来理一理红楼梦里的这些关系

    原标题:用Python来理一理红楼梦里的这些关系 最近把红楼梦又抽空看了一遍,古典中的经典,我真无法用言辞赞美她.今天,想跟大家一起用 Python 来理一理红楼梦中的的那些关系 不要问我为啥是红楼梦 ...

  3. python代码电影人物关系_Python基于network模块制作电影人物关系图

    Python基于network模块制作电影人物关系图,节点,值为,模块,关系,算法 Python基于network模块制作电影人物关系图 易采站长站,站长之家为您整理了Python基于network模 ...

  4. python人物关系抽取小说_用python分析小说人物关系(一)——理论篇

    1.工具介绍 jieba jieba分词,最好用的开源中文分词工具.他最主要的两个功能是分词和关键词的抽取.在这里,我们需要用他的分词功能来提取文本中的人名. gephi gephi是一个开源的复杂网 ...

  5. Python实现小说人物关系输出(完整+修正)

    这篇博客提供能够输出小说人物关系的完整python代码. 代码的原作者是Qingyu Mao,十分感谢!! 以下是Mao的github链接和博客教程链接: @source: https://githu ...

  6. python 小说人物分析_用python分析小说人物关系(二)——实战篇

    用到的工具jieba jieba分词,最好用的开源中文分词工具.他最主要的两个功能是分词和关键词的抽取.在这里我们需要用他的分词功能来提取文本中的人名. gephi gephi是一个开源的复杂网络数据 ...

  7. python代码电影人物关系_以腾讯5000部电影为例,告诉你Python数据分析该怎么做...

    上一篇文章(Python爬虫帮助解决挑选电影费时费力的烦恼),我们对腾讯视频中的电影按照"豆瓣好评"的方式进行了数据爬虫,获取了大约5000部电影的详情数据,解决了选择电影时比较浪 ...

  8. python代码电影人物关系_自动更新高清电影文件中文名python代码

    1.[代码][Python]代码 #coding:utf-8 import urllib, urllib2, cookielib import os, time import re def login ...

  9. python 求连线相似度_Python分析《都挺好》中的人物关系,苏大强与蔡根花是真爱?...

    如今大火的电视剧<都挺好>源于阿耐的同名小说,今天我们来对这部小说使用python分析一下人物关系.本文主要使用google推出的word2vec进行分析.使用的库主要有jieba.gen ...

最新文章

  1. 自由自在休闲食品引领时尚潮流
  2. python的learn_python_learn1
  3. java class类型参数_java – 如何从通用类型参数获取`.class`属性?
  4. 转载:https://blog.csdn.net/dcrmg/article/details/52939318
  5. bzoj千题计划241:bzoj3864: Hero meet devil
  6. 农用地包括哪些地类_土地地类一览表
  7. Nodejs 离线文档下载
  8. 38. DOM 操作
  9. mysql基本语法 外键_MySQL语法创建外键?
  10. block的名词形式_block是什么意思_block在线翻译_英语_读音_用法_例句_海词词典
  11. 数据结构:图的深度优先遍历和广度优先遍历
  12. 计算机专业个税,税后工资个税计算器
  13. Windows与USB的通信
  14. Echarts实现图表下钻
  15. Unity 场景切换间的内存清理
  16. 计算机知识竞赛策划书前言,计算机知识竞赛策划书范文.docx
  17. java 彩票走势图算法
  18. 导出excel,后台执行,前台无反应
  19. vue监听手机键盘搜索事件
  20. 澳门大学沈建冰教授招收全额奖学金博士生/博士后

热门文章

  1. 用jquery简单的实现京东轮播图效果
  2. 敏捷项目管理-如何破解敏捷实践中的三大难题
  3. 双击 计算机 网络打不开,win10系统双击“计算机”打不开的处理步骤
  4. 基于REM的CSS在Android4.4及5.0部分机型出现布局错乱
  5. Java - Java Web开发的Model 1和Model 2分别指的是什么?
  6. 80后清新优雅小别墅 尽显小资生活情调
  7. WINDOW -- U盘做启动盘重装系统
  8. 显卡吧超级计算机,残暴8路Tesla V100:NVIDIA 英伟达 发布 HGX-1 超级计算机
  9. 项目自动化部署与手动部署
  10. 三维可视化数据中心机房监控管理系统