com.tinkerpop.blueprints.Graph类的使用及代码示例

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

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

Graph介绍

[英]A Graph is a container object for a collection of vertices and a collection edges.
[中]图是顶点集合和边集合的容器对象。

代码示例

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core

/**
   * Copy the vertex/edges of one graph over to another graph.
   * The id of the elements in the from graph are attempted to be used in the to graph.
   * This method only works for graphs where the user can control the element ids.
   *
   * @param from the graph to copy from
   * @param to   the graph to copy to
   */
  public static void copyGraph(final Graph from, final Graph to) {
    for (final Vertex fromVertex : from.getVertices()) {
      final Vertex toVertex = to.addVertex(fromVertex.getId());
      ElementHelper.copyProperties(fromVertex, toVertex);
    }
    for (final Edge fromEdge : from.getEdges()) {
      final Vertex outVertex = to.getVertex(fromEdge.getVertex(Direction.OUT).getId());
      final Vertex inVertex = to.getVertex(fromEdge.getVertex(Direction.IN).getId());
      final Edge toEdge = to.addEdge(fromEdge.getId(), outVertex, inVertex, fromEdge.getLabel());
      ElementHelper.copyProperties(fromEdge, toEdge);
    }
  }
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core

public GraphQuery query() {
  return new WrappedGraphQuery(this.baseGraph.query()) {
    @Override
    public Iterable<Edge> edges() {
      return new WrappedEdgeIterable(this.query.edges());
    }
    @Override
    public Iterable<Vertex> vertices() {
      return new WrappedVertexIterable(this.query.vertices());
    }
  };
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-graph-jung

public boolean containsEdge(final Edge edge) {
  return this.graph.getEdge(edge.getId()) != null;
}

代码示例来源:origin: fr.lirmm.graphik/graal-store-blueprints

private void init() {
  try {
    this.graph.getVertices("class", "");
  } catch (IllegalArgumentException e) {
    Vertex v = this.graph.addVertex(null);
    v.setProperty("class", "");
  }
}

代码示例来源:origin: stackoverflow.com

Graph graph = new SingleGraph("Tutorial 1");
graph.setStrict(false);
graph.setAutoCreate(true); // optionally have it create nodes for you automatically
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
graph.display();

代码示例来源:origin: stackoverflow.com

Graph graph = new Graph();
 graph.getNodeTable().addColumn("duration", double.class);
 Node n1 = graph.addNode();
 n1.setDouble("duration", 20.0);
 Node n2 = graph.addNode();
 Edge e = graph.addEdge(n1, n2);

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

@ExtensionDefinition(extensionPoint = ExtensionPoint.GRAPH, produces = MediaType.APPLICATION_JSON,
    method = HttpMethod.GET, path = EXTENSION_METHOD_COUNT)
@ExtensionDescriptor(description = "get true count of vertices to calculate true split size for faunus")
public ExtensionResponse getVertexCount(@RexsterContext final Graph graph) {
  logger.info("Faunus is configured to get the true count of vertices in the graph.");
  int counter = 0;
  final Iterable<Vertex> vertices = graph.getVertices();
  for (Vertex v : vertices) {
    counter++;
    if (logger.isDebugEnabled() && counter % WRITE_STATUS_EVERY == 0) {
      logger.debug(String.format("True count at: %s", counter));
    }
  }
  final Map<String, Integer> m = new HashMap<String, Integer>();
  m.put(EXTENSION_METHOD_COUNT, counter);
  return ExtensionResponse.ok(m);
}

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

@Override
  public void write(OutputStream out) throws IOException {
    long counter = 0;
    long vertexCount = 0;
    final DataOutputStream dos = new DataOutputStream(out);
    final Iterable<Vertex> vertices = graph.getVertices();
    for (Vertex vertex : vertices) {
      if (counter >= start && counter < end) {
        vertexToFaunusBinary.writeVertex(vertex, dos);
        if (logger.isDebugEnabled() && counter % WRITE_STATUS_EVERY == 0) {
          logger.debug(String.format("Request [%s] at [%s] on the way to [%s].",
              requestIdentifier, vertexCount, verticesInSplit));
        }
        vertexCount++;
      } else if (counter >= end) {
        logger.debug(String.format("Request [%s] completed.", requestIdentifier));
        break;
      }
      counter++;
    }
  }
}).build());

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

