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

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

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

Graph.io介绍

[英]Construct a particular Io implementation for reading and writing the Graph and other data. End-users will "select" the Io implementation that they want to use by supplying the org.apache.tinkerpop.gremlin.structure.io.Io.Builder that constructs it. In this way, Graphvendors can supply their IoRegistry to that builder thus allowing for custom serializers to be auto-configured into the Io instance. Registering custom serializers is particularly useful for those graphs that have complex types for Element identifiers.

For those graphs that do not need to register any custom serializers, the default implementation should suffice. If the default is overridden, take care to register the current graph via the org.apache.tinkerpop.gremlin.structure.io.Io.Builder#graph(Graph) method.
[中]构造一个特定的Io实现,用于读写图形和其他数据。最终用户将通过提供组织来“选择”他们想要使用的Io实现。阿帕奇。小炉匠。小精灵。结构木卫一。木卫一。构建它的生成器。通过这种方式,GraphVendor可以将其IoRegistry提供给该构建器,从而允许将自定义序列化程序自动配置到Io实例中。注册自定义序列化程序对于元素标识符具有复杂类型的图特别有用。
对于那些不需要注册任何自定义序列化程序的图,默认实现应该足够了。如果覆盖默认值,请注意通过组织注册当前图形。阿帕奇。小炉匠。小精灵。结构木卫一。木卫一。生成器#图(graph)方法。

代码示例

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

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
  final GraphSONMapper v1mapper = GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistryV1d0.getInstance()).create();
  final GraphSONMapper v2mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create();
  final GraphSONMapper v3mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create();
  return Arrays.asList(new Object[][]{
    {"graphson-v1-embedded",
      (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v1mapper).create(),
      (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v1mapper).create()},
    {"graphson-v2-embedded",
      (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v2mapper).create(),
      (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v2mapper).create()},
    {"graphson-v3",
      (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v3mapper).create(),
      (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v3mapper).create()},
    {"gryo",
      (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().create()).create(),
      (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().create()).create()}
  });
}

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

private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
      graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph);
      return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size());
    } catch (IOException ioe) {
      throw new RuntimeException(ioe);
    }
  }
}

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

private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  try {
    graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph);
    return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size());
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
}

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

/**
 * Use Gryo to pipe the data from one graph to another graph.  Uses readers and writers generated from each
 * {@link Graph} via the {@link Graph#io(Io.Builder)} method.
 */
public static void migrateGraph(final Graph fromGraph, final Graph toGraph) throws IOException {
  migrateGraph(fromGraph, toGraph, fromGraph.io(gryo()).reader().create(), toGraph.io(gryo()).writer().create());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeVertexPropertyWithProperties() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
  final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next();
  final String json = mapper.writeValueAsString(vp);
  final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
  assertEquals(vp.label(), m.get(GraphSONTokens.LABEL));
  assertNotNull(m.get(GraphSONTokens.ID));
  assertEquals(vp.value(), m.get(GraphSONTokens.VALUE));
  assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime"));
  assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime"));
}

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

