Java Code Examples for org.apache.tinkerpop.gremlin.structure.Vertex#label()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Vertex#label() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRdfDocumentGraphConsumer.java From baleen with Apache License 2.0 | 6 votes |
private Object addNodeToModel(OntModel model, Vertex v) { String label = v.label(); if (DOCUMENT.equals(label)) { return addIndividual(model, v, DOCUMENT); } if (MENTION.equals(label)) { return addIndividual(model, v, v.property("type").orElse(ENTITY).toString()); } if (EVENT.equals(label)) { return addIndividual(model, v, EVENT); } if (RELATION.equals(label)) { return addIndividual(model, v, RELATION); } if (REFERENCE_TARGET.equals(label)) { return addIndividual(model, v, REFERENCE_TARGET); } getMonitor().warn("Unrecognized Label {}", label); return null; }
Example 2
Source File: HBaseGraph.java From hgraphdb with Apache License 2.0 | 5 votes |
public void validateEdge(String label, Object id, Map<String, Object> properties, Vertex inVertex, Vertex outVertex) { if (!configuration().getUseSchema() || label == null || inVertex == null || outVertex == null) return; LabelMetadata inVertexLabelMetadata = getLabel(ElementType.VERTEX, inVertex.label()); LabelMetadata labelMetadata = getLabel(ElementType.EDGE, label); LabelMetadata outVertexLabelMetadata = getLabel(ElementType.VERTEX, outVertex.label()); LabelConnection labelConnection = new LabelConnection(outVertex.label(), label, inVertex.label(), null); if (!labelConnections.contains(labelConnection)) { throw new HBaseGraphNotValidException("Edge label '" + label + "' has not been connected with inVertex '" + inVertex.label() + "' and outVertex '" + outVertex.label() + "'"); } validateTypes(labelMetadata, id, properties); }
Example 3
Source File: AbstractRdfEntityGraphConsumer.java From baleen with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Object addNodeToModel(OntModel model, Vertex v) { try { String label = v.label(); if (EVENT.equals(label)) { return addIndividual(model, v, EVENT); } if (ENTITY.equals(label)) { Iterator<VertexProperty<Object>> properties = v.properties("type"); List<?> types = Lists.newArrayList(properties).stream() .filter(VertexProperty::isPresent) .map(VertexProperty::value) .collect(Collectors.toList()); Optional<String> aggregate = mode.aggregate((List<String>) types); if (aggregate.isPresent()) { return addIndividual(model, v, aggregate.get()); } getMonitor().warn("Not type information for {} using entity", v); return addIndividual(model, v, ENTITY); } getMonitor().warn("Unrecognized Label {}", label); } catch (BaleenException e) { getMonitor().warn("Error adding node {} - {} ", v, e.getMessage()); } return null; }
Example 4
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("to-change", "blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "to-change", "dah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 5
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("old","blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "new", "dah").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 6
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldDetachVertexWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex element) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(id, element.id()); assertEquals(label, element.label()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).drop().iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 0, 0); assertThat(triggered.get(), is(true)); }
Example 7
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldReferenceVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("to-change", "blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "to-change", "dah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 8
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldReferenceVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("old","blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "new", "dah").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 9
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldReferenceVertexWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex element) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(id, element.id()); assertEquals(label, element.label()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).drop().iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 0, 0); assertThat(triggered.get(), is(true)); }
Example 10
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexPropertyWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("to-change", "blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "to-change", "dah").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 11
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexPropertyWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); v.property("old","blah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).property(VertexProperty.Cardinality.single, "new", "dah").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.V(v).properties())); assertThat(triggered.get(), is(true)); }
Example 12
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldUseActualVertexWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final String label = v.label(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex element) { assertEquals(v, element); assertEquals(id, element.id()); assertEquals(label, element.label()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).drop().iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 0, 0); assertThat(triggered.get(), is(true)); }
Example 13
Source File: VertexSerializer.java From tinkergraph-gremlin with Apache License 2.0 | 4 votes |
@Override protected String getLabel(Vertex vertex) { return vertex.label(); }