org.apache.tinkerpop.gremlin.structure.Graph.edges()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.edges()方法的一些代码示例,展示了Graph.edges()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.edges()方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:edges

Graph.edges介绍

[英]Get the Edge objects in this graph with the provided edge ids or Edge objects. If no ids are provided, get all edges. Note that an edge identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the Graph.Features around id support, multiple arguments might be applicable here.

If the graph return true for Features.EdgeFeatures#supportsNumericIds() then it should support filters as with:

  • g.edges(e)
  • g.edges(e.id())
  • g.edges(1)
  • g.edges(1L)
  • g.edges(1.0d)
  • g.edges(1.0f)
  • g.edges("1")

If the graph return true for Features.EdgeFeatures#supportsCustomIds() ()} then it should support filters as with:

  • g.edges(e)
  • g.edges(e.id())
  • g.edges(e.id().toString())

If the graph return true for Features.EdgeFeatures#supportsAnyIds() ()} then it should support filters as with:

  • g.edges(e)
  • g.edges(e.id())

If the graph return true for Features.EdgeFeatures#supportsStringIds() ()} then it should support filters as with:

  • g.edges(e)
  • g.edges(e.id().toString())
  • g.edges("id")
    [中]使用提供的边ID或边对象获取此图中的边对象。如果没有提供ID,则获取所有边。请注意,边标识符不需要与图形中使用的实际id相对应。它需要比给定图形中的灵活一点。围绕id支持的功能,这里可能适用多个参数。
    如果特征的图形返回true。EdgeFeatures#supportsNumericIds()则它应支持以下过滤器:
    *g.边缘(e)
    *g.边缘(例如id())
    *g.边缘(1)
    *g.边缘(1L)
    *g.边缘(1.0d)
    *g.边缘(1.0f)
    *g.边缘(“1”)
    如果特征的图形返回true。EdgeFeatures#supportsCustomIds()()}那么它应该支持过滤器,如下所示:
    *g.边缘(e)
    *g.边缘(例如id())
    *g.边缘(例如id()。toString())
    如果特征的图形返回true。EdgeFeatures#supportsAnyIds()()}那么它应该支持过滤器,如下所示:
    *g.边缘(e)
    *g.边缘(例如id())
    如果特征的图形返回true。EdgeFeatures#supportsStringIds()()}那么它应该支持过滤器,如下所示:
    *g.边缘(e)
    *g.边缘(例如id()。toString())
    *g.边缘(“id”)

代码示例

代码示例来源:origin: thinkaurelius/titan

originalGraphStep.getTraversal().getGraph().get().edges(elementIds)));

代码示例来源:origin: JanusGraph/janusgraph

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
  if (TraversalHelper.onGraphComputer(traversal))
    return;
  TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(originalGraphStep -> {
    if (originalGraphStep.getIds() == null || originalGraphStep.getIds().length == 0) {
      //Try to optimize for index calls
      final JanusGraphStep<?, ?> janusGraphStep = new JanusGraphStep<>(originalGraphStep);
      TraversalHelper.replaceStep(originalGraphStep, janusGraphStep, traversal);
      HasStepFolder.foldInIds(janusGraphStep, traversal);
      HasStepFolder.foldInHasContainer(janusGraphStep, traversal, traversal);
      HasStepFolder.foldInOrder(janusGraphStep, janusGraphStep.getNextStep(), traversal, traversal, janusGraphStep.returnsVertex(), null);
      HasStepFolder.foldInRange(janusGraphStep, JanusGraphTraversalUtil.getNextNonIdentityStep(janusGraphStep), traversal, null);
    } else {
      //Make sure that any provided "start" elements are instantiated in the current transaction
      final Object[] ids = originalGraphStep.getIds();
      ElementUtils.verifyArgsMustBeEitherIdOrElement(ids);
      if (ids[0] instanceof Element) {
        //GraphStep constructor ensures that the entire array is elements
        final Object[] elementIds = new Object[ids.length];
        for (int i = 0; i < ids.length; i++) {
          elementIds[i] = ((Element) ids[i]).id();
        }
        originalGraphStep.setIteratorSupplier(() -> originalGraphStep.returnsVertex() ?
            ((Graph) originalGraphStep.getTraversal().getGraph().get()).vertices(elementIds) :
            ((Graph) originalGraphStep.getTraversal().getGraph().get()).edges(elementIds));
      }
    }
  });
}

代码示例来源:origin: apache/tinkerpop

public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
  final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id());
  return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty();
}

代码示例来源:origin: apache/tinkerpop

private static Map<String, String> determineEdgeTypes(final Graph graph) {
  final Map<String, String> edgeKeyTypes = new HashMap<>();
  final Iterator<Edge> edges = graph.edges();
  while (edges.hasNext()) {
    final Edge edge = edges.next();
    for (String key : edge.keys()) {
      if (!edgeKeyTypes.containsKey(key))
        edgeKeyTypes.put(key, GraphMLWriter.getStringType(edge.property(key).value()));
      }
    }
  return edgeKeyTypes;
}

代码示例来源:origin: apache/tinkerpop

