org.apache.tinkerpop.gremlin.structure.Property类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(15.8k)|赞(0)|评价(0)|浏览(150)

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

Property介绍

[英]A Property denotes a key/value pair associated with an Edge. A property is much like a Java8 java.util.Optional in that a property can be not present (i.e. empty). The key of a property is always a String and the value of a property is an arbitrary Java object. Each underlying graph engine will typically have constraints on what Java objects are allowed to be used as values.
[中]属性表示与边关联的键/值对。属性很像Java8 java。util。可选,因为属性可能不存在(即空)。属性的键始终是字符串,属性的值是任意Java对象。每个底层图形引擎通常都会对允许哪些Java对象用作值进行约束。

代码示例

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

private void assertGeoshape(Function<Geoshape,Geoshape> makeGeoshape) {
  graph.traversal().E().has("place").toList().forEach(e-> {
    assertTrue(e.property("shape").isPresent());
    Geoshape place = (Geoshape) e.property("place").value();
    Geoshape expected = makeGeoshape.apply(place);
    Geoshape actual = (Geoshape) e.property("shape").value();
    assertEquals(expected, actual);
  });
}

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

@Override
public void remove() {
  this.baseProperty.remove();
}

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

@Override
public <U> Property<U> property(String key, U value) {
  return Property.<U>empty();
}

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

@Override
public void map(final Vertex vertex, final MapEmitter<Object, Double> emitter) {
  final Property pageRank = vertex.property(PageRankVertexProgram.PAGE_RANK);
  if (pageRank.isPresent()) {
    emitter.emit(vertex.id(), (Double) pageRank.value());
  }
}

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

private static void assertGraphEquality(final Graph source, final Graph target, final Function<Vertex, Object> idAccessor) {
  final GraphTraversalSource tg = target.traversal();
  assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
  assertEquals(IteratorUtils.count(target.edges()), IteratorUtils.count(target.edges()));
  source.vertices().forEachRemaining(originalVertex -> {
    while (vertexIterator.hasNext()) {
      final Vertex v = vertexIterator.next();
      if (idAccessor.apply(v).toString().equals(originalVertex.id().toString())) {
        tmpVertex = v;
        break;
    });
    originalVertex.edges(Direction.OUT).forEachRemaining(originalEdge -> {
      GraphTraversal t = tg.V(clonedVertex).outE(originalEdge.label());
      originalEdge.properties().forEachRemaining(p -> t.has(p.key(), p.value()));
      assertTrue(t.hasNext());
    });
  });

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

@Override
  public void edgePropertyRemoved(final Edge element, final Property property) {
    assertThat(element, instanceOf(DetachedEdge.class));
    assertEquals(label, element.label());
    assertEquals(inId, element.inVertex().id());
    assertEquals(outId, element.outVertex().id());
    assertEquals("dah", property.value());
    assertEquals("to-drop", property.key());
    triggered.set(true);
  }
};

代码示例来源:origin: com.bitplan.simplegraph/com.bitplan.simplegraph-core

public static void dumpGraph(Graph graph) {
 graph.traversal().V().forEachRemaining(vertex -> {
  System.out.println(String.format("%s=%s", vertex.id(), vertex.label()));
  vertex.properties().forEachRemaining(prop -> {
   System.out.println(String.format("\t%s=%s", prop.key(), prop.value()));
  });
 });
 graph.traversal().E().forEachRemaining(edge -> {
  System.out.println(String.format("%s- %s >%s", edge.inVertex().id(),
    edge.label(), edge.outVertex().id()));
  edge.properties().forEachRemaining(prop -> {
   System.out.println(String.format("\t%s=%s", prop.key(), prop.value()));
  });
 });
}

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

private Vertex getOrCreate(final Vertex vertex) {
  final Iterator<Vertex> vertexIterator = subgraph.vertices(vertex.id());
  if (vertexIterator.hasNext()) return vertexIterator.next();
  final Vertex subgraphVertex = subgraph.addVertex(T.id, vertex.id(), T.label, vertex.label());
  vertex.properties().forEachRemaining(vertexProperty -> {
    final VertexProperty.Cardinality cardinality = parentGraphFeatures.getCardinality(vertexProperty.key());
    final VertexProperty<?> subgraphVertexProperty = subgraphVertex.property(cardinality, vertexProperty.key(), vertexProperty.value(), T.id, vertexProperty.id());
    // only iterate the VertexProperties if the current graph can have them and if the subgraph can support
    // them. unfortunately we don't have a way to write a test for this as we dont' have a graph that supports
    // user supplied ids and doesn't support metaproperties.
    if (parentGraphFeatures.supportsMetaProperties() && subgraphSupportsMetaProperties) {
      vertexProperty.properties().forEachRemaining(property -> subgraphVertexProperty.property(property.key(), property.value()));
    }
  });
  return subgraphVertex;
}

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

