Last active
May 22, 2024 03:30
-
-
Save korakot/328aaac51d78e589b4a176228e4bb06f to your computer and use it in GitHub Desktop.
Using Neo4j in Colab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download 3.5.8 or neo4j-enterprise-4.0.0-alpha09mr02-unix | |
!curl https://neo4j.com/artifact.php?name=neo4j-community-3.5.8-unix.tar.gz -o neo4j.tar.gz | |
# decompress and rename | |
!tar -xf neo4j.tar.gz # or --strip-components=1 | |
!mv neo4j-community-3.5.8 nj | |
# disable password, and start server | |
!sed -i '/#dbms.security.auth_enabled/s/^#//g' nj/conf/neo4j.conf | |
!nj/bin/neo4j start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install py2neo -q | |
from py2neo import Graph | |
graph = Graph("bolt://localhost:7687") | |
from IPython.core.magic import register_cell_magic | |
@register_cell_magic | |
def nj(line, cell=None): | |
return graph.run(cell or line).to_table() | |
%%nj | |
MATCH (n) RETURN n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install py2neo -q | |
from py2neo.data import Node, Relationship | |
a = Node("Person", name="Alice") | |
b = Node("Person", name="Bob") | |
ab = Relationship(a, "KNOWS", b) | |
ab #(Alice)-[:KNOWS]->(Bob) | |
# now still floating, need to add to Graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download and config | |
!wget -P nj/plugins https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar | |
!sed -i '/dbms.security.procedures.unrestricted/s/^#//g' nj/conf/neo4j.conf | |
!sed -i 's/my.extensions.example,my.procedures/apoc/' nj/conf/neo4j.conf | |
!nj/bin/neo4j restart | |
%%cypher | |
RETURN apoc.version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install -q ipython-cypher | |
import cypher # for cypher.run | |
%load_ext cypher | |
%config CypherMagic.feedback=False | |
%cypher MATCH (a)-[]-(b) RETURN a, b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is that the URL is screwed up, use this code and it will work