当前位置:网站首页>Basic concepts of neo4j graph database
Basic concepts of neo4j graph database
2022-06-27 05:06:00 【Thought is tightening】
brief introduction : This paper takes the movie diagram as an example , explain neo4j Figure basic concepts in database
Movie diagram
The circle in the following figure represents three nodes (node), Each node has a label representing the category (label) And attribute (properties), Such as :name、born、title、released, Nodes are connected by one-way arrows to represent the relationship between nodes (relationships), Such as :ACTED_IN、DIRECTED
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-MyWLOPT6-1656069356588)(F:/Backup/img/graph_simple.png)]](/img/17/f0d65a62e7bf1fd4001ca76093bbb4.png)
following Cycher Statement to generate the above graph structure
CREATE (:Person:Actor {name: 'Tom Hanks', born: 1956})-[:ACTED_IN {roles: ['Forrest']}]->(:Movie {title: 'Forrest Gump'})<-[:DIRECTED]-(:Person {name: 'Robert Zemeckis', born: 1951})
node node
Each circle in the movie graph represents a node (node), Each node represents an entity , The first node is analyzed in detail below ![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Hui2IOn9-1656069356589)(F:/Backup/img/graph_single_node.png)]](/img/0b/3cd2455fa89681a607557cc5cbdf38.png)
Nodes in the Person、Actor For node label (label), Nodes with the same label can be divided into the same class , Be similar to Java The concept of middle class . A node can have multiple labels , The relationship between tags is similar to that between classes ( Inherit ), In this node Actor It can be seen as Person Subclasses of ;
name:'Tom Hanks' born:1956 For node attribute (properties), Be similar to Java Properties in a class
java The implementation code is as follows
public class Person{
String name;
long born;
}
class Actor extends Person{
}
This node can be composed of the following Cypher Statements generated
CREATE (:Person:Actor {name: 'Tom Hanks', born: 1956})
Statements explain :
- Create the label to which the node belongs
:Person、:Actor - Pair with key value (key-value pairs) Declare attributes in the form of , And braces
{}Include
Relationship relationship
Describe how interconnected start and end nodes are related (describes how a connection between a source node and a target node are related), Relationships can make nodes into linked lists (list)、 Trees (tree)、 chart (map)、 Composite entities .
characteristic :
- Directional and unidirectional
- There must be a type (type) To define what kind of relationship
Must have a type (one type) to define (classify) what type of relationship it is. - Nodes can be represented by relationships that point to themselves
- Relationships can have attributes
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-hxXMjQEd-1656069356590)(F:/Backup/img/graph_example_relationship.png)]](/img/a8/77e55e0c176384bacbd460f846131c.png)
The type of relationship shown in the figure above (type) yes ACTED_IN, The attribute is roles: ['Forrest']、performance: 5
Cypher Statement for :
CREATE ()-[:ACTED_IN {roles: ['Forrest'], performance: 5}]->()
() Representation node
-[:ACTED_IN {roles: ['Forrest'], performance: 5}]-> Is a statement that declares a relationship , Key value pairs also represent attributes (properties)
attribute properties
Attributes describe nodes in the form of key value pairs (node) And relationship (relationships) The data of
Attributes can be of various data types , Such as :number、string or boolean; It can be used to store similar data array or list, Such as :strings、numbers、bollean values
CREATE (:Example {a: 1, b: 3.14}) // attribute a Storage integer Type value 1, attribute b Storage float Data of type
CREATE (:Example {c: 'This is an example string', d: true, e: false})
CREATE (:Example {f: [1, 2, 3], g: [2.71, 3.14], h: ['abc', 'example'], i: [true, true, false]})
Other concepts
Other concepts in the figure database will not be detailed for the time being , Such as :Traversals( Traverse )、paths( route )、Schema、Indexes( Indexes )、Constraints( constraint )
Add
The movie database is neo4j The official example of , You can use :guide movie-graph Command view . About attributes 、 Concepts such as tags can be verified and understood with the help of the following query statements .
Match (n)
return ID(n) as id, properties(n) AS properties, labels(n) AS label
neo4j Naming conventions in
Label of the node 、 The type of relationship 、 Attributes are case sensitive , for example : attribute name≠Name, For a moment neo4j Officially recommended naming conventions
| Graph entity | Recommended style | Example |
|---|---|---|
| Node label | Camel case, beginning with an upper-case character | :VehicleOwner rather than :vehice_owner |
| Relationship type | Upper case, using underscore to separate words | :OWNS_VEHICLE rather than :ownsVehicle |
| Property | Lower camel case, beginning with a lower-case character | firstName rather than first_name |
Comparative graph theory
In graph theory , Nodes are also called vertices (vertices ) Or point (point)
Relationships are also called edges (edges)、 link (links) Or line (lines)
Create nodes
The syntax for creating nodes , You can name the node n. Because the node name is not used as a unique identifier , Similar to temporary variables , Using the same node name does not affect the creation of the database
CREATE (n:Person {name:'Sally'}) RETURN n
CREATE (n:Person {name:'Steve'}) RETURN n
CREATE (n:Person {name:'Mike'}) RETURN n
neo4j Image export
If exported as svg, You can use vscode or notepad Edit content , lookup font-size Set font size , lookup font-family Set the font format , And then use photoshop take svg Export to png Or with the help of online transfer png Website
neo4j Interactive settings
Click on any node , A gray circle appears , Respectively represent the position of the fixed node 、 Hide nodes 、 Display other nodes related to this node
Click the tab of the node on the right Person, You can adjust the color and size of nodes
Click on the arrow , You can set the thickness and color of the arrows representing the relationship
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GA4QPan5-1656069356591)(F:/Backup/img/image-20220624190647695.png)]](/img/4c/5a8997ce0381931fe7343b72260e58.png)
Reference article :
meo4j 4.4 Official documents Graph database concepts
Neo4j Figure Chinese document of database —neo4j 0.1.0a documentation
be based on Neo4j Build a movie map - You know (zhihu.com)
neo4j Figure database node name 、 Tag name 、 Property name - Simple books (jianshu.com)
neo4j Export high definition pictures and adjust Fonts - You know (zhihu.com)
边栏推荐
- EPICS记录参考5 -- 数组模拟输入记录Array Analog Input (aai)
- Zener diode zener diode sod123 package positive and negative distinction
- 流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)
- 关于元器件封装的一些文章和一下我的体会
- Microservice system design -- message caching service design
- What is BFC? What's the usage?
- 第1章 绪论
- Halon common affine transformation operators
- 日志收集系統
- Edge loads web pages in IE mode - edge sets ie compatibility
猜你喜欢

