This is the seventh day of my participation in the First Challenge 2022

1. Install Neo4j

The following is the official document: neo4j.com/download/ After downloading from the above website, remember the pop-up key, which will be used for subsequent software activation.

Two, basic use method

  1. New project

2. Change the project name

  1. Create a local or remote database

  1. Starting a local database

  1. Use Neo4j Broswer to operate

Node operation

  1. Create a node
Create (: university {name:" Xidian University "})Copy the code
  1. View the constructed node diagram

  1. Adjust the font size of the node display

  1. Get all nodes
match(n) return (n)
Copy the code

The following focuses on how to use Py2neo to operate Neo4j.

  1. Query node
created_node = matcher[node_id]
print(created_node)
Copy the code
  1. Conditional query
matcher.match('Judgment instrument').where(name = 'XXX Criminal Judgment ').first()
Copy the code
  1. Returns a node that matches the condition
temp = selector.match('Person').first()
Copy the code
  1. Adds and modifies node attribute values
temp['name'] = '001'
Copy the code
  1. labeling
temp.add_label('case')
graph.push(temp)
Copy the code
  1. Remove nodes
graph.delete(node)
Copy the code
  1. Create a node
node = Node('people', name = 'Joe')
graph.create(node)
Copy the code

Connect to the database using Py2neo

from py2neo import Graph,Node,Relationship,Subgraph
from py2neo.matching import *


graph = Graph("bolt://localhost:7687", auth=("neo4j"."1234"))
success = graph.run("UNWIND range(1, 3) AS n RETURN n, n * n as n_sq")
if (success):
  print("Connection successful")
Copy the code

conclusion

Py2neo is a python third-party library that operates on Neo4j. It can be queried and used at the same time.

Reference documentation

  • Use Py2neo to add, delete, modify and check Neo4j data: nodes

  • Neo4j-applic Py2neo tutorial with Python

  • Simple Use of Py2neo (1)