当前位置: 首页>>代码示例>>Java>>正文


Java Graph.addVertex方法代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.Graph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.addVertex方法的具体用法?Java Graph.addVertex怎么用?Java Graph.addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tinkerpop.gremlin.structure.Graph的用法示例。


在下文中一共展示了Graph.addVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSerializeEdgeProperty

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
    final Graph g = TinkerGraph.open();
    final Vertex v1 = g.addVertex();
    final Vertex v2 = g.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
    final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());

    final JsonNode json = mapper.readTree(results);

    assertNotNull(json);
    assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
    final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);

    assertNotNull(converted);
    assertEquals(1, converted.size());

    final JsonNode propertyAsJson = converted.get(0);
    assertNotNull(propertyAsJson);

    assertEquals(123, propertyAsJson.get("value").asInt());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:GraphSONMessageSerializerV1d0Test.java

示例2: shouldSerializeEdgeProperty

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
    final Graph graph = TinkerGraph.open();
    final Vertex v1 = graph.addVertex();
    final Vertex v2 = graph.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
    final ResponseMessage response = convert(iterable);
    assertCommon(response);

    final List<Map<String, Object>> propertyList = (List<Map<String, Object>>) response.getResult().getData();
    assertEquals(1, propertyList.size());
    assertEquals(123, propertyList.get(0).get("value"));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GraphSONMessageSerializerGremlinV1d0Test.java

