Python
所需的wheel:
pip install neo4j
pip install neo4j-driver
Python
代码如下:
import pickle
import neo4j
from neo4j import GraphDatabase
# 连接neo4j,运行命令
user = 'neo4j'
password = 'root'
driver = GraphDatabase.driver(uri='bolt://localhost:7687', auth=(user, password))
query_str1 ="""CALL semantics.importRDF ("file:///C:/Users/my/Desktop/NLP/end2_harrypotter_end.rdf", "Turtle", {handleVocabUris: "IGNORE"})"""
with driver.session() as session:
records = session.run(query_str)
session.close()
Java
需要的依赖:
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.6.3</version>
</dependency>
Java
代码如下:
import org.neo4j.driver.v1.*;
/**
* 连接 Neo4j,执行命令
* Neo4j的版本3.5.28
*/
public class OperateNeo4j {
public static void main(String[] args) {
String user = "neo4j";
String passwd = "root";
Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic(user, passwd));
Session session = driver.session();
session.run("CALL semantics.importRDF(\"file:///C:/Users/my/Desktop/NLP/end2_harrypotter_end.rdf\", \"Turtle\", {handleVocabUris: \"IGNORE\"})");
session.close();
driver.close();
}
}