當前位置: 首頁>>代碼示例>>Java>>正文


Java Vertex類代碼示例

本文整理匯總了Java中org.apache.tinkerpop.gremlin.structure.Vertex的典型用法代碼示例。如果您正苦於以下問題:Java Vertex類的具體用法?Java Vertex怎麽用?Java Vertex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Vertex類屬於org.apache.tinkerpop.gremlin.structure包,在下文中一共展示了Vertex類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateTestParameters

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> generateTestParameters() {
    return Arrays.asList(new Object[][]{
            {__.V().count(), countStep(Vertex.class), Collections.emptyList()},
            {__.V().count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().as("a").count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().map(out()).count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().map(out()).identity().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().map(out().groupCount()).identity().count().as("a"), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().label().map(s -> s.get().length()).count(), countStep(Vertex.class), TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            {__.V().as("a").map(select("a")).count(), countStep(Vertex.class),TraversalStrategies.GlobalCache.getStrategies(TinkerGraph.class).toList()},
            //
            {__.V(), __.V(), Collections.emptyList()},
            {__.V().out().count(), __.V().out().count(), Collections.emptyList()},
            {__.V(1).count(), __.V(1).count(), Collections.emptyList()},
            {__.count(), __.count(), Collections.emptyList()},
            {__.V().map(out().groupCount("m")).identity().count().as("a"), __.V().map(out().groupCount("m")).identity().count().as("a"), Collections.emptyList()},
    });
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:21,代碼來源:TinkerGraphCountStrategyTest.java

示例2: main

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
/**
 * The main code basically instantiate its own class and call individual methods.
 * @param argv
 */
public static void main(String[] argv) {
  LoadData loader = new LoadData(Schema.CONFIG_FILE);

  Vertex users[] = loader.generateUsers(1000);
  loader.commit();
  for(Vertex user: users) {
    LOGGER.info("User {} comments:", user.value(Schema.USER_NAME).toString());
    for(Vertex update: loader.generateStatusUpdates(user, 1000)) {
      LOGGER.info("     -> {}", update.value(Schema.CONTENT).toString());
    }
    loader.commit();

    LOGGER.info("User {} follows:", user.value(Schema.USER_NAME).toString());
    for(Vertex followedUser: loader.generateFollows(user, users, 50)) {
      LOGGER.info("     -> {}", followedUser.value(Schema.USER_NAME).toString());
    }
    loader.commit();
  }

  loader.close();
}
 
開發者ID:marcelocf,項目名稱:janusgraph_tutorial,代碼行數:26,代碼來源:LoadData.java

示例3: shouldLoseTypesWithGraphSONNoTypesForEdgeProps

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的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

示例4: printTimeline

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
public void printTimeline(GraphTraversal<Vertex, Map<String, Map<String, Object>>> traversal) {
  int count = 0;
  resetTimer();
  while (traversal.hasNext()) {
    Map<String, Map<String, Object>> item = traversal.next();
    Vertex user = (Vertex) item.get(userVertex);
    Edge posts = (Edge) item.get(postsEdge);
    Vertex statusUpdate = (Vertex) item.get(statusUpdateVertex);
    LOGGER.info(
        " {}: @{} {}: {}",
        count++,
        user.value(USER_NAME),
        formatTimestamp(posts.value(CREATED_AT)),
        statusUpdate.value(CONTENT)
    );
  }

  LOGGER.info("Printed {} element(s) in {}ms", count, duration());
}
 
開發者ID:marcelocf,項目名稱:janusgraph_tutorial,代碼行數:20,代碼來源:QueryRunner.java

示例5: getTimeline3

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
public GraphTraversal<Vertex, Map<String, Map<String,Object>>> getTimeline3(int limit){
  return getUser().
      aggregate("users").
      local(
          __.outE(FOLLOWS).
              has(CreateWeightIndex.WEIGHT).
              order().by(CreateWeightIndex.WEIGHT, decr).
              dedup().
              limit(50).
              inV()
      ).
      aggregate("users").
      cap("users").
      unfold().
      as(userVertex).
      outE(POSTS).
      dedup().
      as(postsEdge).
      order().by(CREATED_AT, decr).
      limit(limit).
      inV().
      as(statusUpdateVertex).
      select(userVertex, postsEdge, statusUpdateVertex);
}
 
開發者ID:marcelocf,項目名稱:janusgraph_tutorial,代碼行數:25,代碼來源:HadoopQueryRunner.java

示例6: getTimeline2

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
public GraphTraversal<Vertex, Map<String, Map<String,Object>>> getTimeline2(int limit){
  return getUser().
      aggregate("users").
      out(FOLLOWS).
      aggregate("users").
      cap("users").
      unfold().
      as(userVertex).
      outE(POSTS).
      as(postsEdge).
      order().by(CREATED_AT, decr).
      limit(limit).
      inV().
      as(statusUpdateVertex).
      select(userVertex, postsEdge, statusUpdateVertex);
}
 
開發者ID:marcelocf,項目名稱:janusgraph_tutorial,代碼行數:17,代碼來源:QueryRunner.java

示例7: getEntity

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
/**
 * Returns the entity with attributes only on the requested vertex. No parent attributes are included.
 */
public E getEntity(final ZoneEntity zone, final String identifier) {
    try {
        GraphTraversal<Vertex, Vertex> traversal = this.graphTraversal.V().has(ZONE_ID_KEY, zone.getName())
                .has(getEntityIdKey(), identifier);
        if (!traversal.hasNext()) {
            return null;
        }
        Vertex vertex = traversal.next();
        E entity = vertexToEntity(vertex);

        // There should be only one entity with a given entity id.
        Assert.isTrue(!traversal.hasNext(),
                String.format("There are two entities with the same %s.", getEntityIdKey()));
        return entity;
    } finally {
        this.graphTraversal.tx().commit();
    }
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:22,代碼來源:GraphGenericRepository.java

示例8: testUpdateAttachedEntity

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT,
        invocationCount = CONCURRENT_TEST_INVOCATIONS)
public void testUpdateAttachedEntity() {
    ResourceEntity resourceEntity = persistRandomResourcetoZone1AndAssert();
    String resourceId = resourceEntity.getResourceIdentifier();

    GraphTraversalSource g = this.graphTraversalSource;
    GraphTraversal<Vertex, Vertex> traversal = g.V().has(RESOURCE_ID_KEY, resourceId);
    assertThat(traversal.hasNext(), equalTo(true));
    assertThat(traversal.next().property(RESOURCE_ID_KEY).value(), equalTo(resourceId));

    // Update the resource.
    String updateJSON = "{\'status':'test'}";
    resourceEntity.setAttributesAsJson(updateJSON);
    saveWithRetry(this.resourceRepository, resourceEntity, 3);
    assertThat(this.resourceRepository.getEntity(TEST_ZONE_1, resourceEntity.getResourceIdentifier())
            .getAttributesAsJson(), equalTo(updateJSON));
    this.resourceRepository.delete(resourceEntity);
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:20,代碼來源:GraphResourceRepositoryTest.java

示例9: create

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
public User create(User user) throws Exception {
  // Must first create the person and then create its wishList
  String password = user.getPassword();
  if (StringUtils.isNotBlank(password)) {
    final byte[] salt = new byte[SALT_LENGTH];
    final byte[] passwordHash = createSaltThenComputePasswordHash(salt, password);

    return graphUtils.doInGraphTransaction(graph -> {
      Vertex reactionVertex = graph.addVertex(
        T.label, "User",
        "login", user.getLogin(),
        "email", user.getEmail(),
        "passwordHash", passwordHash,
        "salt", salt,
        "creationDate", new Date());
      graphUtils.getRoot(graph).addEdge("created", reactionVertex);
      user.setId(graphUtils.getStringVertexId(reactionVertex, graph));
      return user;
    });
  } else {
    throw new IllegalArgumentException("The given user must define a password");
  }
}
 
開發者ID:iorga-group,項目名稱:debattons,代碼行數:24,代碼來源:UserService.java

示例10: generate

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的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

示例11: shouldNotAddEdgeToAVertexThatWasRemoved

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void shouldNotAddEdgeToAVertexThatWasRemoved() {
    final TinkerGraph graph = TinkerGraph.open();
    final Vertex v = graph.addVertex();
    v.property("name", "stephen");

    assertEquals("stephen", v.value("name"));
    v.remove();
    v.addEdge("self", v);
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:11,代碼來源:TinkerGraphTest.java

示例12: TinkerGraph

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
/**
 * An empty private constructor that initializes {@link TinkerGraph}.
 */
private TinkerGraph(final Configuration configuration, boolean usesSpecializedElements) {
    this.configuration = configuration;
    this.usesSpecializedElements = usesSpecializedElements;
    vertexIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, Vertex.class);
    edgeIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, Edge.class);
    vertexPropertyIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, VertexProperty.class);
    defaultVertexPropertyCardinality = VertexProperty.Cardinality.valueOf(
            configuration.getString(GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.single.name()));

    graphLocation = configuration.getString(GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null);
    graphFormat = configuration.getString(GREMLIN_TINKERGRAPH_GRAPH_FORMAT, null);

    if ((graphLocation != null && null == graphFormat) || (null == graphLocation && graphFormat != null))
        throw new IllegalStateException(String.format("The %s and %s must both be specified if either is present",
                GREMLIN_TINKERGRAPH_GRAPH_LOCATION, GREMLIN_TINKERGRAPH_GRAPH_FORMAT));

    if (graphLocation != null) loadGraph();
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:22,代碼來源:TinkerGraph.java

示例13: createElementIterator

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
private <T extends Element> Iterator<T> createElementIterator(final Class<T> clazz, final Map<Object, T> elements,
                                                              final IdManager idManager,
                                                              final Object... ids) {
    final Iterator<T> iterator;
    if (0 == ids.length) {
        iterator = elements.values().iterator();
    } else {
        final List<Object> idList = Arrays.asList(ids);
        validateHomogenousIds(idList);

        // if the type is of Element - have to look each up because it might be an Attachable instance or
        // other implementation. the assumption is that id conversion is not required for detached
        // stuff - doesn't seem likely someone would detach a Titan vertex then try to expect that
        // vertex to be findable in OrientDB
        return clazz.isAssignableFrom(ids[0].getClass()) ?
                IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(clazz.cast(id).id())).iterator(), Objects::nonNull)
                : IteratorUtils.filter(IteratorUtils.map(idList, id -> elements.get(idManager.convert(id))).iterator(), Objects::nonNull);
    }
    return TinkerHelper.inComputerMode(this) ?
            (Iterator<T>) (clazz.equals(Vertex.class) ?
                    IteratorUtils.filter((Iterator<Vertex>) iterator, t -> this.graphComputerView.legalVertex(t)) :
                    IteratorUtils.filter((Iterator<Edge>) iterator, t -> this.graphComputerView.legalEdge(t.outVertex(), t))) :
            iterator;
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:25,代碼來源:TinkerGraph.java

示例14: smallTest

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
public static void smallTest(Graph graph) {
	Iterator<Vertex> it = graph.vertices();
	int i=0;
	while(i<100 && it.hasNext()) {
		Vertex v = it.next();
		System.out.println(v.id()+"/"+v.property("node"));
		i++;

	}
	
	// Iterate over Edges
	Iterator<Edge> it2 = graph.edges();
	i=0;
	while(i<100 && it2.hasNext()) {
		Edge e = it2.next();
		System.out.println(e);
		i++;
	}
}
 
開發者ID:rdfhdt,項目名稱:hdt-gremlin,代碼行數:20,代碼來源:HDTtoGremlin.java

示例15: deserialize

import org.apache.tinkerpop.gremlin.structure.Vertex; //導入依賴的package包/類
@Override
public TinkerGraph deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals("vertices")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedVertex v = (DetachedVertex) deserializationContext.readValue(jsonParser, Vertex.class);
                    v.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        } else if (jsonParser.getCurrentName().equals("edges")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedEdge e = (DetachedEdge) deserializationContext.readValue(jsonParser, Edge.class);
                    e.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        }
    }

    return graph;
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:27,代碼來源:TinkerIoRegistryV3d0.java


注:本文中的org.apache.tinkerpop.gremlin.structure.Vertex類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。