简体   繁体   English

如何查看从Neo4J Java应用程序创建的节点的可视图形表示?

[英]How can I view the visual graph representation of the nodes created from a Neo4J Java Application?

I'm working with NEO4J and Java to create a prototype for an application that integrates a graph database that holds patient information (with fake, made up data). 我正在使用NEO4J和Java为应用程序创建一个原型,该应用程序集成了一个图形数据库,用于保存患者信息(包含伪造的数据)。

I've created a simple two class program, and created nodes (haven't assigned relationships yet). 我创建了一个简单的两类程序,并创建了节点(尚未分配关系)。 However, I want to be able to view the nodes that I've created in order to make sure that my application is working properly, and to be able to see the results in the NEO4J Browser / Community Server. 但是,我希望能够查看我创建的节点,以确保我的应用程序正常工作,并能够在NEO4J浏览器/社区服务器中查看结果。

How can I get the nodes to appear visually? 如何让节点以可视方式显示? I know I could test the fact that they're being created by querying them, but I also want to know how to visually display them. 我知道我可以测试它们是通过查询它们来创建它的事实,但我也想知道如何在视觉上显示它们。

What I've tried to do is go into the Neo4j.conf file, and change the active database from the default "graph.db" to "Users/andrew/eclipse-workspace/patients-database/target/patient-db" , since in the Java class I've created, I use this line of code to set my database: 我试图做的是进入Neo4j.conf文件,并将活动数据库从默认的“graph.db”更改为“Users / andrew / eclipse-workspace / patients-database / target / patient-db” ,因为在我创建的Java类中,我使用这行代码来设置我的数据库:

private static final File Patient_DB = new File("target/patient-db");

However, whenever I open the NEO4J browser at localhost:7474, after running my code there are no nodes visible. 但是,每当我在localhost:7474打开NEO4J浏览器时,运行我的代码后都没有可见的节点。

Below, I'll paste the code to my PatientGraph class (the other class is just a Patient class that creates the Patients and their attributes) 下面,我将代码粘贴到我的PatientGraph类(另一个类只是一个创建患者及其属性的患者类)

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();
    }
}

You did not provide sufficient information about how you are querying the nodes. 您没有提供有关如何查询节点的足够信息。 You did not even elaborate as to what you are classes do in a brief detail before actually pasting the entire class contents. 在实际粘贴整个课程内容之前,您甚至没有详细说明课程中的内容。 What is the relationship between these classes? 这些课程之间有什么关系? Expecting someone to decode this for you from the code, is asking for too much. 期待有人从代码中为你解码这个问题太多了。

You could use Neo4J Browser (comes built-in) or Neo4J Bloom (commercial tool) to visualize the graph nodes and their interconnections (relations). 您可以使用Neo4J Browser(内置)或Neo4J Bloom(商业工具)来可视化图形节点及其互连(关系)。

To query a Neo4j database you can use Cypher, a pictorial graph query language, that represents patterns as Ascii Art. 要查询Neo4j数据库,您可以使用图形图查询语言Cypher,它将模式表示为Ascii Art。

A detailed Hands-On procedure for querying and visualizing the Graph Nodes is given in the article below. 下面的文章给出了详细的查询和可视化图形节点的动手程序。

https://medium.com/neo4j/hands-on-graph-data-visualization-bd1f055a492d https://medium.com/neo4j/hands-on-graph-data-visualization-bd1f055a492d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM