Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#has()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#has() .
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: GremlinConsumer.java From baleen with Apache License 2.0 | 6 votes |
private GraphTraversal<Vertex, Vertex> buildTraversal(String label, Object... values) { GraphTraversal<Vertex, Vertex> t = g.traversal().V().hasLabel(label); for (int i = 0; i < values.length; i += 2) { String key = values[i].toString(); Object value = values[i + 1]; if (value == null) { t = t.hasNot(key); } else { t = t.has(key, value); } } return t; }
Example 2
Source File: SocialTraversalSourceDsl.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Starts a traversal that finds all vertices with a "person" label and optionally allows filtering of those * vertices on the "name" property. * * @param names list of person names to filter on */ public GraphTraversal<Vertex, Vertex> persons(String... names) { GraphTraversalSource clone = this.clone(); // Manually add a "start" step for the traversal in this case the equivalent of V(). GraphStep is marked // as a "start" step by passing "true" in the constructor. clone.getBytecode().addStep(GraphTraversal.Symbols.V); GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone); traversal.asAdmin().addStep(new GraphStep<>(traversal.asAdmin(), Vertex.class, true)); traversal = traversal.hasLabel("person"); if (names.length > 0) traversal = traversal.has("name", P.within(names)); return traversal; }
Example 3
Source File: HasKeys.java From gremlin-ogm with Apache License 2.0 | 5 votes |
@Override @SneakyThrows public GraphTraversal<Element, Element> apply(GraphTraversal<Element, Element> traversal) { traversal.hasLabel(element.label()); List<Field> fields; if (keyType != null) { if (is(keyType, PrimaryKey.class)) { fields = primaryKeyFields(element); } else if (is(keyType, OrderingKey.class)) { fields = orderingKeyFields(element); } else { throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions .invalidAnnotationType(keyType); } } else { fields = keyFields(element); } for (Field field : fields) { 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.has(key, value); } return traversal; }
Example 4
Source File: TraversalBuilder.java From tinkerpop with Apache License 2.0 | 5 votes |
private static GraphTraversal<?, ?> matchProperty(final GraphTraversal<?, ?> traversal, final String propertyName, final PropertyType type, final Node object) { switch (propertyName) { case "id": return object.isConcrete() ? traversal.hasId(object.getLiteralValue()) : traversal.id().as(object.getName()); case "label": return object.isConcrete() ? traversal.hasLabel(object.getLiteralValue().toString()) : traversal.label().as(object.getName()); case "key": return object.isConcrete() ? traversal.hasKey(object.getLiteralValue().toString()) : traversal.key().as(object.getName()); case "value": return object.isConcrete() ? traversal.hasValue(object.getLiteralValue().toString()) : traversal.value().as(object.getName()); default: if (type.equals(PropertyType.PROPERTY)) { return traversal.properties(propertyName).as(object.getName()); } else { return object.isConcrete() ? traversal.has(propertyName, object.getLiteralValue()) : traversal.values(propertyName).as(object.getName()); } } }
Example 5
Source File: QueryTypeCriterion.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Adds a criterion to given pipeline which filters out vertices representing given WindupVertexFrame. */ public static GraphTraversal<Vertex, Vertex> addPipeFor(GraphTraversal<Vertex, Vertex> pipeline, Class<? extends WindupVertexFrame> clazz) { pipeline.has(WindupVertexFrame.TYPE_PROP, GraphTypeManager.getTypeValue(clazz)); return pipeline; }
Example 6
Source File: ClassificationService.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Return all {@link ClassificationModel} instances that are attached to the given {@link FileModel} instance. */ public Iterable<ClassificationModel> getClassifications(FileModel model) { GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(model.getElement()); pipeline.in(ClassificationModel.FILE_MODEL); pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE)); return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), ClassificationModel.class); }
Example 7
Source File: InlineHintService.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Gets all {@link InlineHintModel} instances that are directly associated with the given {@link FileReferenceModel} */ public Iterable<InlineHintModel> getHintsForFileReference(FileReferenceModel reference) { GraphTraversal<Vertex, Vertex> inlineHintPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(reference.getElement()); inlineHintPipeline.in(InlineHintModel.FILE_LOCATION_REFERENCE); inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE)); return new FramedVertexIterable<>(getGraphContext().getFramed(), inlineHintPipeline.toList(), InlineHintModel.class); }
Example 8
Source File: TestEdgeHas.java From sqlg with MIT License | 5 votes |
@Test public void testEdgeHas() { Vertex stephen = this.sqlgGraph.addVertex("name", "stephen"); Vertex marko = this.sqlgGraph.addVertex("name", "marko"); stephen.addEdge("knows", marko, "weight", 1.0d); stephen.addEdge("knows", marko, "weight", 2.0d); this.sqlgGraph.tx().commit(); GraphTraversal knows = vertexTraversal(this.sqlgGraph, stephen).outE("knows"); knows.has("weight", 1.0d); Assert.assertEquals(1L, knows.count().next()); Assert.assertEquals(1, vertexTraversal(this.sqlgGraph, stephen).outE("knows").has("weight", 1.0d).count().next(), 0); }
Example 9
Source File: AbstractRolePlayerFragment.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
static void applyLabelsToTraversal( GraphTraversal<?, Edge> traversal, Schema.EdgeProperty property, @Nullable Set<Label> typeLabels, ConceptManager conceptManager) { if (typeLabels != null) { Set<Integer> typeIds = typeLabels.stream().map(label -> conceptManager.convertToId(label).getValue()).collect(toSet()); traversal.has(property.name(), P.within(typeIds)); } }
Example 10
Source File: QueryPropertyCriterion.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public void query(GraphRewrite event, GraphTraversal<?, Vertex> pipeline) { switch (searchType) { case EQUALS: pipeline.has(this.propertyName, this.searchValue); break; case NOT_EQUALS: pipeline.has(this.propertyName, P.neq(this.searchValue)); break; case CONTAINS_TOKEN: pipeline.has(this.propertyName, Text.textContains(searchValue)); break; case CONTAINS_ANY_TOKEN: pipeline.has(this.propertyName, new P(new MultipleValueTitanPredicate(), searchValue)); break; case REGEX: pipeline.has(this.propertyName, Text.textRegex(searchValue)); break; case DEFINED: pipeline.has(this.propertyName); break; case NOT_DEFINED: pipeline.hasNot(this.propertyName); break; default: throw new IllegalArgumentException("Unrecognized property query type: " + searchType); } }
Example 11
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void updateEntityInStore(EntityDetail entity) throws RepositoryErrorException { String methodName = "updateEntityInStore"; // Look in the graph String guid = entity.getGUID(); GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, guid); // Only looking for non-proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, false); if (gt.hasNext()) { Vertex vertex = gt.next(); log.debug("{} found entity vertex {}", methodName, vertex); try { // Check if we have stumbled on a proxy somehow, and if so avoid processing it. Boolean isProxy = entityMapper.isProxy(vertex); if (!isProxy) { entityMapper.mapEntityDetailToVertex(entity, vertex); updateEntityClassifications(entity, vertex, g); } } catch (Exception e) { log.error("{} caught exception {}", methodName, e.getMessage()); g.tx().rollback(); throw new RepositoryErrorException(GraphOMRSErrorCode.ENTITY_NOT_UPDATED.getMessageDefinition(entity.getGUID(), methodName, this.getClass().getName(), repositoryName), this.getClass().getName(), methodName, e); } } log.debug("{} commit entity update tx: ", methodName); g.tx().commit(); }
Example 12
Source File: Has.java From gremlin-ogm with Apache License 2.0 | 4 votes |
@Override public GraphTraversal<Element, Element> apply(GraphTraversal<Element, Element> traversal) { return traversal.has(label, key, value); }
Example 13
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void removeEntityFromStore(String entityGUID) { final String methodName = "removeEntityFromStore"; // Look in the graph String guid = entityGUID; GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID); // Only looking for non-proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, false); if (gt.hasNext()) { Vertex vertex = gt.next(); Boolean isProxy = entityMapper.isProxy(vertex); if (!isProxy) { log.debug("{} found entity vertex {} to be removed", methodName, vertex); // Look for associated classifications. Iterator<Edge> classifierEdges = vertex.edges(Direction.OUT, "Classifier"); while (classifierEdges.hasNext()) { Edge classifierEdge = classifierEdges.next(); Vertex classificationVertex = classifierEdge.inVertex(); // Get the classification's name for debug/info only Classification existingClassification = new Classification(); try { classificationMapper.mapVertexToClassification(classificationVertex, existingClassification); } catch (Exception e) { log.error("{} caught exception from classification mapper for classification {}", methodName, existingClassification.getName()); // Nothing you can do - just keep going } log.debug("{} removing classification {} from entity", methodName, existingClassification.getName()); classifierEdge.remove(); classificationVertex.remove(); } // Finally remove the entity vertex... vertex.remove(); log.debug("{} removed entity vertex with guid {}", methodName, entityGUID); } } g.tx().commit(); }
Example 14
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void updateEntityProxyInStore(EntityProxy entityProxy) throws RepositoryErrorException { String methodName = "updateEntityProxyInStore"; log.debug("{}", methodName); // Look in the graph String guid = entityProxy.getGUID(); GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, guid); // Only looking for proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, true); if (gt.hasNext()) { Vertex vertex = gt.next(); log.debug("{} found entity vertex {}", methodName, vertex); try { // Check if we have stumbled on a proxy somehow, and if so avoid processing it. Boolean isProxy = entityMapper.isProxy(vertex); if (isProxy) { entityMapper.mapEntityProxyToVertex(entityProxy, vertex); updateEntityClassifications(entityProxy, vertex, g); } } catch (Exception e) { log.error("{} caught exception {}", methodName, e.getMessage()); g.tx().rollback(); throw new RepositoryErrorException(GraphOMRSErrorCode.ENTITY_NOT_UPDATED.getMessageDefinition(entityProxy.getGUID(), methodName, this.getClass().getName(), repositoryName), this.getClass().getName(), methodName, e); } } log.debug("{} commit entity proxy update tx: ", methodName); g.tx().commit(); }
Example 15
Source File: TraceTraversalSourceDsl.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public GraphTraversal<Vertex, Vertex> trace(int traceId) { GraphTraversal traversal = this.clone().V(); return traversal.has(Keys.TRACE_ID, traceId); }
Example 16
Source File: TypeReferenceService.java From windup with Eclipse Public License 1.0 | 4 votes |
private void getPackageUseFrequencies(Map<String, Integer> data, ProjectModel projectModel, Set<String> includeTags, Set<String> excludeTags, int nameDepth, boolean recursive) { ExecutionStatistics.get().begin("TypeReferenceService.getPackageUseFrequencies(data,projectModel,nameDepth,recursive)"); if (projectModel instanceof DuplicateProjectModel) projectModel = ((DuplicateProjectModel)projectModel).getCanonicalProject(); InlineHintService hintService = new InlineHintService(getGraphContext()); // 1. Get all JavaHints for the given project GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(projectModel.getElement()); pipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE).in(InlineHintModel.FILE_MODEL); pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE)); pipeline.as("inlineHintVertex"); pipeline.out(InlineHintModel.FILE_LOCATION_REFERENCE) .has(WindupVertexFrame.TYPE_PROP, Text.textContains(JavaTypeReferenceModel.TYPE)); pipeline.select("inlineHintVertex"); // 2. Organize them by package name // summarize results. for (Vertex inlineHintVertex : pipeline.toList()) { InlineHintModel javaInlineHint = hintService.frame(inlineHintVertex); // only check tags if we have some passed in if (!includeTags.isEmpty() || !excludeTags.isEmpty()) { if (!TagUtil.checkMatchingTags(javaInlineHint.getTags(), includeTags, excludeTags)) continue; } int val = 1; FileLocationModel fileLocationModel = javaInlineHint.getFileLocationReference(); if (fileLocationModel == null || !(fileLocationModel instanceof JavaTypeReferenceModel)) { continue; } JavaTypeReferenceModel typeReferenceModel = (JavaTypeReferenceModel) fileLocationModel; String pattern = typeReferenceModel.getResolvedSourceSnippit(); String[] keyArray = pattern.split("\\."); if (keyArray.length > 1 && nameDepth > 1) { StringBuilder patternSB = new StringBuilder(); for (int i = 0; i < nameDepth; i++) { String subElement = keyArray[i]; // FIXME/TODO - This shouldn't be necessary, but is at the moment due to some stuff emmitted by our // AST if (subElement.contains("(") || subElement.contains(")")) { continue; } if (patternSB.length() != 0) { patternSB.append("."); } patternSB.append(subElement); } if (patternSB.toString().contains(".")) { patternSB.append(".*"); } pattern = patternSB.toString(); } if (pattern.contains("(")) { pattern = pattern.substring(0, pattern.indexOf('(')); } if (data.containsKey(pattern)) { val = data.get(pattern); val++; } data.put(pattern, val); } if (recursive) { for (ProjectModel childProject : projectModel.getChildProjects()) { ExecutionStatistics.get().end("TypeReferenceService.getPackageUseFrequencies(data,projectModel,nameDepth,recursive)"); getPackageUseFrequencies(data, childProject, includeTags, excludeTags, nameDepth, recursive); ExecutionStatistics.get().begin("TypeReferenceService.getPackageUseFrequencies(data,projectModel,nameDepth,recursive)"); } } ExecutionStatistics.get().end("TypeReferenceService.getPackageUseFrequencies(data,projectModel,nameDepth,recursive)"); }
Example 17
Source File: TraceTraversalSourceDsl.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public GraphTraversal<Vertex, Vertex> duration(Predicate<Integer> p) { GraphTraversal traversal = this.clone().V(); traversal = traversal.has(Keys.DURATION, p); return traversal; }
Example 18
Source File: TraceTraversalSourceDsl.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public GraphTraversal<Vertex, Vertex> startTime(Predicate<Integer> p) { GraphTraversal traversal = this.clone().V(); traversal = traversal.has(Keys.START_TIME, p); return traversal; }
Example 19
Source File: TraceTraversalSourceDsl.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public GraphTraversal<Vertex, Vertex> hasTag(String key) { GraphTraversal traversal = this.clone().V(); traversal = traversal.has(key); return traversal; }
Example 20
Source File: TraceTraversalSourceDsl.java From jaeger-analytics-java with Apache License 2.0 | 4 votes |
public GraphTraversal<Vertex, Vertex> hasName(String name) { GraphTraversal traversal = this.clone().V(); traversal = traversal.has(Keys.OPERATION_NAME, name); return (TraceTraversal<Vertex, Vertex>) traversal; }