Recently, I tried several graph databases and visualization tools on large-scale graphs such as Neo4j, Graph-Tool etc..
In the blog, I will introduce some basic knowledge of them. At the same time, I record some issues and the corresponding solutions.
Neo4j
1. Install Neo4j on Ubuntu
1
2
# list the databases
show databses
2. Usage
Since I am using the community version, there are some actions such as creating a new database that are not able to take easily.
2.1 How to create/delete a new database:
- Create: link.
- Delete: link.
- Neo4j Server Config file:
/etc/neo4j/neo4j.conf
. - Neo4j database path:
/var/lib/neo4j/
1
2
3
4
5
6
7
# Step 1: Stop the server
# Step 2:
cd /var/lib/neo4j/
# Step 3:
# rm -rf data/databases/lanl/* data/transactions/lanl/*
rm -rf data/databases/<database name> data/transactions/<database name>
# Step 4: Restart the server
2.2 How to count the nodes and edges number in the whole database
- Solution: link
1
2
3
4
5
6
7
# count node number
MATCH (n)
RETURN count(n) as count
# count edge number
MATCH ()-[r]->()
RETURN count(r) as count
2.3 Install APOC for Neo4j
2.4 Merge repulicated nodes
1
2
3
4
5
MATCH (n1:Node),(n2:Node)
WHERE n1.name = n2.name and id(n1) < id(n2)
WITH [n1,n2] as ns
CALL apoc.refactor.mergeNodes(ns) YIELD node
RETURN node
2.5 Insert the nodes or edges if not existing
1
2
3
MERGE (a:Node {name:1146})
MERGE (b:Node {name: 2464})
MERGE (a)-[r: Timestamp]->(b)
2.6 Show all the nodes and edges in one graph
1
2
Match (n)-[r]->(m)
Return n,r,m
2.7 Display more nodes and edges
:config initialNodeDisplay: 1000
Issues:
- When we try to login on Neo4j client, we receive the issue
ServiceUnavailable: WebSocket connection failure. Due to security constraints in your web browser, the reason for the failure is not available to this Neo4j Driver. Please use your browsers development console to determine the root cause of the failure. Common reasons include the database being unavailable, using the wrong connection URL or temporary network problems. If you have enabled encryption, ensure your browser is configured to trust the certificate Neo4j is configured to use. WebSocket readyState is: 3
:- The solution is to connect to
localhost:7687/
. And then we can login onlocalhost:7474/browser/
smoothly.
- The solution is to connect to
- Trouble shooting link. 3.
Graph-Tool
Graph-tool is a python package that can analyses the graphs and visualize large-scale graphs.
It runs faster than Networkx because the core data structure and algorithms are implement in C++ instead of pure python.
There are several ways to install it. But most of them are annoying by installing extra C++ packages. The easiest way is to install it by conda following the link.
There are some quick tutorials and examples in the link.