public static Edge createEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
  final Edge baseEdge = attachableEdge.get();
  Iterator<Vertex> vertices = hostGraph.vertices(baseEdge.outVertex().id());
  final Vertex outV = vertices.hasNext() ? vertices.next() : hostGraph.features().vertex().willAllowId(baseEdge.outVertex().id()) ? hostGraph.addVertex(T.id, baseEdge.outVertex().id()) : hostGraph.addVertex();
  vertices = hostGraph.vertices(baseEdge.inVertex().id());
  final Vertex inV = vertices.hasNext() ? vertices.next() : hostGraph.features().vertex().willAllowId(baseEdge.inVertex().id()) ? hostGraph.addVertex(T.id, baseEdge.inVertex().id()) : hostGraph.addVertex();
  if (ElementHelper.areEqual(outV, inV)) {
    final Iterator<Edge> itty = outV.edges(Direction.OUT, baseEdge.label());
    while (itty.hasNext()) {
      final Edge e = itty.next();
      if (ElementHelper.areEqual(baseEdge, e))
        return e;
    }
  }
  final Edge e = hostGraph.features().edge().willAllowId(baseEdge.id()) ? outV.addEdge(baseEdge.label(), inV, T.id, baseEdge.id()) : outV.addEdge(baseEdge.label(), inV);
  baseEdge.properties().forEachRemaining(p -> e.property(p.key(), p.value()));
  return e;
}

代码示例来源:origin: HuygensING/timbuctoo

static void moveOutgoingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) {
 for (Iterator<Edge> edges = vertex.edges(Direction.OUT); edges.hasNext(); ) {
  Edge edge = edges.next();
  if (edge.label().equals(VERSION_OF)) {
   continue;
  }
  Edge duplicateEdge = duplicate.addEdge(edge.label(), edge.inVertex());
  for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
   Property<Object> property = properties.next();
   duplicateEdge.property(property.key(), property.value());
  }
  if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) {
   duplicateEdge.<String>property("tim_id")
    .ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge));
  }
  edge.remove();
 }
}

代码示例来源:origin: MartinHaeusler/chronos

@Test
public void removingVertexMetaPropertiesWorks() {
  Graph g = this.getGraph();
  Vertex me = g.addVertex("kind", "person", "name", "martin");
  me.property("kind").property("job", "researcher");
  g.tx().commit();
  Vertex me2 = g.traversal().V().has("name", "martin").toSet().iterator().next();
  assertNotNull(me2);
  assertTrue(me2.property("kind").isPresent());
  assertTrue(me2.property("kind").property("job").isPresent());
  assertEquals("person", me2.value("kind"));
  assertEquals("researcher", me2.property("kind").value("job"));
  me2.property("kind").property("job").remove();
  g.tx().commit();
  Vertex me3 = g.traversal().V().has("name", "martin").toSet().iterator().next();
  assertNotNull(me3);
  assertTrue(me3.property("kind").isPresent());
  assertFalse(me3.property("kind").property("job").isPresent());
}

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

/**
 * Creates a clone of the given property for the given vertex.
 *
 * @param property The property to be cloned.
 * @param vertex   The vertex in the given graph..
 * @param graph    The graph that holds the given vertex.
 * @param g        A standard traversal source for the given graph.
 * @return The cloned property.
 */
public default VertexProperty createVertexProperty(final VertexProperty<?> property, final Vertex vertex, final Graph graph, final GraphTraversalSource g) {
  final VertexProperty result = vertex.property(property.key(), property.value());
  property.properties().forEachRemaining(metaProperty -> result.property(metaProperty.key(), metaProperty.value()));
  return result;
}

代码示例来源:origin: org.jboss.windup.reporting/windup-reporting-api

/**
 * Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided {@link FileModel}.
 */
public int getMigrationEffortPoints(FileModel fileModel)
{
  GraphTraversal<Vertex, Vertex> classificationPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement());
  classificationPipeline.in(ClassificationModel.FILE_MODEL);
  classificationPipeline.has(EffortReportModel.EFFORT, P.gt(0));
  classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE));
  int classificationEffort = 0;
  for (Vertex v : classificationPipeline.toList())
  {
    Property<Integer> migrationEffort = v.property(ClassificationModel.EFFORT);
    if (migrationEffort.isPresent())
    {
      classificationEffort += migrationEffort.value();
    }
  }
  return classificationEffort;
}

代码示例来源:origin: MartinHaeusler/chronos

@Test
public void removingEdgePropertiesWorks() {
  Graph g = this.getGraph();
  Vertex me = g.addVertex("kind", "person", "name", "martin");
  Vertex john = g.addVertex("kind", "person", "name", "john");
  me.addEdge("friend", john, "since", "forever");
  g.tx().commit();
  // find the edge
  Edge friendship = g.traversal().E().has("since", "forever").toSet().iterator().next();
  assertNotNull(friendship);
  // remove the edge property and commit
  friendship.property("since").remove();
  g.tx().commit();
  // assert that the property is gone
  Vertex me2 = g.traversal().V().has("name", "martin").toSet().iterator().next();
  Iterator<Edge> edges = me2.edges(Direction.BOTH, "friend");
  assertTrue(edges.hasNext());
  Edge friendship2 = Iterators.getOnlyElement(edges);
  assertNotNull(friendship2);
  assertFalse(friendship2.property("since").isPresent());
}

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

