use of uk.gov.gchq.gaffer.doc.properties.generator.HllSketchElementGenerator in project gaffer-doc by gchq.
the class HllSketchWalkthrough method run.
@Override
public CloseableIterable<? extends Element> run() throws OperationException {
// / [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [add] addElements - add the edges to the graph
// ---------------------------------------------------------
final Set<String> dummyData = Collections.singleton("");
final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new HllSketchElementGenerator()).input(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
print("Added 1000 entities for vertex A, each time with a HllSketch containing a vertex that A was seen in an edge with");
// [get] Get all entities
// ---------------------------------------------------------
CloseableIterable<? extends Element> allEntities = graph.execute(new GetAllElements(), user);
// ---------------------------------------------------------
print("\nAll edges:");
for (final Element entity : allEntities) {
print("GET_ALL_ENTITIES_RESULT", entity.toString());
}
// [get the approximate degree of a] Get the entity for A and print out the estimate of the degree
// ---------------------------------------------------------
final GetElements query = new GetElements.Builder().input(new EntitySeed("A")).build();
final Element element;
try (final CloseableIterable<? extends Element> elements = graph.execute(query, user)) {
element = elements.iterator().next();
}
final HllSketch hllSketch = (HllSketch) element.getProperty("approxCardinality");
final double approxDegree = hllSketch.getEstimate();
final String degreeEstimate = "Entity A has approximate degree " + approxDegree;
// ---------------------------------------------------------
print("\nEntity A with an estimate of its degree");
print("GET_APPROX_DEGREE_FOR_ENTITY_A", degreeEstimate);
return null;
}
Aggregations