Search in sources :

Example 1 with ClusterMemberMapReduce

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

the class TinkerComputeQueryRunner method run.

public <T> ComputeJob<T> run(ConnectedComponentQuery<T> query) {
    return runCompute(query, tinkerComputeQuery -> {
        if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
            LOG.info("Selected types don't have instances");
            return (T) Collections.emptyMap();
        }
        Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
        GraknVertexProgram<?> vertexProgram;
        if (query.sourceId().isPresent()) {
            ConceptId conceptId = query.sourceId().get();
            if (!tinkerComputeQuery.verticesExistInSubgraph(conceptId)) {
                throw GraqlQueryException.instanceDoesNotExist();
            }
            vertexProgram = new ConnectedComponentVertexProgram(conceptId);
        } else {
            vertexProgram = new ConnectedComponentsVertexProgram();
        }
        Long clusterSize = query.clusterSize();
        GraknMapReduce<?> mapReduce;
        if (query.isMembersSet()) {
            mapReduce = new ClusterMemberMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
        } else {
            mapReduce = new ClusterSizeMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
        }
        Memory memory = tinkerComputeQuery.compute(vertexProgram, mapReduce, subLabelIds).memory();
        return memory.get(mapReduce.getClass().getName());
    });
}
Also used : ConnectedComponentVertexProgram(ai.grakn.graql.internal.analytics.ConnectedComponentVertexProgram) Memory(org.apache.tinkerpop.gremlin.process.computer.Memory) ClusterSizeMapReduce(ai.grakn.graql.internal.analytics.ClusterSizeMapReduce) LabelId(ai.grakn.concept.LabelId) ConnectedComponentsVertexProgram(ai.grakn.graql.internal.analytics.ConnectedComponentsVertexProgram) ClusterMemberMapReduce(ai.grakn.graql.internal.analytics.ClusterMemberMapReduce) ConceptId(ai.grakn.concept.ConceptId)

Example 2 with ClusterMemberMapReduce

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

the class TinkerComputeQueryRunner method run.

public ComputeJob<Map<String, Set<String>>> run(KCoreQuery query) {
    return runCompute(query, tinkerComputeQuery -> {
        long k = query.kValue();
        if (k < 2L)
            throw GraqlQueryException.kValueSmallerThanTwo();
        if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
            return Collections.emptyMap();
        }
        ComputerResult result;
        Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
        try {
            result = tinkerComputeQuery.compute(new KCoreVertexProgram(k), new ClusterMemberMapReduce(KCoreVertexProgram.K_CORE_LABEL), subLabelIds);
        } catch (NoResultException e) {
            return Collections.emptyMap();
        }
        return result.memory().get(ClusterMemberMapReduce.class.getName());
    });
}
Also used : KCoreVertexProgram(ai.grakn.graql.internal.analytics.KCoreVertexProgram) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) LabelId(ai.grakn.concept.LabelId) NoResultException(ai.grakn.graql.internal.analytics.NoResultException) ClusterMemberMapReduce(ai.grakn.graql.internal.analytics.ClusterMemberMapReduce)

Aggregations

LabelId (ai.grakn.concept.LabelId)2 ClusterMemberMapReduce (ai.grakn.graql.internal.analytics.ClusterMemberMapReduce)2 ConceptId (ai.grakn.concept.ConceptId)1 ClusterSizeMapReduce (ai.grakn.graql.internal.analytics.ClusterSizeMapReduce)1 ConnectedComponentVertexProgram (ai.grakn.graql.internal.analytics.ConnectedComponentVertexProgram)1 ConnectedComponentsVertexProgram (ai.grakn.graql.internal.analytics.ConnectedComponentsVertexProgram)1 KCoreVertexProgram (ai.grakn.graql.internal.analytics.KCoreVertexProgram)1 NoResultException (ai.grakn.graql.internal.analytics.NoResultException)1 ComputerResult (org.apache.tinkerpop.gremlin.process.computer.ComputerResult)1 Memory (org.apache.tinkerpop.gremlin.process.computer.Memory)1