コード例 #1
0
ファイル: TraversalDocTest.java プロジェクト: Analect/neo4j
  /**
   * A link:javadocs/org/neo4j/graphdb/traversal/TraversalDescription.html[traversal description] is
   * built using a fluent interface and such a description can then spawn
   * link:javadocs/org/neo4j/graphdb/traversal/Traverser.html[traversers]. @@graph
   *
   * <p>With the definition of the +RelationshipTypes+ as @@sourceRels
   *
   * <p>The graph can be traversed with for example the following traverser, starting at the ``Joe''
   * node: @@knowslikestraverser
   *
   * <p>The traversal will output: @@knowslikesoutput
   *
   * <p>Since
   * link:javadocs/org/neo4j/graphdb/traversal/TraversalDescription.html[+TraversalDescription+]s
   * are immutable it is also useful to create template descriptions which holds common settings
   * shared by different traversals. For example, let's start with this traverser: @@basetraverser
   *
   * <p>This traverser would yield the following output (we will keep starting from the ``Joe''
   * node): @@baseoutput
   *
   * <p>Now let's create a new traverser from it, restricting depth to three: @@depth3
   *
   * <p>This will give us the following result: @@output3
   *
   * <p>Or how about from depth two to four? That's done like this: @@depth4
   *
   * <p>This traversal gives us: @@output4
   *
   * <p>For various useful evaluators, see the
   * link:javadocs/org/neo4j/graphdb/traversal/Evaluators.html[Evaluators] Java API or simply
   * implement the link:javadocs/org/neo4j/graphdb/traversal/Evaluator.html[Evaluator] interface
   * yourself.
   *
   * <p>If you're not interested in the link:javadocs/org/neo4j/graphdb/Path.html[+Path+]s, but the
   * link:javadocs/org/neo4j/graphdb/Node.html[+Node+]s you can transform the traverser into an
   * iterable of link:javadocs/org/neo4j/graphdb/traversal/Traverser.html#nodes()[nodes] like
   * this: @@nodes
   *
   * <p>In this case we use it to retrieve the names: @@nodeoutput
   *
   * <p>link:javadocs/org/neo4j/graphdb/traversal/Traverser.html#relationships()[Relationships] are
   * fine as well, here's how to get them: @@relationships
   *
   * <p>Here the relationship types are written, and we get: @@relationshipoutput
   *
   * <p>TIP: The source code for the traversers in this example is available at: @@github
   */
  @Test
  @Documented
  @Graph({
    "Joe KNOWS Sara",
    "Lisa LIKES Joe",
    "Peter KNOWS Sara",
    "Dirk KNOWS Peter",
    "Lars KNOWS Dirk",
    "Ed KNOWS Lars",
    "Lisa KNOWS Lars"
  })
  public void how_to_use_the_Traversal_framework() {
    Node joe = data.get().get("Joe");
    TraversalExample example = new TraversalExample(db);
    gen.get()
        .addSnippet(
            "graph",
            createGraphVizWithNodeId("Traversal Example Graph", graphdb(), gen.get().getTitle()));

    try (Transaction tx = db.beginTx()) {
      String output = example.knowsLikesTraverser(joe);
      gen.get().addSnippet("knowslikesoutput", createOutputSnippet(output));

      output = example.traverseBaseTraverser(joe);
      gen.get().addSnippet("baseoutput", createOutputSnippet(output));

      output = example.depth3(joe);
      gen.get().addSnippet("output3", createOutputSnippet(output));

      output = example.depth4(joe);
      gen.get().addSnippet("output4", createOutputSnippet(output));

      output = example.nodes(joe);
      gen.get().addSnippet("nodeoutput", createOutputSnippet(output));

      output = example.relationships(joe);
      gen.get().addSnippet("relationshipoutput", createOutputSnippet(output));

      gen.get()
          .addSourceSnippets(
              example.getClass(),
              "knowslikestraverser",
              "sourceRels",
              "basetraverser",
              "depth3",
              "depth4",
              "nodes",
              "relationships");
      gen.get().addGithubSourceLink("github", example.getClass(), "community/embedded-examples");
    }
  }
コード例 #2
0
ファイル: TraversalDocTest.java プロジェクト: Analect/neo4j
 @Test
 public void runAll() throws IOException {
   TraversalExample.main(null);
 }