其他分享
首页 > 其他分享> > Neo4j学习笔记(持续更新)

Neo4j学习笔记(持续更新)

作者:互联网

目录

什么是Neo4j

Neo4j是一种以网络(或者称为图形结构)为储存形式的数据库,相比于关系型数据库,这种图数据库有着更高的性能,而Neo4j是其中最流行的那个

什么是知识图谱

在Neo4j数据库中,知识图谱就是储存数据的载体,由节点(Node)和关系(Relationship)组成
Neo4j官方给出的示例如图(没有完全展开):
在这里插入图片描述

环境

Neo4j Desktop - 1.4.14
jdk-15
(下载安装配置环境比较无脑,随便找点博客教程就行了)

Neo4j数据库的语言

Cypher是Neo4j数据库的语言
官方给出的示例:

      CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
      CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
      CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
      CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
      CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
      CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
      CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
      CREATE (JoelS:Person {name:'Joel Silver', born:1952})
      CREATE
      (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
      (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
      (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
      (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
      (LillyW)-[:DIRECTED]->(TheMatrix),
      (LanaW)-[:DIRECTED]->(TheMatrix),
      (JoelS)-[:PRODUCED]->(TheMatrix)

      CREATE (Emil:Person {name:"Emil Eifrem", born:1978})
      CREATE (Emil)-[:ACTED_IN {roles:["Emil"]}]->(TheMatrix)

当然这只是一小部分,完整的代码有508行
第一行CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})创建了一个ID为TheMatrix的节点,其标签为Movie,中括号中的title、released、tagline都是Movie类型节点的properties
接下来的七行创建了七个Person,显然他们都是黑客帝国的演员或导演或制片人
再接下来的八行创建了这七个人与TheMatrix的关系

CREATE
      (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
      (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
      (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
      (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
      (LillyW)-[:DIRECTED]->(TheMatrix),
      (LanaW)-[:DIRECTED]->(TheMatrix),
      (JoelS)-[:PRODUCED]->(TheMatrix)

(感觉很简单但不完全简单)
来点别人的博客
图数据库之Cypher语言

标签:roles,CREATE,更新,Person,TheMatrix,笔记,Neo4j,ACTED
来源: https://blog.csdn.net/Hoppinging/article/details/123306602