我正在与NEO4J和Java合作,为一个应用程序创建一个原型,该应用程序集成了一个图形数据库,该数据库存储了患者信息(带有伪造的,伪造的数据)。
我创建了一个简单的两类程序,并创建了节点(尚未分配关系)。但是,我希望能够查看自己创建的节点,以确保我的应用程序正常运行,并能够在NEO4J浏览器/社区服务器中查看结果。
如何使节点外观可见?我知道我可以通过查询它们来测试是否创建了它们,但是我也想知道如何以可视方式显示它们。
我试图做的是进入Neo4j.conf文件,并将活动数据库从默认的“ graph.db” 更改为“ Users / andrew / eclipse-工作区/患者数据库/目标/患者数据库” ,因为在我创建的Java类中,我使用以下代码行设置数据库:
private static final File Patient_DB = new File("target/patient-db");
但是,每当我在localhost:7474处打开NEO4J浏览器时,运行代码后就看不到任何节点。
下面,我将代码粘贴到我的PatientGraph类(另一个类只是创建Patient及其属性的Patient类)
package com.andrewhe.neo4j.Patients_Database;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.io.fs.FileUtils;
public class PatientGraph {
private static final File Patient_DB = new File("target/patient-db");
private ArrayList<Patient> patients = new ArrayList<Patient>();
private long patientZero;
private GraphDatabaseService graphDb;
public ArrayList<Patient> getPatients() { return patients; }
public void manualPatientSetUp() throws IOException {
Patient homeNode = new Patient("");
Patient jan = new Patient("Jan");
patients.add(jan);
Patient kim = new Patient("Kim");
patients.add(kim);
Patient ahmad = new Patient("Ahmad");
patients.add(ahmad);
Patient andrew = new Patient("Andrew");
patients.add(andrew);
}
public void createPatientNodes() throws IOException {
FileUtils.deleteRecursively(Patient_DB);
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(Patient_DB);
registerShutdownHook();
try (Transaction tx = graphDb.beginTx()) {
for (Patient patient : patients) {
Node patientNode = graphDb.createNode();
System.out.println("Node created");
setProperties(patientNode, patient);
}
tx.success();
}
}
//Method to create and set properties for node instead of using 5 set properties each time.
public void setProperties(Node node, Patient patient) {
node.setProperty("name", patient.getName());
node.setProperty("weight", patient.getWeight());
node.setProperty("pat_id", new String(patient.getPatientID()));
node.setProperty("age", patient.getAge());
//Don't worry about diagnoses yet;
//To get it to work, just turn the diagnoses ArrayList into a String separated by commas.
}
public void setUp() throws IOException {
//reads in patients using a file
}
public void shutdown()
{
graphDb.shutdown();
}
private void registerShutdownHook()
{
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running example before it's completed)
Runtime.getRuntime().addShutdownHook(new Thread(() -> graphDb.shutdown()));
}
public static void main(String[] args) throws IOException {
PatientGraph pg = new PatientGraph();
pg.manualPatientSetUp();
pg.createPatientNodes();
for (int i = 0; i < pg.getPatients().size(); i++) {
pg.getPatients().get(i).printAllData();
}
pg.shutdown();
}
}
答案 0 :(得分:0)
您没有提供有关如何查询节点的足够信息。在实际粘贴整个课程内容之前,您甚至没有详细介绍自己的课程。这些类之间有什么关系?期望有人从代码中为您解码此请求,这要求太多。
您可以使用Neo4J Browser(内置)或Neo4J Bloom(商业工具)来可视化图形节点及其互连(关系)。
要查询Neo4j数据库,可以使用Cypher(一种图形图形查询语言),将图案表示为Ascii Art。
下面的文章中给出了用于查询和可视化图节点的详细动手过程。
https://medium.com/neo4j/hands-on-graph-data-visualization-bd1f055a492d