com.tinkerpop.gremlin.java.GremlinPipeline Java Examples
The following examples show how to use
com.tinkerpop.gremlin.java.GremlinPipeline.
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: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 6 votes |
@Override public Set<Integer> getCommunitiesConnectedToNodeCommunities(int nodeCommunities) { Set<Integer> communities = new HashSet<Integer>(); Iterable<Vertex> vertices = titanGraph.getVertices(NODE_COMMUNITY, nodeCommunities); for (Vertex vertex : vertices) { GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).out(SIMILAR); Iterator<Vertex> iter = pipe.iterator(); while (iter.hasNext()) { int community = iter.next().getProperty(COMMUNITY); communities.add(community); } } return communities; }
Example #2
Source File: TeacherStudentTraversal.java From secure-data-service with Apache License 2.0 | 6 votes |
void benchmarkTeacherThroughProgram() { logger.log(Level.INFO, "Starting..."); StopWatch bigWatch = new StopWatch(); for (int i = 0; i < ITERATIONS; ++i) { StopWatch subWatch = new StopWatch(); pipe = new GremlinPipeline(); long students = pipe .start(graph.getVertices("mongoid", "2012wo-a9d9e975-cfbb-11e1-a172-024224a39f1b").iterator() .next()).inE("staffProgram").outV().outE("staffCohort").inV().count(); subWatch.stop(); logger.log(Level.INFO, "Found {0} students", "" + students); times.add(subWatch.getEndTime()); } bigWatch.stop(); logger.log(Level.INFO, "Total {0} \t Avg {1} ms", new String[] { bigWatch.inSeconds(), "" + averageTime() }); }
Example #3
Source File: TeacherStudentTraversal.java From secure-data-service with Apache License 2.0 | 6 votes |
void benchmarkTeacherThroughCohort() { logger.log(Level.INFO, "Starting..."); StopWatch bigWatch = new StopWatch(); for (int i = 0; i < ITERATIONS; ++i) { StopWatch subWatch = new StopWatch(); pipe = new GremlinPipeline(); long students = pipe .start(graph.getVertices("mongoid", "2012zc-a9b37634-cfbb-11e1-a172-024224a39f1b").iterator() .next()).inE("staffCohort").count(); subWatch.stop(); logger.log(Level.INFO, "Found {0} students", "" + students); times.add(subWatch.getEndTime()); } bigWatch.stop(); logger.log(Level.INFO, "Total {0} \t Avg {1} ms", new String[] { bigWatch.inSeconds(), "" + averageTime() }); }
Example #4
Source File: TeacherStudentTraversal.java From secure-data-service with Apache License 2.0 | 6 votes |
void benchmarkTeacherThroughSection() { logger.log(Level.INFO, "Starting..."); StopWatch bigWatch = new StopWatch(); for (int i = 0; i < ITERATIONS; ++i) { StopWatch subWatch = new StopWatch(); pipe = new GremlinPipeline(); long students = pipe .start(graph.getVertices("mongoid", "2012wl-f126bd7d-cfba-11e1-a172-024224a39f1b").iterator() .next()).inE("teacherSection").outV().outE("studentSection").inV().count(); subWatch.stop(); logger.log(Level.INFO, "Found {0} students", "" + students); times.add(subWatch.getEndTime()); } bigWatch.stop(); logger.log(Level.INFO, "Total {0} \t Avg {1} ms", new String[] { bigWatch.inSeconds(), "" + averageTime() }); }
Example #5
Source File: AtlasEntityQueryTest.java From incubator-atlas with Apache License 2.0 | 6 votes |
public TestAtlasEntityQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, Request request, GremlinPipeline initialPipeline, Pipe queryPipe, Pipe notDeletedPipe, AtlasGraph graph, VertexWrapper vWrapper) { super(queryExpression, resourceDefinition, request); this.initialPipeline = initialPipeline; this.queryPipe = queryPipe; this.notDeletedPipe = notDeletedPipe; this.graph = graph; this.vWrapper = vWrapper; }
Example #6
Source File: Instruction.java From bjoern with GNU General Public License v3.0 | 6 votes |
public GremlinPipeline<?, Instruction> exits() { final int MAX_LOOPS = 10000; final String[] EDGES = {Traversals.INSTR_CFLOW_EDGE, Traversals.INSTR_CFLOW_TRANSITIVE_EDGE}; if (!this.getVertices(Direction.OUT, EDGES).iterator().hasNext()) { return new GremlinPipeline<>(this); } else { return new GremlinPipeline<>(this.getBaseVertex()).as("start") .out(EDGES).dedup().loop("start", arg -> arg.getLoops() < MAX_LOOPS, arg -> arg.getLoops() < MAX_LOOPS && !arg.getObject().getEdges(Direction.OUT, EDGES).iterator().hasNext()) .dedup() .transform(Instruction::new); } }
Example #7
Source File: AtlasEntityTagQuery.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override protected Pipe getQueryPipe() { GremlinPipeline p; if (guid.equals("*")) { p = new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY). hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy").outE(); } else { p = new GremlinPipeline().has(Constants.GUID_PROPERTY_KEY, guid).outE(); } //todo: this is basically the same pipeline used in TagRelation.asPipe() p.add(new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() { @Override public Boolean compute(Edge edge) { String type = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN)); return edge.getLabel().startsWith(type) && v.getPropertyKeys().contains("available_as_tag"); } })); return p.inV(); }
Example #8
Source File: DataDependencePlugin.java From bjoern with GNU General Public License v3.0 | 6 votes |
public static Set<ReachingDefinitionAnalyser.Definition> killedDefinitions( final Vertex vertex) { Set<ReachingDefinitionAnalyser.Definition> killSet = new HashSet<>(); GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<>(); pipe.start(vertex) .out("WRITE") .out("BELONGS_TO") .in("BELONGS_TO") .inE("WRITE"); for (Edge writeEdge : pipe) { Vertex genVertex = writeEdge.getVertex(Direction.OUT); Vertex aloc = writeEdge.getVertex(Direction.IN); GremlinPipeline<Vertex, Object> pipe2 = new GremlinPipeline<>(); pipe2.start(aloc) .out("BELONGS_TO") .in("BELONGS_TO") .property("name"); for (Object identifier : pipe2) { killSet.add(new ReachingDefinitionAnalyser.Definition( genVertex, identifier)); } } return killSet; }
Example #9
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 5 votes |
public static List<Instruction> functionToInstructions(Function func) { GremlinPipeline<Function, Instruction> pipe = new GremlinPipeline<>(); pipe.start(func).out(EdgeTypes.IS_FUNCTION_OF).out(EdgeTypes.IS_BB_OF); return pipe.toList(); }
Example #10
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 5 votes |
@Override public Set<Integer> getNeighborsIds(int nodeId) { Set<Integer> neighbors = new HashSet<Integer>(); Vertex vertex = titanGraph.getVertices(NODE_ID, nodeId).iterator().next(); GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).out(SIMILAR); Iterator<Vertex> iter = pipe.iterator(); while (iter.hasNext()) { Integer neighborId = iter.next().getProperty(NODE_ID); neighbors.add(neighborId); } return neighbors; }
Example #11
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 5 votes |
@Override public void shortestPath(final Vertex fromNode, Integer node) { final Vertex v2 = titanGraph.getVertices(NODE_ID, node).iterator().next(); @SuppressWarnings("rawtypes") final GremlinPipeline<String, List> pathPipe = new GremlinPipeline<String, List>(fromNode).as(SIMILAR) .out(SIMILAR).loop(SIMILAR, new PipeFunction<LoopBundle<Vertex>, Boolean>() { // @Override public Boolean compute(LoopBundle<Vertex> bundle) { return bundle.getLoops() < 5 && !bundle.getObject().equals(v2); } }).path(); }
Example #12
Source File: AtlasTermQuery.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override protected Pipe getQueryPipe() { GremlinPipeline p; if (termPath.getTaxonomyName().equals("*")) { p = new GremlinPipeline().has("Taxonomy.name").out(); } else { p = new GremlinPipeline().has("Taxonomy.name", termPath.getTaxonomyName()).out(). has(Constants.ENTITY_TYPE_PROPERTY_KEY, Text.PREFIX, termPath.getFullyQualifiedName()); } return p; }
Example #13
Source File: BaseQuery.java From incubator-atlas with Apache License 2.0 | 5 votes |
protected GremlinPipeline buildPipeline() { GremlinPipeline pipeline = getRootVertexPipeline(); Pipe queryPipe = getQueryPipe(); if (queryPipe != null) { pipeline.add(queryPipe); } pipeline.add(getNotDeletedPipe()); return pipeline; }
Example #14
Source File: BaseQuery.java From incubator-atlas with Apache License 2.0 | 5 votes |
private List<Vertex> executeQuery() { GremlinPipeline pipeline = buildPipeline().as("root"); Pipe expressionPipe = queryExpression.asPipe(); // AlwaysQuery returns null for pipe return expressionPipe == null ? pipeline.toList() : pipeline.add(expressionPipe).back("root").toList(); }
Example #15
Source File: ProjectionQueryExpression.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public Pipe asPipe() { //todo: encapsulate all of this path logic including path sep escaping and normalizing final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN); final String edgeToken = getField().substring(0, sepIdx); GremlinPipeline pipeline = new GremlinPipeline(); Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]); if (relation != null) { pipeline = pipeline.outE(); pipeline.add(relation.asPipe()).inV(); } else { if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) { return super.asPipe(); } else { //todo: default Relation implementation pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV(); } } //todo: set resource definition from relation on underlying expression where appropriate String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length()); underlyingExpression.setField(childFieldName); Pipe childPipe; if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) { childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe(); } else { childPipe = underlyingExpression.asPipe(); } pipeline.add(childPipe); return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline; }
Example #16
Source File: FunctionExportPlugin.java From bjoern with GNU General Public License v3.0 | 5 votes |
private void copyFunctionEdges(Graph graph, Vertex functionRoot) { GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<>(); pipe.start(functionRoot).as("loop") .out(EdgeTypes.IS_FUNCTION_OF, EdgeTypes.IS_BB_OF, EdgeTypes.READ, EdgeTypes.WRITE) .loop("loop", v -> true, v -> Arrays.asList(nodes) .contains(v.getObject().getProperty(BjoernNodeProperties.TYPE).toString())) .outE(edges); for (Edge e : pipe) { copyEdge(graph, e); } }
Example #17
Source File: ReachingDefinitionAnalyser.java From bjoern with GNU General Public License v3.0 | 5 votes |
private LinkedList<Vertex> getAllNodes(Vertex entry) { LinkedList<Vertex> worklist = new LinkedList<>(); GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<>(); pipe.start(entry) .as("loop") .out(CFLOW_LABEL) .dedup() .simplePath() .loop("loop", argument -> true, argument -> true); for (Vertex vertex : pipe) { worklist.add(vertex); } return worklist; }
Example #18
Source File: DataDependencePlugin.java From bjoern with GNU General Public License v3.0 | 5 votes |
public static Set<ReachingDefinitionAnalyser.Definition> generatedDefinitions( final Vertex vertex) { Set<ReachingDefinitionAnalyser.Definition> genSet = new HashSet<>(); GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<>(); pipe.start(vertex) .out("WRITE") .out("BELONGS_TO") .in("BELONGS_TO"); for (Vertex register : pipe) { String registerName = register.getProperty("name"); genSet.add(new ReachingDefinitionAnalyser.Definition(vertex, registerName)); } return genSet; }
Example #19
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 5 votes |
public static BasicBlock functionToEntryBlock(Vertex func) { GremlinPipeline<Vertex, Vertex> pipe = createNewGremlinPipe(); pipe.start(func).in(EdgeTypes.INTERPRETATION).out(EdgeTypes.INTERPRETATION).filter( v -> v.getProperty(BjoernNodeProperties.TYPE).equals (BjoernNodeTypes.BASIC_BLOCK) ); Vertex vertex = getFirstVertexFromPipeOrRaise(pipe); return new BasicBlock(vertex); }
Example #20
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 5 votes |
private static Vertex getFirstVertexFromPipeOrRaise(GremlinPipeline<Vertex, Vertex> pipe) { if (!pipe.hasNext()) throw new RuntimeException("Empty pipeline"); Vertex vertex = pipe.next(); if (vertex == null) throw new RuntimeException("Empty pipeline"); return vertex; }
Example #21
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 5 votes |
public static Instruction functionToEntryInstruction(Function function) { GremlinPipeline<Function, Instruction> pipeline = new GremlinPipeline<>(); pipeline.start(function).in(EdgeTypes.INTERPRETATION).out(EdgeTypes.INTERPRETATION) .filter(v -> v.getProperty(BjoernNodeProperties.TYPE).equals(BjoernNodeTypes.INSTRUCTION)); if (pipeline.hasNext()) { return pipeline.next(); } else { return null; } }
Example #22
Source File: AtlasTaxonomyQuery.java From incubator-atlas with Apache License 2.0 | 4 votes |
@Override protected Pipe getQueryPipe() { return new GremlinPipeline().has("__typeName", "Taxonomy"); }
Example #23
Source File: JavaHandlerContextImpl.java From org.openntf.domino with Apache License 2.0 | 4 votes |
/** * @return A gremlin pipeline at the context element */ @Override public <E> GremlinPipeline<C, E> gremlin() { return new GremlinPipeline<C, E>(it()); }
Example #24
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
public double getNodeOutDegree(Vertex vertex) { GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).out(SIMILAR); return (double) pipe.count(); }
Example #25
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
public double getNodeInDegree(Vertex vertex) { GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).in(SIMILAR); return (double) pipe.count(); }
Example #26
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 4 votes |
private static GremlinPipeline<Vertex, Vertex> createNewGremlinPipe() { return new GremlinPipeline<>(); }
Example #27
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
@Override public int getNodeCount() { long nodeCount = new GremlinPipeline<Object, Object>(titanGraph).V().count(); return (int) nodeCount; }
Example #28
Source File: Traversals.java From bjoern with GNU General Public License v3.0 | 4 votes |
public static List<Aloc> functionToAlocs(Function function) { GremlinPipeline<Function, Aloc> pipe = new GremlinPipeline<>(); pipe.start(function).out(ALOC_USE_EDGE).dedup().cast(Aloc.class); return pipe.toList(); }
Example #29
Source File: BjoernNode.java From bjoern with GNU General Public License v3.0 | 4 votes |
public GremlinPipeline<BjoernNode, BjoernNode> start() { return new GremlinPipeline<>(this); }
Example #30
Source File: BaseTraversal.java From secure-data-service with Apache License 2.0 | 4 votes |
public BaseTraversal(DB mongo, OrientGraph graph) { this.mongo = mongo; this.graph = graph; pipe = new GremlinPipeline(); times = new ArrayList<Long>(); }