public Serializer serializer(Graph g) {
  // TODO: cache Serializer
  return new JsonSerializer(g.io(IoCore.graphson()).writer()
                .wrapAdjacencyList(true).create());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
  final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
  final String json = mapper.writeValueAsString(e);
  final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
  assertEquals(GraphSONTokens.EDGE, m.get(GraphSONTokens.TYPE));
  assertEquals(e.label(), m.get(GraphSONTokens.LABEL));
  assertNotNull(m.get(GraphSONTokens.ID));
  assertEquals((Double) e.value("weight"), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("weight"));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
  final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
  final String json = mapper.writeValueAsString(vp);
  final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
  assertEquals(vp.label(), m.get(GraphSONTokens.LABEL));
  assertNotNull(m.get(GraphSONTokens.ID));
  assertEquals(vp.value(), m.get(GraphSONTokens.VALUE));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
@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 shouldMigrateClassicGraph() throws Exception {
  final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CLASSIC);
  graphProvider.clear(configuration);
  final Graph g1 = graphProvider.openTestGraph(configuration);
  final GraphReader reader = graph.io(ioBuilderToTest).reader().create();
  final GraphWriter writer = graph.io(ioBuilderToTest).writer().create();
  GraphMigrator.migrateGraph(graph, g1, reader, writer);
  IoTest.assertClassicGraph(g1, assertDouble, lossyForId);
  graphProvider.clear(g1, configuration);
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@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 shouldMigrateModernGraph() throws Exception {
  final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
  graphProvider.clear(configuration);
  final Graph g1 = graphProvider.openTestGraph(configuration);
  final GraphReader reader = graph.io(ioBuilderToTest).reader().create();
  final GraphWriter writer = graph.io(ioBuilderToTest).writer().create();
  GraphMigrator.migrateGraph(graph, g1, reader, writer);
  IoTest.assertModernGraph(g1, true, lossyForId);
  graphProvider.clear(g1, configuration);
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
  final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
  final String json = mapper.writeValueAsString(p);
  final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
  assertEquals(p.value(), m.get(GraphSONTokens.VALUE));
  assertEquals(p.key(), m.get(GraphSONTokens.KEY));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializePropertyAsDetached() throws Exception {
  final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0));
  final GryoWriter gryoWriter = gryoIo.writer().create();
  final GryoReader gryoReader = gryoIo.reader().create();
  final Property property = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  gryoWriter.writeObject(outputStream, property);
  final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
  final Property detached = gryoReader.readObject(inputStream, DetachedProperty.class);
  assertNotNull(detached);
  assertEquals(property.key(), detached.key());
  assertEquals(property.value(), detached.value());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
  final Vertex v = graph.vertices(convertToVertexId("marko")).next();
  final String json = mapper.writeValueAsString(v);
  final Vertex detached = mapper.readValue(json, Vertex.class);
  assertNotNull(detached);
  assertEquals(v.label(), detached.label());
  assertEquals(v.id(), detached.id());
  assertEquals(v.value("name").toString(), detached.value("name"));
  assertEquals((Integer) v.value("age"), detached.value("age"));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
  final Vertex v = graph.vertices(convertToVertexId("marko")).next();
  final String json = mapper.writeValueAsString(v);
  final Vertex detached = mapper.readValue(json, Vertex.class);
  assertNotNull(detached);
  assertEquals(v.label(), detached.label());
  assertEquals(v.id(), detached.id());
  assertEquals(v.value("name").toString(), detached.value("name"));
  assertEquals((Integer) v.value("age"), detached.value("age"));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
  final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
  final String json = mapper.writeValueAsString(vp);
  final VertexProperty detached = mapper.readValue(json, VertexProperty.class);
  assertNotNull(detached);
  assertEquals(vp.label(), detached.label());
  assertEquals(vp.id(), detached.id());
  assertEquals(vp.value(), detached.value());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
  final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
  final String json = mapper.writeValueAsString(vp);
  final VertexProperty detached = mapper.readValue(json, VertexProperty.class);
  assertNotNull(detached);
  assertEquals(vp.label(), detached.label());
  assertEquals(vp.id(), detached.id());
  assertEquals(vp.value(), detached.value());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
  final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
  final String json = mapper.writeValueAsString(p);
  final Property detached = mapper.readValue(json, Property.class);
  assertNotNull(detached);
  assertEquals(p.key(), detached.key());
  assertEquals(p.value(), detached.value());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
  final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
  final String json = mapper.writeValueAsString(p);
  final Property detached = mapper.readValue(json, Property.class);
  assertNotNull(detached);
  assertEquals(p.key(), detached.key());
  assertEquals(p.value(), detached.value());
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
  final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
  final String json = mapper.writeValueAsString(e);
  final Edge detached = mapper.readValue(json, Edge.class);
  assertNotNull(detached);
  assertEquals(e.label(), detached.label());
  assertEquals(e.id(), detached.id());
  assertEquals((Double) e.value("weight"), detached.value("weight"));
}

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

@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
  final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
  final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
  final String json = mapper.writeValueAsString(e);
  final Edge detached = mapper.readValue(json, Edge.class);
  assertNotNull(detached);
  assertEquals(e.label(), detached.label());
  assertEquals(e.id(), detached.id());
  assertEquals((Double) e.value("weight"), detached.value("weight"));
}

相关文章