public GraphStep(final Traversal.Admin traversal, final Class<E> returnClass, final boolean isStart, final Object... ids) {
  super(traversal);
  this.returnClass = returnClass;
  this.ids = (ids.length == 1 && ids[0] instanceof Collection) ? ((Collection) ids[0]).toArray(new Object[((Collection) ids[0]).size()]) : ids;
  this.isStart = isStart;
  this.iteratorSupplier = () -> (Iterator<E>) (Vertex.class.isAssignableFrom(this.returnClass) ?
      this.getTraversal().getGraph().get().vertices(this.ids) :
      this.getTraversal().getGraph().get().edges(this.ids));
}

代码示例来源:origin: apache/tinkerpop

private Iterator<? extends Edge> edges() {
  if (null == this.ids)
    return Collections.emptyIterator();
  return IteratorUtils.filter(this.getTraversal().getGraph().get().edges(this.ids), edge -> HasContainer.testAll(edge, this.hasContainers));
}

代码示例来源:origin: apache/tinkerpop

@Test
public void shouldHaveExceptionConsistencyWhenFindEdgeByIdThatIsNonExistentViaIterator() {
  try {
    graph.edges(graphProvider.convertId(10000l, Edge.class)).next();
    fail("Call to g.edges(10000l) should throw an exception");
  } catch (Exception ex) {
    assertThat(ex, IsInstanceOf.instanceOf(NoSuchElementException.class));
  }
}

代码示例来源:origin: apache/tinkerpop

/**
  * make a deep clone of the graph elements that preserves ids
  */
 public static void cloneElements(final Graph original, final Graph clone) {
  original.vertices().forEachRemaining(v -> DetachedFactory.detach(v, true).attach(Attachable.Method.create(clone)));
  original.edges().forEachRemaining(e -> DetachedFactory.detach(e, true).attach(Attachable.Method.create(clone)));
 }
}

代码示例来源:origin: apache/tinkerpop

private void addEdgeToSubgraph(final Edge edge) {
    final Iterator<Edge> edgeIterator = subgraph.edges(edge.id());
    if (edgeIterator.hasNext()) return;
    final Iterator<Vertex> vertexIterator = edge.vertices(Direction.BOTH);
    final Vertex subGraphOutVertex = getOrCreate(vertexIterator.next());
    final Vertex subGraphInVertex = getOrCreate(vertexIterator.next());
    final Edge subGraphEdge = subGraphOutVertex.addEdge(edge.label(), subGraphInVertex, T.id, edge.id());
    edge.properties().forEachRemaining(property -> subGraphEdge.property(property.key(), property.value()));
  }
}

代码示例来源:origin: apache/tinkerpop

public static Consumer<Graph> getAssertVertexEdgeCounts(final int expectedVertexCount, final int expectedEdgeCount) {
  return (g) -> {
    assertEquals(expectedVertexCount, IteratorUtils.count(g.vertices()));
    assertEquals(expectedEdgeCount, IteratorUtils.count(g.edges()));
  };
}

代码示例来源:origin: apache/tinkerpop

private void distributionGeneratorTest(final Graph graph, final DistributionGenerator generator) {
    final int numEdges = generator.generate();
    assertTrue(numEdges > 0);
    tryCommit(graph, g -> assertEquals(numEdges, IteratorUtils.count(g.edges())));
  }
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingStringRepresentation() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    final Edge e = graph.edges(e1.id().toString()).next();
    assertEquals(e1.id(), e.id());
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_NUMERIC_IDS)
public void shouldAddEdgeWithUserSuppliedNumericId() {
  final Vertex v = graph.addVertex();
  v.addEdge("self", v, T.id, 1000L);
  tryCommit(graph, graph -> {
    final Edge e = graph.edges(1000L).next();
    assertEquals(1000L, e.id());
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_STRING_IDS)
public void shouldAddEdgeWithUserSuppliedStringId() {
  final Vertex v = graph.addVertex();
  v.addEdge("self", v, T.id, "1000");
  tryCommit(graph, graph -> {
    final Edge e = graph.edges("1000").next();
    assertEquals("1000", e.id());
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingStringRepresentations() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  final Edge e2 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.edges(e1.id().toString(), e2.id().toString())));
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdge() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    final Edge e = graph.edges(e1).next();
    assertEquals(e1.id(), e.id());
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdgeId() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    final Edge e = graph.edges(e1.id()).next();
    assertEquals(e1.id(), e.id());
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadGraphMLWithoutEdgeIds() throws IOException {
  final GraphReader reader = GraphMLReader.build().strict(false).create();
  try (final InputStream stream = IoTest.class.getResourceAsStream(TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "graph-no-edge-ids.xml")) {
    reader.readGraph(stream, graph);
  }
  assertEquals(1, IteratorUtils.count(graph.edges()));
  assertEquals(2, IteratorUtils.count(graph.vertices()));
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdges() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  final Edge e2 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.edges(e1, e2)));
  });
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdgeIds() {
  final Vertex v = graph.addVertex();
  final Edge e1 = v.addEdge("self", v);
  final Edge e2 = v.addEdge("self", v);
  v.addEdge("self", v);
  tryCommit(graph, graph -> {
    assertEquals(2, IteratorUtils.count(graph.edges(e1.id(), e2.id())));
  });
}

相关文章