示例3: shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
/**
 * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException {
    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Graph sampleGraph1 = TinkerFactory.createModern();
    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID());
    final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID());
    v1.addEdge("hello", v2, T.id, 101L,
            "uuid", UUID.randomUUID());

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, sampleGraph1);
        final String json = out.toString();

        final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class);
        assertTrue(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:23,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例4: shouldLoseTypesWithGraphSONNoTypesForEdgeProps

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
/**
 * Asserts the approximateGraphsChecks function fails when expected. Edge props.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final Graph sampleGraph1 = TinkerFactory.createModern();

    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
    v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
            "uuid", UUID.randomUUID());
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized edge prop.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:22,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例5: generate

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
private static void generate(final Graph graph) {
    final int size = 100;
    final List<Object> ids = new ArrayList<>();
    final Vertex v = graph.addVertex("sin", 0.0f, "cos", 1.0f, "ii", 0f);
    ids.add(v.id());

    final GraphTraversalSource g = graph.traversal();

    final Random rand = new Random();
    for (int ii = 1; ii < size; ii++) {
        final Vertex t = graph.addVertex("ii", ii, "sin", Math.sin(ii / 5.0f), "cos", Math.cos(ii / 5.0f));
        final Vertex u = g.V(ids.get(rand.nextInt(ids.size()))).next();
        t.addEdge("linked", u);
        ids.add(u.id());
        ids.add(v.id());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:18,代码来源:TinkerGraphTest.java

示例6: testPlay6

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@Ignore
public void testPlay6() throws Exception {
    final Graph graph = TinkerGraph.open();
    final GraphTraversalSource g = graph.traversal();
    for (int i = 0; i < 1000; i++) {
        graph.addVertex(T.label, "person", T.id, i);
    }
    graph.vertices().forEachRemaining(a -> {
        graph.vertices().forEachRemaining(b -> {
            if (a != b) {
                a.addEdge("knows", b);
            }
        });
    });
    graph.vertices(50).next().addEdge("uncle", graph.vertices(70).next());
    logger.info(TimeUtil.clockWithResult(500, () -> g.V().match(as("a").out("knows").as("b"), as("a").out("uncle").as("b")).toList()).toString());
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:19,代码来源:TinkerGraphPlayTest.java

示例7: loadSection

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
private static void loadSection(long [] map, Iterator<? extends CharSequence> it, Graph graph, DictionarySectionRole role) {

		int count=0;
		while(it.hasNext()) {
			String str = it.next().toString();

			Vertex v = graph.addVertex(str);
//			v.property("node", str);
			map[count] = (long) v.id();

			if((count%1000000)==0) {
				System.out.println(role+" Vertex: "+(count/1000000)+"M");
			}
			count++;
		}
	}
 
开发者ID:rdfhdt,项目名称:hdt-gremlin,代码行数:17,代码来源:HDTtoGremlin.java

示例8: shouldReadWriteSelfLoopingEdges

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphml()).writer().create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphml()).reader().create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:IoTest.java

示例9: shouldUseLongIdManagerToCoerceTypes

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldUseLongIdManagerToCoerceTypes() {
    final Graph graph = TinkerGraph.open(longIdManagerConfig);
    final Vertex v = graph.addVertex(T.id, vertexIdValue);
    final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "value", T.id, vertexPropertyIdValue);
    final Edge e = v.addEdge("self", v, T.id, edgeIdValue);

    assertEquals(100l, v.id());
    assertEquals(200l, e.id());
    assertEquals(300l, vp.id());
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:12,代码来源:TinkerGraphIdManagerTest.java

示例10: shouldUseIntegerIdManagerToCoerceTypes

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldUseIntegerIdManagerToCoerceTypes() {
    final Graph graph = TinkerGraph.open(integerIdManagerConfig);
    final Vertex v = graph.addVertex(T.id, vertexIdValue);
    final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "value", T.id, vertexPropertyIdValue);
    final Edge e = v.addEdge("self", v, T.id, edgeIdValue);

    assertEquals(100, v.id());
    assertEquals(200, e.id());
    assertEquals(300, vp.id());
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:12,代码来源:TinkerGraphIdManagerTest.java

示例11: shouldUseIdManagerToCoerceTypes

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldUseIdManagerToCoerceTypes() {
    final Graph graph = TinkerGraph.open(idManagerConfig);
    final Vertex v = graph.addVertex(T.id, vertexIdValue);
    final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "value", T.id, vertexPropertyIdValue);
    final Edge e = v.addEdge("self", v, T.id, edgeIdValue);

    assertEquals(vertexId, v.id());
    assertEquals(edgeId, e.id());
    assertEquals(vertexPropertyId, vp.id());
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:12,代码来源:TinkerGraphIdManagerTest.java

示例12: addConcepts

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
private void addConcepts(Graph graph) {
    Vertex vertex1 = graph.addVertex();
    vertex1.property("ITEM_IDENTIFIER", "www.grakn.com/action-movie/");
    vertex1.property(Schema.VertexProperty.VALUE_STRING.name(), "hi there");

    Vertex vertex2 = graph.addVertex();
    vertex2.property(Schema.VertexProperty.VALUE_STRING.name(), "hi there");
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:9,代码来源:TxFactoryJanusTest.java

示例13: createRandomGraph

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
public static void createRandomGraph(final Graph graph, final int numberOfVertices, final int maxNumberOfEdgesPerVertex) {
    final Random random = new Random();
    for (int i = 0; i < numberOfVertices; i++) {
        graph.addVertex(T.id, i);
    }
    graph.vertices().forEachRemaining(vertex -> {
        for (int i = 0; i < random.nextInt(maxNumberOfEdgesPerVertex); i++) {
            final Vertex other = graph.vertices(random.nextInt(numberOfVertices)).next();
            vertex.addEdge("link", other);
        }
    });
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:13,代码来源:TestHelper.java

示例14: shouldShouldSerializeMapEntries

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldShouldSerializeMapEntries() throws Exception {
    final Graph graph = TinkerGraph.open();
    final Vertex v1 = graph.addVertex();
    final Date d = new Date();

    final Map<Object, Object> map = new HashMap<>();
    map.put("x", 1);
    map.put(v1, 100);
    map.put(d, "test");

    final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(IteratorUtils.asList(map)).create());
    final JsonNode json = mapper.readTree(results);

    assertNotNull(json);
    assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
    final JsonNode jsonObject = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
    jsonObject.elements().forEachRemaining(e -> {
        if (e.has("x"))
            assertEquals(1, e.get("x").asInt());
        else if (e.has(v1.id().toString()))
            assertEquals(100, e.get(v1.id().toString()).asInt());
        else if (e.has(StdDateFormat.instance.format(d)))
            assertEquals("test", e.get(StdDateFormat.instance.format(d)).asText());
        else
            fail("Map entries contains a key that is not part of what was serialized");
    });
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:29,代码来源:GraphSONMessageSerializerV1d0Test.java

示例15: shouldSerializeMapEntries

import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSerializeMapEntries() throws Exception {
    final Graph graph = TinkerGraph.open();
    final Vertex v1 = graph.addVertex();
    final Date d = new Date();

    final Map<Object, Object> map = new HashMap<>();
    map.put("x", 1);
    map.put(v1, 100);
    map.put(d, "test");

    final ResponseMessage response = convert(IteratorUtils.asList(map.entrySet()));
    assertCommon(response);

    final List<Map<String, Object>> deserializedEntries = (List<Map<String, Object>>) response.getResult().getData();
    assertEquals(3, deserializedEntries.size());
    deserializedEntries.forEach(e -> {
        if (e.containsKey("x"))
            assertEquals(1, e.get("x"));
        else if (e.containsKey(v1.id().toString()))
            assertEquals(100, e.get(v1.id().toString()));
        else if (e.containsKey(StdDateFormat.instance.format(d)))
            assertEquals("test", e.get(StdDateFormat.instance.format(d)));
        else
            fail("Map entries contains a key that is not part of what was serialized");
    });
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:28,代码来源:GraphSONMessageSerializerGremlinV1d0Test.java


注:本文中的org.apache.tinkerpop.gremlin.structure.Graph.addVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。