@Override
public void cleanup(final Mapper<NullWritable, FaunusVertex, LongWritable, Holder<FaunusVertex>>.Context context) throws IOException, InterruptedException {
  if (this.graph instanceof TransactionalGraph) {
    try {
      ((TransactionalGraph) this.graph).commit();
      context.getCounter(Counters.SUCCESSFUL_TRANSACTIONS).increment(1l);
    } catch (Exception e) {
      LOGGER.error("Could not commit transaction during VertexMap.cleanup():", e);
      ((TransactionalGraph) this.graph).rollback();
      context.getCounter(Counters.FAILED_TRANSACTIONS).increment(1l);
      throw new IOException(e.getMessage(), e);
    }
  }
  this.graph.shutdown();
}

代码示例来源:origin: com.tinkerpop.rexster/rexster-core

@Override
public void stop() {
  // need to shutdown all the graphs that were started with the web server
  for (RexsterApplicationGraph rag : this.graphs.values()) {
    final Graph graph = rag.getGraph();
    logger.info(String.format("Shutting down [%s] - [%s]", rag.getGraphName(), graph));
    // graph may not have been initialized properly if an exception gets tossed in
    // on graph creation
    if (graph != null) {
      // call shutdown on the unwrapped graph as some wrappers don't allow shutdown() to be called.
      final Graph shutdownGraph = rag.getUnwrappedGraph();
      shutdownGraph.shutdown();
    }
  }
}

代码示例来源:origin: iTransformers/netTransformer

