use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.
the class AtlasEntityTagQuery method getQueryPipe.
@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();
}
use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.
the class EntityTagResourceDefinition method getTermProjection.
private Projection getTermProjection() {
return new Projection("term", Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {
@Override
public Collection<ProjectionResult> compute(VertexWrapper start) {
Map<String, Object> map = new TreeMap<>(new ResourceComparator());
StringBuilder sb = new StringBuilder();
sb.append("v1/taxonomies/");
String fullyQualifiedName = start.getVertex().getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
String[] paths = fullyQualifiedName.split("\\.");
// first path segment is the taxonomy
sb.append(paths[0]);
for (int i = 1; i < paths.length; ++i) {
String path = paths[i];
if (path != null && !path.isEmpty()) {
sb.append("/terms/");
sb.append(path);
}
}
map.put("href", sb.toString());
return Collections.singleton(new ProjectionResult("term", start, Collections.singleton(map)));
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.
the class TaxonomyResourceDefinition method getTermsProjection.
private Projection getTermsProjection() {
final String termsProjectionName = "terms";
return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {
private String baseHref = "v1/taxonomies/";
@Override
public Collection<ProjectionResult> compute(VertexWrapper v) {
Map<String, Object> map = new HashMap<>();
map.put("href", baseHref + v.getProperty("name") + "/terms");
return Collections.singleton(new ProjectionResult(termsProjectionName, v, Collections.singleton(map)));
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.
the class IfThenElseStepTest method test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name.
public void test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name() {
super.test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(new GremlinPipeline(g.getVertex(1)).out().ifThenElse(new PipeFunction<Vertex, Boolean>() {
public Boolean compute(Vertex vertex) {
return vertex.getProperty("lang") != null && vertex.getProperty("lang").equals("java");
}
}, new PipeFunction<Vertex, Vertex>() {
public Vertex compute(Vertex vertex) {
return vertex;
}
}, new PipeFunction<Vertex, Iterable<Vertex>>() {
public Iterable<Vertex> compute(Vertex vertex) {
return new GremlinPipeline(vertex).out();
}
}));
super.test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(new GremlinPipeline(g.getVertex(1)).optimize(false).out().ifThenElse(new PipeFunction<Vertex, Boolean>() {
public Boolean compute(Vertex vertex) {
return vertex.getProperty("lang") != null && vertex.getProperty("lang").equals("java");
}
}, new PipeFunction<Vertex, Vertex>() {
public Vertex compute(Vertex vertex) {
return vertex;
}
}, new PipeFunction<Vertex, Iterable<Vertex>>() {
public Iterable<Vertex> compute(Vertex vertex) {
return new GremlinPipeline(vertex).out();
}
}));
}
use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.
the class FilterStepTest method test_g_V_filterXtrueX.
public void test_g_V_filterXtrueX() {
super.test_g_V_filterXtrueX(new GremlinPipeline(g).V().filter(new PipeFunction<Vertex, Boolean>() {
public Boolean compute(Vertex vertex) {
return true;
}
}));
super.test_g_V_filterXtrueX(new GremlinPipeline(g.getVertices()).optimize(false).filter(new PipeFunction<Vertex, Boolean>() {
public Boolean compute(Vertex vertex) {
return true;
}
}));
}
Aggregations