Search in sources :

Example 61 with ConceptId

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

the class SubProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    Var varName = var.var().asUserDefined();
    VarPatternAdmin typeVar = this.superType();
    Var typeVariable = typeVar.var().asUserDefined();
    IdPredicate predicate = getIdPredicate(typeVariable, typeVar, vars, parent);
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    return SubAtom.create(varName, typeVariable, predicateId, parent);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId)

Example 62 with ConceptId

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

the class AbstractIsaProperty method mapToAtom.

@Nullable
@Override
public final Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    // IsaProperty is unique within a var, so skip if this is a relation
    if (var.hasProperty(RelationshipProperty.class))
        return null;
    Var varName = var.var().asUserDefined();
    VarPatternAdmin typePattern = this.type();
    Var typeVariable = typePattern.var();
    IdPredicate predicate = getIdPredicate(typeVariable, typePattern, vars, parent);
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    // isa part
    VarPatternAdmin isaVar = varPatternForAtom(varName, typeVariable).admin();
    return IsaAtom.create(isaVar, typeVariable, predicateId, parent);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId) Nullable(javax.annotation.Nullable)

Example 63 with ConceptId

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

the class GrpcServerTest method whenGettingANonExistentConcept_ReturnNothing.

@Test
public void whenGettingANonExistentConcept_ReturnNothing() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    when(tx.getConcept(id)).thenReturn(null);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.getConceptRequest(id));
        GrpcConcept.OptionalConcept response = tx.receive().ok().getOptionalConcept();
        assertEquals(GrpcConcept.OptionalConcept.ValueCase.ABSENT, response.getValueCase());
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 64 with ConceptId

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

the class ElementFactory method buildConcept.

public <X extends Concept> X buildConcept(VertexElement vertexElement) {
    Schema.BaseType type;
    try {
        type = getBaseType(vertexElement);
    } catch (IllegalStateException e) {
        throw TemporaryWriteException.indexOverlap(vertexElement.element(), e);
    }
    ConceptId conceptId = ConceptId.of(vertexElement.property(Schema.VertexProperty.ID));
    if (!tx.txCache().isConceptCached(conceptId)) {
        Concept concept;
        switch(type) {
            case RELATIONSHIP:
                concept = RelationshipImpl.create(RelationshipReified.get(vertexElement));
                break;
            case TYPE:
                concept = new TypeImpl(vertexElement);
                break;
            case ROLE:
                concept = RoleImpl.get(vertexElement);
                break;
            case RELATIONSHIP_TYPE:
                concept = RelationshipTypeImpl.get(vertexElement);
                break;
            case ENTITY:
                concept = EntityImpl.get(vertexElement);
                break;
            case ENTITY_TYPE:
                concept = EntityTypeImpl.get(vertexElement);
                break;
            case ATTRIBUTE_TYPE:
                concept = AttributeTypeImpl.get(vertexElement);
                break;
            case ATTRIBUTE:
                concept = AttributeImpl.get(vertexElement);
                break;
            case RULE:
                concept = RuleImpl.get(vertexElement);
                break;
            default:
                throw GraknTxOperationException.unknownConcept(type.name());
        }
        tx.txCache().cacheConcept(concept);
    }
    return tx.txCache().getCachedConcept(conceptId);
}
Also used : Concept(ai.grakn.concept.Concept) Schema(ai.grakn.util.Schema) ConceptId(ai.grakn.concept.ConceptId)

Example 65 with ConceptId

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

the class ElementFactory method buildConcept.

public <X extends Concept> X buildConcept(EdgeElement edgeElement) {
    Schema.EdgeLabel label = Schema.EdgeLabel.valueOf(edgeElement.label().toUpperCase(Locale.getDefault()));
    ConceptId conceptId = ConceptId.of(edgeElement.id().getValue());
    if (!tx.txCache().isConceptCached(conceptId)) {
        Concept concept;
        switch(label) {
            case ATTRIBUTE:
                concept = RelationshipImpl.create(RelationshipEdge.get(edgeElement));
                break;
            default:
                throw GraknTxOperationException.unknownConcept(label.name());
        }
        tx.txCache().cacheConcept(concept);
    }
    return tx.txCache().getCachedConcept(conceptId);
}
Also used : Concept(ai.grakn.concept.Concept) Schema(ai.grakn.util.Schema) 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