Search in sources :

Example 1 with MedianVertexProgram

use of ai.grakn.graql.internal.analytics.MedianVertexProgram in project grakn by graknlabs.

the class TinkerComputeQueryRunner method run.

public ComputeJob<Optional<Number>> run(MedianQuery query) {
    return runStatistics(query, tinkerComputeQuery -> {
        AttributeType.DataType<?> dataType = tinkerComputeQuery.getDataTypeOfSelectedResourceTypes();
        if (!tinkerComputeQuery.selectedResourceTypesHaveInstance()) {
            return Optional.empty();
        }
        Set<LabelId> allSubLabelIds = convertLabelsToIds(tinkerComputeQuery.getCombinedSubTypes());
        Set<LabelId> statisticsResourceLabelIds = convertLabelsToIds(tinkerComputeQuery.statisticsResourceLabels());
        ComputerResult result = tinkerComputeQuery.compute(new MedianVertexProgram(statisticsResourceLabelIds, dataType), null, allSubLabelIds);
        Number finalResult = result.memory().get(MedianVertexProgram.MEDIAN);
        LOG.debug("Median = " + finalResult);
        return Optional.of(finalResult);
    });
}
Also used : AttributeType(ai.grakn.concept.AttributeType) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) LabelId(ai.grakn.concept.LabelId) MedianVertexProgram(ai.grakn.graql.internal.analytics.MedianVertexProgram)

Aggregations

AttributeType (ai.grakn.concept.AttributeType)1 LabelId (ai.grakn.concept.LabelId)1 MedianVertexProgram (ai.grakn.graql.internal.analytics.MedianVertexProgram)1 ComputerResult (org.apache.tinkerpop.gremlin.process.computer.ComputerResult)1