GremlinPipeline<Vertex, String> pipe = new GremlinPipeline<Vertex, String>(); pipe.setStarts(users); pipe.out(EdgeType.USEREVENT).out(). has(PropertyName.TYPE, VertexType.REPOSITORY). hasNot(PropertyName.FULLNAME, "/").dedup(). property(PropertyName.FULLNAME). fill(childRepositories); pipe = new GremlinPipeline<Vertex, String>(); pipe.out(EdgeType.REPOWATCHED).dedup(). property(PropertyName.FULLNAME).fill(childRepositories);
@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(); }
public double getNodeInDegree(Vertex vertex) { GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).in(SIMILAR); return (double) pipe.count(); }
@Override public int getNodeCount() { long nodeCount = new GremlinPipeline<Object, Object>(titanGraph).V().count(); return (int) nodeCount; }
protected Pipe getQueryPipe() { return new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY). hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy"); } }
public Set<Vertex> getAllRepositoryUsers(final Vertex repo) { Set<Object> users = new HashSet<Object>(); GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); userList = pipe.start(repo).in(EdgeType.REPOCOLLABORATOR).toList(); log.info("Collaboators: {}", userList.size()); users.addAll(userList); pipe = new GremlinPipeline<Vertex, Vertex>(); userList = pipe.start(repo).in(EdgeType.REPOWATCHED).toList(); log.info("Watchers: {}", userList.size()); users.addAll(userList); pipe = new GremlinPipeline<Vertex, Vertex>(); userList = pipe.start(repo).out(EdgeType.ISSUE).in(EdgeType.ISSUEOWNER).dedup().toList(); log.info("Issue owners: {}", userList.size()); users.addAll(userList); pipe = new GremlinPipeline<Vertex, Vertex>(); userList = pipe.start(repo).out(EdgeType.ISSUE).out(EdgeType.ISSUECOMMENT).in(EdgeType.ISSUECOMMENTOWNER).dedup().toList(); log.info("Issue Comment owners: {}", userList.size()); users.addAll(userList); pipe = new GremlinPipeline<Vertex, Vertex>(); userList = pipe.start(repo).out(EdgeType.PULLREQUEST).in(EdgeType.PULLREQUESTOWNER).dedup().toList(); log.info("Pull Request owners: {}", userList.size()); users.addAll(userList); pipe = new GremlinPipeline<Vertex, Vertex>();
GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>(projectModel.asVertex()); pipeline.in(FileModel.FILE_TO_PROJECT_MODEL).in(InlineHintModel.FILE_MODEL); pipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE); pipeline.as("inlineHintVertex"); pipeline.out(InlineHintModel.FILE_LOCATION_REFERENCE).has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, JavaTypeReferenceModel.TYPE); pipeline.back("inlineHintVertex");
/** * Return a mapping between pull requests and the date they were augmented * with discussions. * * @param reponame * @return */ public Map<Integer, Date> getPullRequestDiscussionsAddedAt(final String reponame) { Vertex node = getOrCreateRepository(reponame); HashMap<Integer, Date> map = new HashMap<Integer, Date>(); GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); pipe.start(node).out(EdgeType.PULLREQUEST.toString()); addValuesFromIterable(pipe, map, PropertyName.NUMBER, PropertyName.SYS_DISCUSSIONS_ADDED); return map; }
@Override public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline) { pipeline.has(DoctypeMetaModel.PROPERTY_PUBLIC_ID, Text.REGEX, hibernateRegex); FramedGraphQuery systemIDQuery = event.getGraphContext().getQuery().type(DoctypeMetaModel.class) .has(DoctypeMetaModel.PROPERTY_SYSTEM_ID, Text.REGEX, hibernateRegex); GremlinPipeline<Vertex, Vertex> systemIdPipeline = new GremlinPipeline<>(systemIDQuery.vertices()); pipeline.add(systemIdPipeline); pipeline.dedup(); } };
@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(); }
@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; } }
@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; }
/** * Add an arbitrary Pipe to the end of the pipeline. * * @param pipe The provided pipe. * @param <T> the object type emitted by the provided pipe. * @return the extended Pipeline */ public <T> GremlinPipeline<S, T> step(final Pipe<E, T> pipe) { return this.add(pipe); }
@Override public void query(GraphRewrite event, GremlinPipeline<Vertex, Vertex> pipeline) { Predicate regexPredicate = new Predicate() { @Override public boolean evaluate(Object first, Object second) { return ((String) first).matches((String) second); } }; pipeline.as("result") .out(FileReferenceModel.FILE_MODEL) .out(JavaSourceFileModel.JAVA_CLASS_MODEL) .has(JavaClassModel.QUALIFIED_NAME, regexPredicate, compiledTypeFilterPattern.pattern()) .back("result"); } }
public double getNodeOutDegree(Vertex vertex) { GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).out(SIMILAR); return (double) pipe.count(); }
@Override public Boolean compute(Object vertices) { GremlinPipeline p = new GremlinPipeline(Collections.singleton(vertices)); p.add(excludePipeline); return p.gather().toList().isEmpty(); } }
@Test public void testSingleTxDeepTraversals() throws Exception { //1) Write random graph (copied from above) final int numV = 5000; final int numE = 50; final String label = "knows"; final Random random = new Random(); final long[] vids = writeGraph(numV, numE, label); final int repetitions = 1000; long start = System.currentTimeMillis(); TitanTransaction tx = graph.buildTransaction().readOnly().start(); for (int r = 0; r < repetitions; r++) { TitanVertex v = tx.getVertex(vids[random.nextInt(numV)]); assertTrue((int) Math.pow(numE, 2) <= Iterables.size( new GremlinPipeline<Vertex, Vertex>(v) .both(label).both(label) )); assertEquals((int) Math.pow(numE, 2), Iterables.size( new GremlinPipeline<Vertex, Vertex>(v) .out(label).out(label) )); } tx.commit(); System.out.println("Time in ms for [" + (repetitions) + "] traversals in single tx: " + (System.currentTimeMillis() - start)); }
@Override protected Pipe getQueryPipe() { return new GremlinPipeline().has("__typeName", "Taxonomy"); } }
/** * Start a gremlin pipeline * * @param starts * @return Start a gremlin pipeline at an element */ public <E> GremlinPipeline<C, E> gremlin(Object starts) { return new GremlinPipeline<C, E>(starts); }