Search in sources :

Example 41 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class HasAttributeTypeProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    // NB: HasResourceType is a special case and it doesn't allow variables as resource types
    Var varName = var.var().asUserDefined();
    Label label = this.resourceType().getTypeLabel().orElse(null);
    Var predicateVar = var().asUserDefined();
    SchemaConcept schemaConcept = parent.tx().getSchemaConcept(label);
    ConceptId predicateId = schemaConcept != null ? schemaConcept.getId() : null;
    // isa part
    VarPatternAdmin resVar = varName.has(Graql.label(label)).admin();
    return HasAtom.create(resVar, predicateVar, predicateId, parent);
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) ConceptId(ai.grakn.concept.ConceptId)

Example 42 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class ConceptPropertyTest method whenCallingGetId_TheResultCanBeUsedToRetrieveTheSameConcept.

@Property
public void whenCallingGetId_TheResultCanBeUsedToRetrieveTheSameConcept(@Open GraknTx graph, @FromTx Concept concept) {
    ConceptId id = concept.getId();
    assertEquals(concept, graph.getConcept(id));
}
Also used : ConceptId(ai.grakn.concept.ConceptId) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 43 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class GraknTxPropertyTest method whenCallingGetConceptWithAnExistingConceptId_ItReturnsThatConcept.

@Property
public void whenCallingGetConceptWithAnExistingConceptId_ItReturnsThatConcept(@Open GraknTx graph, @FromTx Concept concept) {
    ConceptId id = concept.getId();
    assertEquals(concept, graph.getConcept(id));
}
Also used : ConceptId(ai.grakn.concept.ConceptId) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 44 with ConceptId

use of ai.grakn.concept.ConceptId 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 45 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class TinkerComputeQueryRunner method run.

public TinkerComputeJob<List<List<Concept>>> run(PathsQuery query) {
    return runCompute(query, tinkerComputeQuery -> {
        ConceptId sourceId = query.from();
        ConceptId destinationId = query.to();
        if (!tinkerComputeQuery.verticesExistInSubgraph(sourceId, destinationId)) {
            throw GraqlQueryException.instanceDoesNotExist();
        }
        if (sourceId.equals(destinationId)) {
            return Collections.singletonList(Collections.singletonList(tx.getConcept(sourceId)));
        }
        ComputerResult result;
        Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
        try {
            result = tinkerComputeQuery.compute(new ShortestPathVertexProgram(sourceId, destinationId), null, subLabelIds);
        } catch (NoResultException e) {
            return Collections.emptyList();
        }
        Multimap<Concept, Concept> predecessorMapFromSource = tinkerComputeQuery.getPredecessorMap(result);
        List<List<Concept>> allPaths = tinkerComputeQuery.getAllPaths(predecessorMapFromSource, sourceId);
        if (tinkerComputeQuery.isAttributeIncluded()) {
            // this can be slow
            return tinkerComputeQuery.getExtendedPaths(allPaths);
        }
        LOG.info("Number of paths: " + allPaths.size());
        return allPaths;
    });
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) ShortestPathVertexProgram(ai.grakn.graql.internal.analytics.ShortestPathVertexProgram) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) List(java.util.List) LabelId(ai.grakn.concept.LabelId) NoResultException(ai.grakn.graql.internal.analytics.NoResultException) ConceptId(ai.grakn.concept.ConceptId)

Aggregations

ConceptId (ai.grakn.concept.ConceptId)80 Test (org.junit.Test)55 Concept (ai.grakn.concept.Concept)23 Role (ai.grakn.concept.Role)22 RelationshipType (ai.grakn.concept.RelationshipType)19 GraknTx (ai.grakn.GraknTx)18 EntityType (ai.grakn.concept.EntityType)18 Label (ai.grakn.concept.Label)16 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)14 Var (ai.grakn.graql.Var)12 List (java.util.List)12 Entity (ai.grakn.concept.Entity)10 AttributeType (ai.grakn.concept.AttributeType)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 ClassRule (org.junit.ClassRule)9 GraknTxType (ai.grakn.GraknTxType)8 Keyspace (ai.grakn.Keyspace)8 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)8