2022-06-26: what does the following golang code output? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { type

Almost because of json Stringify lost his bonus

【C语言】关键字的补充

Microservice system design -- distributed cache service design

渗透测试-目录遍历漏洞

Web3还没实现,Web5乍然惊现!

流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)

重映像(STM32)
![[station B up dr_can learning notes] Kalman filter 1](/img/18/ee21d31f6a118e4e4ad466b55361cc.gif)
[station B up dr_can learning notes] Kalman filter 1

pycharm 如何安装 package
随机推荐
Microservice system design -- message caching service design
2022-06-26:以下golang代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { type
Quick sort (non recursive) and merge sort
020 C语言基础:C语言强制类型转换与错误处理
STM32关闭PWM输出时,让IO输出固定高或低电平的方法。
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
Cognition - how to fill in 2022 college entrance examination volunteers
Acwing's 57th weekly match -- BC question is very good
Qchart note 2: add rollover display
007 basics of C language: C operator
pycharm 如何安装 package
Terminal in pychar cannot enter the venv environment
neo4j图数据库基本概念
[unity] button of UI interactive component & summary of optional base classes
体验 win10 下 oceanbase 数据库
008 C语言基础:C判断
Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
Pytest框架的执行规则
015 basics of C language: C structure and common body
014 C语言基础:C字符串