com.tinkerpop.pipes.PipeFunction Java Examples
The following examples show how to use
com.tinkerpop.pipes.PipeFunction.
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: SelectPipe.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public SelectPipe(final Collection<String> stepNames, final List<AsPipe> allPreviousAsPipes, final PipeFunction... stepFunctions) { this.stepFunctions = stepFunctions; this.stepNames = stepNames; if (this.doFunctions = this.stepFunctions.length > 0) currentFunction = 0; final List<String> tempNames = new ArrayList<String>(); for (final AsPipe asPipe : allPreviousAsPipes) { final String columnName = asPipe.getName(); if (null == this.stepNames || this.stepNames.contains(columnName)) { tempNames.add(columnName); this.asPipes.add(asPipe); } } if (tempNames.size() > 0) this.columnNames = tempNames; else this.columnNames = null; }
Example #2
Source File: TraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add an IfThenElsePipe to the end of the Pipeline. If the ifFunction is true, * then the results of the thenFunction are emitted. If the ifFunction is false, * then the results of the elseFunction are emitted. * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Then Stream or Else Stream * * Path: Map<Object, * * @param ifFunction * the function denoting the "if" part of the pipe * @param thenFunction * the function denoting the "then" part of the pipe * @param elseFunction * the function denoting the "else" part of the pipe * @return the extended Pipeline */ public TraversalEngine ifThenElse(final PipeFunction ifFunction, final PipeFunction thenFunction, final PipeFunction elseFunction) { // Pipeline Update if (isPathEnabled) { // Get Sub-Path Map intermediate = (Map) stream.map(element -> { if ((boolean) ifFunction.compute(element)) { return new AbstractMap.SimpleImmutableEntry(element, thenFunction.compute(element)); } else { return new AbstractMap.SimpleImmutableEntry(element, elseFunction.compute(element)); } }).collect(Collectors.toMap(e -> ((Entry) e).getKey(), e -> ((Entry) e).getValue())); // Update Path updateTransformationPath(intermediate); // Make stream again stream = getStream(intermediate, isParallel); } else { stream = stream.flatMap(element -> { if ((boolean) ifFunction.compute(element)) { return makeStream(thenFunction.compute(element), isParallel); } else { return makeStream(elseFunction.compute(element), isParallel); } }); } // Step Update final Class[] args = new Class[3]; args[0] = PipeFunction.class; args[1] = PipeFunction.class; args[2] = PipeFunction.class; final Step step = new Step(this.getClass().getName(), "ifThenElse", args, ifFunction, thenFunction, elseFunction); stepList.add(step); return this; }
Example #3
Source File: OrderMapPipe.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public S processNextStart() { while (true) { if (!this.pipe.hasNext()) this.pipe = new PipesPipeline(this.starts.next().entrySet()).order(this.compareFunction).transform(new PipeFunction<Map.Entry, Object>() { public Object compute(final Map.Entry entry) { return entry.getKey(); } }); else return (S) this.pipe.next(); } }
Example #4
Source File: Table.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public Table apply(final PipeFunction... functions) { Table table = new Table(); for (final Row row : this) { List temp = new ArrayList(); for (int i = 0; i < row.size(); i++) { temp.add(functions[i % functions.length].compute(row.get(i))); } table.addRow(temp); } return table; }
Example #5
Source File: NaiveTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add a TransformFunctionPipe to the end of the Pipeline. Given an input, the * provided function is computed on the input and the output of that function is * emitted. * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Transformed Stream * * Path: Map<Object, TransformedObject> * * @param function * the transformation function of the pipe * @return the extended Pipeline */ public NaiveTraversalEngine transform(final PipeFunction function, final Class outputClass) { // Pipeline Update if (isPathEnabled) { // Get Sub-Path Map intermediate = (Map) stream.map(e -> { return new AbstractMap.SimpleImmutableEntry(e, function.compute(e)); }).collect(Collectors.toMap(e -> ((Entry) e).getKey(), e -> ((Entry) e).getValue())); // Update Path if (elementClass != List.class) updateTransformationPath(intermediate); // Make stream again stream = getStream(intermediate, isParallel); } else { stream = stream.map(e -> { return function.compute(e); }); } // Step Update final Class[] args = new Class[2]; args[0] = PipeFunction.class; args[1] = Class.class; final Step step = new Step(this.getClass().getName(), "transform", args, function, outputClass); stepList.add(step); // Set Class elementClass = outputClass; return this; }
Example #6
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 #7
Source File: NaiveTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add an FilterFunctionPipe to the end of the Pipeline. The serves are an * arbitrary filter where the filter criteria is provided by the filterFunction. * * Identical semantic with Java Parallelism filter * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Filtered Stream * * Path: Map<DeduplicationHolder, Filtered Set<Object>> * * @param filterFunction * the filter function of the pipe * @return the extended Pipeline */ public NaiveTraversalEngine filter(final PipeFunction filterFunction) { // Pipeline Update if (isPathEnabled) { List intermediate = (List) stream.filter(e -> (boolean) filterFunction.compute(e)) .collect(Collectors.toList()); // Update Path ( Filter if any last elements of each path are not // included in intermediate ) // currentPath.keySet().retainAll(intermediate); // Make stream again if (isParallel) stream = intermediate.parallelStream(); else stream = intermediate.stream(); } else { stream = stream.filter(e -> (boolean) filterFunction.compute(e)); } // Step Update final Class[] args = new Class[1]; args[0] = PipeFunction.class; final Step step = new Step(this.getClass().getName(), "filter", args, filterFunction); stepList.add(step); return this; }
Example #8
Source File: ExternalTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add an FilterFunctionPipe to the end of the Pipeline. The serves are an * arbitrary filter where the filter criteria is provided by the filterFunction. * * Identical semantic with Java Parallelism filter * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Filtered Stream * * Path: Map<DeduplicationHolder, Filtered Set<Object>> * * @param filterFunction * the filter function of the pipe * @return the extended Pipeline */ public ExternalTraversalEngine filter(final PipeFunction filterFunction) { // Pipeline Update if (isPathEnabled) { List intermediate = (List) stream.filter(e -> (boolean) filterFunction.compute(e)) .collect(Collectors.toList()); // Update Path ( Filter if any last elements of each path are not // included in intermediate ) // currentPath.keySet().retainAll(intermediate); // Make stream again if (isParallel) stream = intermediate.parallelStream(); else stream = intermediate.stream(); } else { stream = stream.filter(e -> (boolean) filterFunction.compute(e)); } // Step Update final Class[] args = new Class[1]; args[0] = PipeFunction.class; final Step step = new Step(this.getClass().getName(), "filter", args, filterFunction); stepList.add(step); return this; }
Example #9
Source File: TraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add an FilterFunctionPipe to the end of the Pipeline. The serves are an * arbitrary filter where the filter criteria is provided by the filterFunction. * * Identical semantic with Java Parallelism filter * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Filtered Stream * * Path: Map<DeduplicationHolder, Filtered Set<Object>> * * @param filterFunction * the filter function of the pipe * @return the extended Pipeline */ public TraversalEngine filter(final PipeFunction filterFunction) { // Pipeline Update if (isPathEnabled) { List intermediate = (List) stream.filter(e -> (boolean) filterFunction.compute(e)) .collect(Collectors.toList()); // Update Path ( Filter if any last elements of each path are not // included in intermediate ) // currentPath.keySet().retainAll(intermediate); // Make stream again if (isParallel) stream = intermediate.parallelStream(); else stream = intermediate.stream(); } else { stream = stream.filter(e -> (boolean) filterFunction.compute(e)); } // Step Update final Class[] args = new Class[1]; args[0] = PipeFunction.class; final Step step = new Step(this.getClass().getName(), "filter", args, filterFunction); stepList.add(step); return this; }
Example #10
Source File: TraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add a TransformFunctionPipe to the end of the Pipeline. Given an input, the * provided function is computed on the input and the output of that function is * emitted. * * Path Enabled: Greedy * * Path Disabled: Lazy * * Pipeline: Stream -> Transformed Stream * * Path: Map<Object, TransformedObject> * * @param function * the transformation function of the pipe * @return the extended Pipeline */ public TraversalEngine transform(final PipeFunction function, final Class outputClass) { // Pipeline Update if (isPathEnabled) { // Get Sub-Path Map intermediate = (Map) stream.map(e -> { Object val = function.compute(e); if (val == null) return null; return new AbstractMap.SimpleImmutableEntry(e, val); }).filter(e -> e != null).collect(Collectors.toMap(e -> ((Entry) e).getKey(), e -> ((Entry) e).getValue())); // Update Path if (elementClass != List.class) updateTransformationPath(intermediate); // Make stream again stream = getStream(intermediate, isParallel); } else { stream = stream.map(e -> { return function.compute(e); }); // stream = stream.flatMap(e -> { // return function.compute(e); // }); } // Step Update final Class[] args = new Class[2]; args[0] = PipeFunction.class; args[1] = Class.class; final Step step = new Step(this.getClass().getName(), "transform", args, function, outputClass); stepList.add(step); // Set Class elementClass = outputClass; return this; }
Example #11
Source File: TraitRelation.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public Pipe asPipe() { return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() { @Override public Boolean compute(Edge edge) { String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); if (edge.getLabel().startsWith(name)) { VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN)); return ! v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex()); } else { return false; } } }); }
Example #12
Source File: OrderMapPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public OrderMapPipe(final PipeFunction<Pair<Map.Entry<S, ?>, Map.Entry<S, ?>>, Integer> compareFunction) { this.compareFunction = compareFunction; }
Example #13
Source File: AggregationTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() { ChronoGraph g = new ChronoGraph("epcis"); // g.getChronoVertexSet().parallelStream().forEach(v -> System.out.println(v)); BsonArray contains = new BsonArray(); contains.add(new BsonString("contains")); // 각 중요시간 마다 트럭 안에 있는 물건들의 리스트와 무게를 가져옴 Iterator<Long> timeSet = g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001") .getTimestamps(Direction.OUT, contains, 0l, AC.$gt).iterator(); while (timeSet.hasNext()) { Long t = timeSet.next(); System.out.println("at " + new Date(t)); AtomicDouble totalK = new AtomicDouble(); ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); PipeFunction<EdgeEvent, Boolean> retainIfAdd = new PipeFunction<EdgeEvent, Boolean>() { @Override public Boolean compute(EdgeEvent ee) { if (ee.getProperty("action").equals(new BsonString("ADD"))) { return true; } return false; } }; PipeFunction<VertexEvent, Object> listUpFreight = new PipeFunction<VertexEvent, Object>() { @Override public Object compute(VertexEvent ve) { BsonDouble kg = (BsonDouble) ve.getVertex().getProperty("urn:epc:cbv:mda:netWeight"); totalK.addAndGet(kg.doubleValue()); map.put(ve.getVertex().toString(), "1"); return ve; } }; TraversalEngine engine = new TraversalEngine(g, g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001").setTimestamp(t), false, false, VertexEvent.class); engine.outEe(contains, TemporalType.TIMESTAMP, AC.$lte, null, null, null, null, null, null) .filter(retainIfAdd).inVe().sideEffect(listUpFreight).toList(); // g.getChronoVertex("urn:epc:id:sscc:0000001.0000000001").getChronoEdgeSet(Direction.OUT, // contains) // .parallelStream().forEach(e -> { // // System.out.println(e); // // EdgeEvent ee = e.pickFloorTimestamp(t); // if (ee != null && ee.getProperty("action").equals(new BsonString("ADD"))) { // BsonDouble kg = (BsonDouble) // e.getInVertex().getProperty("urn:epc:cbv:mda:netWeight"); // totalK.addAndGet(kg.doubleValue()); // map.put(e.getInVertex().toString(), "1"); // } // }); System.out.println(map.keySet()); System.out.println(totalK); } g.shutdown(); }
Example #14
Source File: PersistentBreadthFirstSearchEmulation.java From epcis with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") public Map compute(String epc, Long startTime, AC tt) { // order = forward / backward EPCTime source = new EPCTime(epc, startTime); gamma.put(epc, startTime); PipeFunction<EPCTime, Boolean> exceedBound2 = new PipeFunction<EPCTime, Boolean>() { @Override public Boolean compute(EPCTime ve) { if (gamma.containsKey(ve.epc) && (ve.time >= gamma.get(ve.epc))) { return false; } return true; } }; PipeFunction<List<EPCTime>, Object> storeGamma = new PipeFunction<List<EPCTime>, Object>() { @Override public Object compute(List<EPCTime> vertexEvents) { vertexEvents.parallelStream().forEach(ve -> { gamma.put(ve.epc, ve.time); }); return null; } }; LoopPipeFunction exitIfEmptyIterator = new LoopPipeFunction() { @Override public boolean compute(Object argument, Map<Object, Object> currentPath, int loopCount) { List list = (List) argument; // System.out.println(list.size()); if (list == null || list.size() == 0) return false; return true; } }; // Event Collection MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("EventData", BsonDocument.class); // input이 epc 이고 시간이 그 뒤인 output 들과 그 시간을 가져온다 // collection.find() NaiveTraversalEngine pipeLine = new NaiveTraversalEngine(collection, source, true, true, EPCTime.class); pipeLine = pipeLine.as("s"); pipeLine = pipeLine.scatter(); pipeLine = pipeLine.oute(null, TemporalType.TIMESTAMP, tt, null, null, null, null, null, null, Position.first); pipeLine = pipeLine.filter(exceedBound2); pipeLine = pipeLine.gather(); // 방문한 버텍스 중 최소만을 꼽는다 해당 스텝에서 도달 한 것 중 pipeLine = pipeLine.elementDedup(FC.$min); // lower bound 보다 크면 필터한다. // lower bound 가 없는 것은 무한대 // pipeLine = pipeLine.transform(exceedBound, List.class); pipeLine = pipeLine.sideEffect(storeGamma); // pipeLine = pipeLine.pathEnabledTransform(historyPipe, List.class); // pipeLine.storeTimestamp(bound); // pipeLine.pathFilter(bound, ); // pipeLine = pipeLine.sideEffect(storeCurrentVertexEvents); pipeLine = pipeLine.loop("s", exitIfEmptyIterator); return pipeLine.path(); }
Example #15
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public <T> PipesPipeline<S, T> transform(final PipeFunction<E, T> function) { return this.add(new TransformFunctionPipe(FluentUtility.prepareFunction(this.asMap, function))); }
Example #16
Source File: FilterFunctionPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public FilterFunctionPipe(final PipeFunction<S, Boolean> filterFunction) { this.filterFunction = filterFunction; }
Example #17
Source File: OrderPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipeFunctionComparator(final PipeFunction<Pair<S, S>, Integer> pipeFunction) { this.pipeFunction = pipeFunction; }
Example #18
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, E> sideEffect(final PipeFunction<E, ?> sideEffectFunction) { return this.add(new SideEffectFunctionPipe<E>(FluentUtility.prepareFunction(this.asMap, sideEffectFunction))); }
Example #19
Source File: GroupByPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public GroupByPipe(final Map<K, Collection<V>> byMap, final PipeFunction<S, K> keyFunction, final PipeFunction<S, V> valueFunction) { this.byMap = byMap; this.keyFunction = keyFunction; this.valueFunction = valueFunction; }
Example #20
Source File: TreePipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public TreePipe(final Tree tree, final PipeFunction... branchFunctions) { this(branchFunctions); this.tree = tree; }
Example #21
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, ?> ifThenElse(final PipeFunction<E, Boolean> ifFunction, final PipeFunction<E, ?> thenFunction, final PipeFunction<E, ?> elseFunction) { return this.add(new IfThenElsePipe(FluentUtility.prepareFunction(this.asMap, ifFunction), FluentUtility.prepareFunction(this.asMap, thenFunction), FluentUtility.prepareFunction(this.asMap, elseFunction))); }
Example #22
Source File: GroupByReducePipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public GroupByReducePipe(final Map<K, V2> reduceMap, final PipeFunction<S, K> keyFunction, final PipeFunction<S, V> valueFunction, final PipeFunction<Collection<V>, V2> reduceFunction) { super(new HashMap<K, Collection<V>>(), keyFunction, valueFunction); this.reduceMap = reduceMap; this.reduceFunction = reduceFunction; }
Example #23
Source File: GroupCountFunctionPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public GroupCountFunctionPipe(final PipeFunction<S, K> keyFunction, final PipeFunction<Pair<S, Number>, Number> valueFunction) { this(new HashMap<K, Number>(), keyFunction, valueFunction); }
Example #24
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, E> dedup(final PipeFunction<E, ?> dedupFunction) { return this.add(new DuplicateFilterPipe<E>(FluentUtility.prepareFunction(this.asMap, dedupFunction))); }
Example #25
Source File: IfThenElsePipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public IfThenElsePipe(final PipeFunction<S, Boolean> ifFunction, final PipeFunction<S, ?> thenFunction, final PipeFunction<S, ?> elseFunction) { this.ifFunction = ifFunction; this.thenFunction = thenFunction; this.elseFunction = elseFunction; }
Example #26
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, E> loop(final int numberedStep, final PipeFunction<LoopPipe.LoopBundle<E>, Boolean> whileFunction) { return this.add(new LoopPipe(new Pipeline(FluentUtility.removePreviousPipes(this, numberedStep)), FluentUtility.prepareFunction(this.asMap, whileFunction))); }
Example #27
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, List> path(final PipeFunction... pathFunctions) { return this.add(new PathPipe<Object>(FluentUtility.prepareFunctions(this.asMap, pathFunctions))); }
Example #28
Source File: GroupByPipe.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public GroupByPipe(final PipeFunction<S, K> keyFunction, final PipeFunction<S, V> valueFunction) { this(new HashMap<K, Collection<V>>(), keyFunction, valueFunction); }
Example #29
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, E> table(final PipeFunction... columnFunctions) { return this.add(new TablePipe<E>(new Table(), null, FluentUtility.getAsPipes(this), FluentUtility.prepareFunctions(this.asMap, columnFunctions))); }
Example #30
Source File: PipesPipeline.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public PipesPipeline<S, E> tree(final PipeFunction... branchFunctions) { return this.add(new TreePipe<E>(FluentUtility.prepareFunctions(this.asMap, branchFunctions))); }