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


Java GraphTraversal类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal的典型用法代码示例。如果您正苦于以下问题:Java GraphTraversal类的具体用法?Java GraphTraversal怎么用?Java GraphTraversal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GraphTraversal类属于org.apache.tinkerpop.gremlin.process.traversal.dsl.graph包,在下文中一共展示了GraphTraversal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversalSource g) {
  GraphTraversal traversal = g.addV(element.label());
  if (element.id() != null && HasFeature.Verifier.of(g)
      .verify(supportsUserSuppliedIds(element))) {
    traversal.property(T.id, element.id());
  }
  for (Field field : keyFields(element)) {
    String key = propertyKey(field);
    Object value = propertyValue(field, element);
    if (isMissing(value)) {
      throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing(
          element.getClass(), key);
    }
    traversal.property(key, value);
  }
  return traversal;
}
 
开发者ID:karthicks,项目名称:gremlin-ogm,代码行数:20,代码来源:AddV.java

示例2: shouldPluginSugar

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Test
public void shouldPluginSugar() throws Exception {
    MetaRegistryUtil.clearRegistry(new HashSet<>(Arrays.asList(TinkerGraph.class)));

    final SugarGremlinPlugin plugin = new SugarGremlinPlugin();

    final Groovysh groovysh = new Groovysh();

    final Map<String, Object> env = new HashMap<>();
    env.put("ConsolePluginAcceptor.io", new IO());
    env.put("ConsolePluginAcceptor.shell", groovysh);

    final SpyPluginAcceptor spy = new SpyPluginAcceptor(groovysh::execute, () -> env);
    plugin.pluginTo(spy);

    groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());
    assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V()")).count().next());
    assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V")).count().next());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:20,代码来源:SugarGremlinPluginTest.java

示例3: find

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
/**
 * Find the given element using it's id, if it has one, or all of it's properties.
 */
protected <E extends Element> GraphTraversal find(E element) {
  GraphTraversal traversal = g.V();
  if (element.id() != null) {
    traversal = traversal.hasId(element.id());
  } else {
    traversal = traversal.hasLabel(element.label());
    Object[] properties = Properties.id(element);
    if (properties == null || properties.length == 0) {
      properties = Properties.all(element);
    }
    for (Property property : list(properties)) {
      traversal = traversal.has(property.key(), property.value());
    }
  }
  return traversal;
}
 
开发者ID:karthicks,项目名称:gremlin-ogm,代码行数:20,代码来源:ElementGraph.java

示例4: apply

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Override
public GraphTraversal<Element, Map<String, Object>> apply(
    GraphTraversal<Element, Element> traversal) {
  GraphTraversal<Element, Map<String, Object>> selectTraversal;
  if (selectKey2 == null) {
    selectTraversal = traversal.select(selectKey1);
  } else {
    selectTraversal =
        traversal.select(selectKey1, selectKey2, otherSelectKeys.toArray(new String[] {}));
  }
  if (selectKey1 != null) {
    selectTraversal.by();
  }
  if (selectKey2 != null) {
    selectTraversal.by();
  }
  otherSelectKeys.forEach(otherSelectKey -> {
    selectTraversal.by();
  });
  return selectTraversal;
}
 
开发者ID:karthicks,项目名称:gremlin-ogm,代码行数:22,代码来源:Select.java

示例5: setUp

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Before
public void setUp() {
  marko = Person.of("marko");
  vertex = new DetachedVertex(
      1, "person", new HashMap<String, Object>() {
        {
          put("name", Arrays.asList(new HashMap() {
            {
              put("value", "marko");
            }
          }));
        }
      });

  g = mock(GraphTraversalSource.class);
  traversal = mock(GraphTraversal.class);

  when(g.V()).thenReturn(traversal);

  query = new ObjectQuery(g);
}
 
开发者ID:karthicks,项目名称:gremlin-ogm,代码行数:22,代码来源:ObjectQueryTest.java

