<jupyter_start><jupyter_text>Using py2neo with Neo4J DatabaseThis notebook is designed for run py2neo with neo4j database. In py2neo, there are graph module for connecting and run cypher query, while in data module py2neo has Node and Relationship class for declaring node and make relationship between node. Through this notebook, I will explain how to use py2neo to manipulate neo4j database, lets have fun!!!<jupyter_code># lets prepare our notebook to work with local module and visualization
%matplotlib inline
%reload_ext autoreload
%reload_ext cypher
%autoreload 2
#lets import py2neo module that we will use later
import py2neo
from py2neo import Graph, NodeMatcher
from py2neo.data import Node, Relationship

#local library from directory scripts in this repositories
from scripts.vis import vis_network, draw<jupyter_output><empty_output><jupyter_text>In the code below, I made connection to neo4j database via bolt protocol in port 11004. You can change this port with neo4j desktop apps.<jupyter_code>#making connection to neo4j
graph = Graph("bolt://localhost:11004", user="neo4j", password="<PASSWORD>")<jupyter_output><empty_output><jupyter_text>To make sure all data is empty, I choose to delete all node and its relationship. Be careful, dont RUN this on your own database without knowing what you do.<jupyter_code>#delete all nodes and its realtionships, be carefull
graph.delete_all()
#defining nodes and its relationship
f = Node("Person", name="Fandi")
p = Node("Person", name="Piko")
pf = Relationship(p, "FRIEND", f)
#saving data
tx = graph.begin()
tx.create(f)
tx.create(p)
tx.create(pf)
tx.commit()
options = {"Person":"name"}
draw(graph, options)
#defining nodes and its relationship
e = Node("Person", name="Eby")
d = Node("Person", name="Danil")
ed = Relationship(e, "FRIEND", d, since="2015")
ed
#saving data
tx = graph.begin()
tx.create(e)
tx.create(d)
tx.create(ed)
tx.commit()
options = {"Person":"name"}
draw(graph, options)
f = NodeMatcher(graph)
fandi = f.match("Person", name="Fandi").first()
danil = f.match("Person", name="Danil").first()
eby = f.match("Person", name="Eby").first()

fd = Relationship(fandi, "LECTURE", danil)
fe = Relationship(fandi, "LECTURE", eby)
#saving data
tx = graph.begin()
tx.create(fd)
tx.create(fe)
tx.commit()
options = {"Person":"name"}
draw(graph, options)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11544991511035653, 'fraction_numerical': 0.013157894736842105, 'mean_word_length': 6.365625, 'pattern_counts': {'":': 3, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '86562', 'license': 'MIT', 'n_tokens_mistral': 771, 'n_tokens_neox': 728, 'n_words': 268, 'path': '.ipynb_checkpoints/1.Introduction-checkpoint.ipynb', 'repo_name': 'nunenuh/graph.database', 'size': '2352'}