if (graph.getFeatures().supportsVertexIndex && graph instanceof KeyIndexableGraph) {
      ((KeyIndexableGraph) graph).createKeyIndex("name", Vertex.class);
    GraphQuery result = graph.query().has(nodeId);
    logger.info(graphmlFile.getAbsolutePath() +" "+ "does not exist");
    return null;
logger.info(versionDir.getAbsolutePath() + " " + "does not exist");

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

Vertex blueprintsVertex = null;
if (null != blueprintsId)
  blueprintsVertex = this.graph.getVertex(blueprintsId);
    final Object otherId = faunusBlueprintsIdMap.get(faunusEdge.getVertex(IN).getId());
    Vertex otherVertex = null;
    if (null != otherId)
      otherVertex = this.graph.getVertex(otherId);
    if (null != otherVertex) {
      this.getOrCreateEdge((FaunusEdge) faunusEdge, blueprintsVertex, otherVertex, context);
    } else {
      LOGGER.warn("No target vertex: faunusVertex[" + faunusEdge.getVertex(IN).getId() + "] blueprintsVertex[" + otherId + "]");
      context.getCounter(Counters.NULL_VERTEX_EDGES_IGNORED).increment(1l);
  LOGGER.warn("No source vertex: faunusVertex[" + NullWritable.get() + "] blueprintsVertex[" + blueprintsId + "]");
  context.getCounter(Counters.NULL_VERTICES_IGNORED).increment(1l);

代码示例来源:origin: org.jboss.windup.legacy.application/grapher

private void writeGraphEdges(OutputStream os) throws IOException {
  for(Edge edge : graph.getEdges()) {
    String label = edge.getLabel();
    String source = ""+edge.getVertex(Direction.IN).getId().hashCode();
    String target = ""+edge.getVertex(Direction.OUT).getId().hashCode();
    writeGraphEdge(label, source, target, os);
  }
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core

Map<String, String> edgeKeyTypes = new HashMap<String, String>();
for (Vertex vertex : graph.getVertices()) {
  for (String key : vertex.getPropertyKeys()) {
    if (!vertexKeyTypes.containsKey(key)) {
      vertexKeyTypes.put(key, GraphMLWriter.getStringType(vertex.getProperty(key)));
if (normalize) {
  vertices = new ArrayList<Vertex>();
  for (Vertex v : graph.getVertices()) {
    ((Collection<Vertex>) vertices).add(v);
  vertices = graph.getVertices();
  for (Vertex vertex : graph.getVertices()) {
    for (Edge edge : vertex.getEdges(Direction.OUT)) {
      edges.add(edge);
    writer.writeAttribute(GraphMLTokens.ID, edge.getId().toString());
    writer.writeAttribute(GraphMLTokens.SOURCE, edge.getVertex(Direction.OUT).getId().toString());
    writer.writeAttribute(GraphMLTokens.TARGET, edge.getVertex(Direction.IN).getId().toString());
  for (Vertex vertex : graph.getVertices()) {
    for (Edge edge : vertex.getEdges(Direction.OUT)) {
      writer.writeStartElement(GraphMLTokens.EDGE);

代码示例来源:origin: iTransformers/netTransformer

private void mergeEdge(Graph graph1, Edge edge2) {
  Edge edge1 = graph1.getEdge(edge2.getId());
  if (edge1 == null) {
    Vertex outVertex1 = graph1.getVertex(edge2.getVertex(Direction.OUT).getId());
    Vertex outVertex2 = graph1.getVertex(edge2.getVertex(Direction.IN).getId());
    edge1 = graph1.addEdge(edge2.getId(), outVertex1, outVertex2, edge2.getLabel());
    for (String key2 : edge2.getPropertyKeys()) {
      edge1.setProperty(key2,edge2.getProperty(key2));
    }
  } else {
    Set<String> keys1 = edge1.getPropertyKeys();
    Set<String> keys2 = edge2.getPropertyKeys();
    for (String key2 : keys2) {
      if (keys1.contains(key2)) {
        MergeConflictResolver conflictResolver = getEdgeConflictResolver(key2);
        Object merge =  conflictResolver.resolveConflict(edge1.getProperty(key2), edge2.getProperty(key2));
        edge1.setProperty(key2, merge);
      } else {
        edge1.setProperty(key2, edge2.getProperty(key2));
      }
    }
  }
}

代码示例来源:origin: SciGraph/SciGraph

for (Vertex vertex : graph.getVertices()) {
 BbopNode bbopNode = new BbopNode();
 bbopNode.setId(getCurieOrIri(vertex));
   getFirst(TinkerGraphUtil.getProperties(vertex, NodeProperties.LABEL, String.class), null);
 bbopNode.setLbl(label);
 for (String key : vertex.getPropertyKeys()) {
  if (IGNORED_PROPERTY_KEYS.contains(key)) {
   continue;
for (Edge edge : graph.getEdges()) {
 BbopEdge bbopEdge = new BbopEdge();
 Vertex subject = edge.getVertex(Direction.OUT);
 Vertex object = edge.getVertex(Direction.IN);
 bbopEdge.setSub(getCurieOrIri(subject));
 bbopEdge.setObj(getCurieOrIri(object));
 bbopEdge.setPred(edge.getLabel());
 for (String key : edge.getPropertyKeys()) {
  if (IGNORED_PROPERTY_KEYS_FOR_EDGES.contains(key)) {

代码示例来源:origin: SciGraph/SciGraph

Edge addEdge(Edge edge) {
 Edge newEdge = graph.getEdge(edge.getId());
 if (null == newEdge) {
  Vertex outVertex = addNode(edge.getVertex(Direction.OUT));
  Vertex inVertex = addNode(edge.getVertex(Direction.IN));
  String label = edge.getLabel();
  newEdge = graph.addEdge(edge.getId(), outVertex, inVertex, label);
  copyProperties(edge, edge);
 }
 return newEdge;
}

代码示例来源:origin: org.jboss.windup.legacy.application/grapher

private void writeGraphNodes(OutputStream os) throws IOException {
  //iterate the nodes.
  for(Vertex vertex : graph.getVertices()) {
    String id = ""+vertex.getId().hashCode();
    String label = vertex.getProperty(vertexLabelProperty);
    
    if(StringUtils.isBlank(label)) {
      label = vertex.toString();
    }
    writeGraphNode(id, label, os);
  }
  
}

代码示例来源:origin: SciGraph/SciGraph

void addCuries(Graph graph) {
 for (Vertex vertex: graph.getVertices()) {
  String iri = (String)vertex.getProperty(CommonProperties.IRI);
  Optional<String> curie = curieUtil.getCurie(iri);
  if (curie.isPresent()) {
   vertex.setProperty(CommonProperties.CURIE, curie.get());
  }
 }
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core

private void populateLists(final List<Vertex> vertices, final List<Edge> edges) {
  for (Vertex v : graph.getVertices()) {
    vertices.add(v);
  }
  for (Edge e : graph.getEdges()) {
    edges.add(e);
  }
}

相关文章