示例6: insertList

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
private static void insertList(final List list, final String listKey, final GraphTraversal traversal) {
    if (list.get(0) instanceof List)
        throw new IllegalArgumentException("Lists can not contain nested lists");
    char state = list.get(0) instanceof Map ? 'o' : 'p';
    for (int i = 1; i < list.size(); i++) {
        if (list.get(i) instanceof Map && 'p' == state)
            throw new IllegalArgumentException("Lists can only support all objects or all primitives");
        else if (list.get(i) instanceof List)
            throw new IllegalArgumentException("Lists can not contain nested lists");
        else if (!(list.get(i) instanceof Map) && 'o' == state)
            throw new IllegalArgumentException("Lists can only support all objects or all primitives");
    }
    for (final Object object : list) {
        if ('p' == state)
            traversal.property(VertexProperty.Cardinality.list, listKey, object);
        else {
            traversal.map(insertMap((Map) object, new DefaultGraphTraversal()));
            traversal.addE(listKey).from("a").select("a");
        }
    }
}
 
开发者ID:okram,项目名称:mongodb-gremlin,代码行数:22,代码来源:MongoDBStrategy.java

示例7: getEntity

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的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: testSaveHierarchical

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT,
        invocationCount = CONCURRENT_TEST_INVOCATIONS)
public void testSaveHierarchical() {
    ResourceEntity childResource = persist2LevelRandomResourcetoZone1();
    String childResourceId = childResource.getResourceIdentifier();

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

    Parent parent = (Parent) childResource.getParents().toArray()[0];
    traversal = this.graphTraversalSource.V(childResourceVertex.id()).out("parent")
            .has(RESOURCE_ID_KEY, parent.getIdentifier());
    assertThat(traversal.hasNext(), equalTo(true));
    Vertex parentVertex = traversal.next();
    assertThat(parentVertex.property(RESOURCE_ID_KEY).value(), equalTo(parent.getIdentifier()));
    deleteTwoLevelEntityAndParents(childResource, TEST_ZONE_1, this.resourceRepository);
}
 
开发者ID:eclipse,项目名称:keti,代码行数:20,代码来源:GraphResourceRepositoryTest.java

示例9: testUpdateAttachedEntity

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的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

示例10: getFollowRecommendation

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Override
public GraphTraversal<Vertex, Vertex> getFollowRecommendation(){
  return getUser().
      aggregate("me").
      aggregate("ignore").
      outE(Schema.FOLLOWS).
      order().by(CreateWeightIndex.WEIGHT, decr).
      outV().
      aggregate("ignore").
      cap("me").
      unfold().
      inE(Schema.FOLLOWS).
      order().by(CreateWeightIndex.WEIGHT, decr).
      inV().
      where(without("ignore"));
}
 
开发者ID:marcelocf,项目名称:janusgraph_tutorial,代码行数:17,代码来源:HadoopQueryRunner.java

示例11: getTimeline3

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的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

示例12: getTimeline2

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的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

示例13: printTimeline

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的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

示例14: transform

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
public static GraphTraversal<?, ?> transform(final Triple triple) {
    final GraphTraversal<Vertex, ?> matchTraversal = __.as(triple.getSubject().getName());
    
    final Node predicate = triple.getPredicate();
    final String uri = predicate.getURI();
    final String uriValue = Prefixes.getURIValue(uri);
    final String prefix = Prefixes.getPrefix(uri);

    switch (prefix) {
        case "edge":
            return matchTraversal.out(uriValue).as(triple.getObject().getName());
        case "property":
            return matchProperty(matchTraversal, uriValue, PropertyType.PROPERTY, triple.getObject());
        case "value":
            return matchProperty(matchTraversal, uriValue, PropertyType.VALUE, triple.getObject());
        default:
            throw new IllegalStateException(String.format("Unexpected predicate: %s", predicate));
    }
}
 
开发者ID:LITMUS-Benchmark-Suite,项目名称:sparql-to-gremlin,代码行数:20,代码来源:TraversalBuilder.java

示例15: createXOManager

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; //导入依赖的package包/类
@Before
   public void createXOManager() throws SQLException, IOException, ServiceException {
AccountManagerTester.cleanupDatabase();
xoManager = xoManagerFactory.createXOManager();
GraphTraversal<Vertex, Vertex> vertices = ((Graph) ductileGraph).traversal().V();
int counter = 0;
while (vertices.hasNext()) {
    Vertex vertex = vertices.next();
    counter++;
    Iterator<VertexProperty<Object>> properties = vertex.properties();
    while (properties.hasNext()) {
	VertexProperty<Object> property = properties.next();
	System.out.println(property.key() + ": " + property.value());
    }
}
assertEquals(7, counter);
   }
 
开发者ID:PureSolTechnologies,项目名称:Purifinity,代码行数:18,代码来源:XOEntitiesIT.java


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