コード例 #1
0
ファイル: BlockType.java プロジェクト: radekzak/neo4j
 @Override
 String process(Block block, State state) {
   String first = block.lines.get(0);
   String id = "";
   if (first.length() > 8) {
     id = first.substring(first.indexOf("graph") + 5).trim();
     if (id.indexOf(':') != -1) {
       id = first.substring(first.indexOf(':') + 1).trim();
     }
   }
   GraphvizWriter writer =
       new GraphvizWriter(AsciiDocSimpleStyle.withAutomaticRelationshipTypeColors());
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try (Transaction tx = state.database.beginTx()) {
     writer.emit(out, Walker.fullGraph(state.database));
     tx.success();
   } catch (IOException e) {
     e.printStackTrace();
   }
   StringBuilder output = new StringBuilder(512);
   try {
     String dot = out.toString("UTF-8");
     output
         .append("[\"dot\", \"cypherdoc-")
         .append(id)
         .append('-')
         .append(Integer.toHexString(dot.hashCode()))
         .append(".svg\", \"neoviz\"]\n----\n")
         .append(dot)
         .append("----\n");
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   return output.toString();
 }
コード例 #2
0
  @Test
  public void test() throws Exception {
    OwlLoadConfiguration config = new OwlLoadConfiguration();
    Neo4jConfiguration neo4jConfig = new Neo4jConfiguration();
    neo4jConfig.setLocation(folder.getRoot().getAbsolutePath());
    config.setGraphConfiguration(neo4jConfig);
    OntologySetup ontSetup = new OntologySetup();
    ontSetup.setUrl("http://127.0.0.1:10000/main.owl");
    config.getOntologies().add(ontSetup);
    BatchOwlLoader.load(config);

    GraphDatabaseService graphDb =
        new GraphDatabaseFactory().newEmbeddedDatabase(folder.getRoot().toString());
    graphDb.beginTx();
    GraphvizWriter writer = new GraphvizWriter();
    Walker walker = Walker.fullGraph(graphDb);
    writer.emit(new File("/tmp/test.dot"), walker);
  }
コード例 #3
0
 @Test
 public void testSimpleGraph() throws Exception {
   GraphDatabaseService neo = dbRule.getGraphDatabaseService();
   Transaction tx = neo.beginTx();
   try {
     final Node emil = neo.createNode();
     emil.setProperty("name", "Emil Eifrém");
     emil.setProperty("age", 30);
     final Node tobias = neo.createNode();
     tobias.setProperty("name", "Tobias \"thobe\" Ivarsson");
     tobias.setProperty("age", 23);
     tobias.setProperty("hours", new int[] {10, 10, 4, 4, 0});
     final Node johan = neo.createNode();
     johan.setProperty("!<>)", "!<>)");
     johan.setProperty("name", "!<>Johan '\\n00b' !<>Svensson");
     final Relationship emilKNOWStobias = emil.createRelationshipTo(tobias, type.KNOWS);
     emilKNOWStobias.setProperty("since", "2003-08-17");
     final Relationship johanKNOWSemil = johan.createRelationshipTo(emil, type.KNOWS);
     final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(johan, type.KNOWS);
     final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo(emil, type.WORKS_FOR);
     OutputStream out = new ByteArrayOutputStream();
     GraphvizWriter writer = new GraphvizWriter();
     writer.emit(
         out,
         Walker.crosscut(
             emil.traverse(
                 Order.DEPTH_FIRST,
                 StopEvaluator.END_OF_GRAPH,
                 ReturnableEvaluator.ALL,
                 type.KNOWS,
                 Direction.BOTH,
                 type.WORKS_FOR,
                 Direction.BOTH),
             type.KNOWS,
             type.WORKS_FOR));
     tx.success();
     out.toString();
   } finally {
     tx.finish();
   }
 }
コード例 #4
0
ファイル: OwlTestCase.java プロジェクト: jmcmurry/SciGraph
 void drawGraph() throws IOException {
   GraphvizWriter writer = new GraphvizWriter();
   Walker walker = Walker.fullGraph(graphDb);
   new File("target/owl_cases").mkdirs();
   writer.emit(new File("target/owl_cases/" + getTestName() + ".dot"), walker);
 }