Neo4j is an open source database that can be used to mine and display entity relationships, and display the relationships between entities in the form of a knowledge graph.
1. Java environment deployment and configuration
First of all, Neo4j depends on the Java environment to run, so you need to complete the Java environment deployment and configuration first.
Download the corresponding version of the exe installation package from the official website of Java Windows, and install it normally, without changing the installation directory.
Configure environment variables:
New JAVA_HOME variable Variable name:
JAVA_HOME Variable value: C:\Program Files\Java\jdk1.8.0_191\
Edit the Path variable and add
%JAVA_HOME%\bin;
Insert at the top, with higher priority to reduce conflicts
Check if the configuration is successful
Open the command prompt and enter where java to check the java installation directory. If it is the installation directory just now, the installation is correct.
If the display is another version of java, just delete java.exe, javaw.exe, javaws.exe in the corresponding directory displayed.
Two, Neo4j installation and deployment
Official website download address:
Download the community version:
Since the version installed by JAVA here is version 8, the downloaded version is 3.5.26.
If it is Neo4j version 4 or higher, the JAVA version needs to be 11 or higher, otherwise an error of JAVA Version is not supported will be reported.
Here copy the downloaded and decompressed files to the C:\neo4j folder:
Configure environment variables:
cmd console to run neo4j:
<NEO4J_HOME>\bin\neo4j console cmdInstall neo4j service:
<NEO4J_HOME>\bin\neo4j install-service
Three, test data
The test data comes from the Internet and was searched on github.
Download it and place it under the import folder:
http://localhost:7474/ Log in to the Neo4j system.
Test loading data (I haven't studied the syntax carefully here, I found the ready-made loading code):
LOAD CSV WITH HEADERS FROM 'file:///ylq_star_nodes.csv' AS data CREATE (:star{
starname:data.name, starid:data.id});
LOAD CSV WITH HEADERS FROM "file:///ylq_star_relations.csv" AS relations
MATCH (entity1:star{
starname:relations.subject}) , (entity2:star{
starname:relations.object})
CREATE (entity1)-[:rel{
relation: relations.relation}]->(entity2)
Inquire:
# 查某人全部关系
return (:star{
starname:"张国荣"})-->();
If the relationship cannot be displayed normally, you can check the csv encoding method and change it to UTF-8.
Quickly clear the data in the database
MATCH p = ()-[r]->() delete p //删除关系
MATCH (n) delete n //删除节点