当前位置:网站首页>Py2neo basic syntax

Py2neo basic syntax

2022-06-27 05:06:00 Thought is tightening

1. Import library

import py2neo
from py2neo import Graph,Node,Relationship,NodeMatcher

2. Connect neo4j

graph_ = Graph("http://localhost:7474", auth=("username", "password"))
# g = Graph('http://username:[email protected]:7474')  Sure 
#  Here's how to write it ,py2neo-2021.2.3 I won't support it .
# graph = Graph('http://127.0.0.1:7474', username="your_username", password="your_password")

3. Create nodes 、 Relationship

Method 1 : Import txt or csv Document to neo4j

Reference resources : Knowledge map actual battle : Build a knowledge map of a dream of Red Mansions _ Ren Caixue programming blog -CSDN Blog

  1. stay jupyter Created in the txt Files can be imported directly

  2. If it is csv file , It is recommended to open it with Notepad , Save as bom-utf-8 Format csv file

Method 2 : Use py2neo Chinese grammar

Reference resources :py2neo——Neo4j&python In combination with - Simple books (jianshu.com)

4. perform cypher command

It is recommended to delete all existing nodes before creating them , Avoid query confusion

#  Delete all nodes and relationships in the database 
graph_.run('MATCH (n) detach delete n')

#  View all nodes and relationships in the database 
MATCH (n) RETURN n
原网站

版权声明
本文为[Thought is tightening]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270435105214.html