public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) {
  final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get();
  final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id());
  if (vertexIterator.hasNext()) {
    final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(baseVertexProperty.id()) ?
        vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) :
        vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value());
    baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
    return vertexProperty;
  }
  throw new IllegalStateException("Could not find vertex to create the attachable vertex property on");
}

代码示例来源: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

public void shouldDetachCollections() {
  final Vertex vertex = DetachedFactory.detach(g.V().has("name", "marko").next(), true);
  assertTrue(vertex instanceof DetachedVertex);
  final List<Vertex> vertices = DetachedFactory.detach(g.V().hasLabel("software").fold().next(), true);
  for (final Vertex v : vertices) {
    assertTrue(v instanceof DetachedVertex);
    assertEquals("java", v.value("lang"));
  final List<List<Vertex>> lists = DetachedFactory.detach(g.V().hasLabel("software").fold().fold().next(), true);
  for (final Vertex v : lists.get(0)) {
    assertTrue(v instanceof DetachedVertex);
    assertEquals("java", v.value("lang"));
  for (final Vertex v : set.iterator().next()) {
    assertTrue(v instanceof DetachedVertex);
    assertEquals("java", v.value("lang"));
    for (final Edge edge : entry.getValue()) {
      assertTrue(edge instanceof DetachedEdge);
      assertTrue(edge.property("weight").isPresent());
    for (final Edge edge : entry.getValue()) {
      assertTrue(edge instanceof DetachedEdge);
      assertTrue(edge.property("weight").isPresent());

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

@Test
@LoadGraphWith(GraphData.MODERN)
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
public void shouldConstructDetachedEdge() {
  g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("year", 2002);
  final DetachedEdge detachedEdge = DetachedFactory.detach(g.E(convertToEdgeId("marko", "knows", "vadas")).next(), true);
  assertEquals(convertToEdgeId("marko", "knows", "vadas"), detachedEdge.id());
  assertEquals("knows", detachedEdge.label());
  assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.OUT).next().getClass());
  assertEquals(convertToVertexId("marko"), detachedEdge.vertices(Direction.OUT).next().id());
  assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());
  assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.IN).next().getClass());
  assertEquals(convertToVertexId("vadas"), detachedEdge.vertices(Direction.IN).next().id());
  assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());
  assertEquals(2, IteratorUtils.count(detachedEdge.properties()));
  assertEquals(1, IteratorUtils.count(detachedEdge.properties("year")));
  assertEquals(0.5d, detachedEdge.properties("weight").next().value());
}

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

private void writeEdges(final XMLStreamWriter writer, final Graph graph) throws XMLStreamException {
  if (normalize) {
    final List<Edge> edges = IteratorUtils.list(graph.edges());
    Collections.sort(edges, Comparators.ELEMENT_COMPARATOR);
      writer.writeAttribute(GraphMLTokens.ID, edge.id().toString());
      writer.writeAttribute(GraphMLTokens.SOURCE, edge.outVertex().id().toString());
      writer.writeAttribute(GraphMLTokens.TARGET, edge.inVertex().id().toString());
        writer.writeCharacters(edge.property(key).orElse("").toString());
        writer.writeEndElement();
    final Iterator<Edge> iterator = graph.edges();
    while (iterator.hasNext()) {
      final Edge edge = iterator.next();
      writer.writeStartElement(GraphMLTokens.EDGE);
      writer.writeAttribute(GraphMLTokens.ID, edge.id().toString());
      writer.writeAttribute(GraphMLTokens.SOURCE, edge.outVertex().id().toString());
      writer.writeAttribute(GraphMLTokens.TARGET, edge.inVertex().id().toString());
        writer.writeCharacters(edge.property(key).orElse("").toString());
        writer.writeEndElement();

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

private void addEdgeToSubgraph(final Edge edge) {
    final Iterator<Edge> edgeIterator = subgraph.edges(edge.id());
    if (edgeIterator.hasNext()) return;
    final Iterator<Vertex> vertexIterator = edge.vertices(Direction.BOTH);
    final Vertex subGraphOutVertex = getOrCreate(vertexIterator.next());
    final Vertex subGraphInVertex = getOrCreate(vertexIterator.next());
    final Edge subGraphEdge = subGraphOutVertex.addEdge(edge.label(), subGraphInVertex, T.id, edge.id());
    edge.properties().forEachRemaining(property -> subGraphEdge.property(property.key(), property.value()));
  }
}

相关文章