Search in sources :

Example 76 with Label

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

the class MigratorTestUtils method assertRelationBetweenInstancesExists.

public static void assertRelationBetweenInstancesExists(GraknTx graph, Thing thing1, Thing thing2, Label relation) {
    RelationshipType relationshipType = graph.getSchemaConcept(relation);
    Role role1 = thing1.plays().filter(r -> r.relationshipTypes().anyMatch(rel -> rel.equals(relationshipType))).findFirst().get();
    assertTrue(thing1.relationships(role1).anyMatch(rel -> rel.rolePlayers().anyMatch(r -> r.equals(thing2))));
}
Also used : Role(ai.grakn.concept.Role) InvalidKBException(ai.grakn.exception.InvalidKBException) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Files(com.google.common.io.Files) GraknTx(ai.grakn.GraknTx) Relationship(ai.grakn.concept.Relationship) GraknTxType(ai.grakn.GraknTxType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) GraknSession(ai.grakn.GraknSession) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Schema(ai.grakn.util.Schema) TestCase.assertEquals(junit.framework.TestCase.assertEquals) RelationshipType(ai.grakn.concept.RelationshipType)

Example 77 with Label

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

the class GraknTxPutPropertyTest method whenCallingPutResourceTypeWithThePropertiesOfAnExistingResourceType_ItReturnsThatType.

@Property
public void whenCallingPutResourceTypeWithThePropertiesOfAnExistingResourceType_ItReturnsThatType(@Open GraknTx graph, @FromTx AttributeType<?> attributeType) {
    assumeFalse(attributeType.equals(graph.admin().getMetaAttributeType()));
    Label label = attributeType.getLabel();
    AttributeType.DataType<?> dataType = attributeType.getDataType();
    AttributeType<?> newType = graph.putAttributeType(label, dataType);
    assertEquals(attributeType, newType);
}
Also used : AttributeType(ai.grakn.concept.AttributeType) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Label(ai.grakn.concept.Label) Property(com.pholser.junit.quickcheck.Property)

Example 78 with Label

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

the class RemoteGraknTxTest method whenGettingNonExistentSchemaConceptViaLabel_ReturnNull.

@Test
public void whenGettingNonExistentSchemaConceptViaLabel_ReturnNull() {
    Label label = Label.of("foo");
    try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
        // The open request
        verify(server.requests()).onNext(any());
        server.setResponse(GrpcUtil.getSchemaConceptRequest(label), GrpcUtil.optionalConceptResponse(Optional.empty()));
        assertNull(tx.getSchemaConcept(label));
    }
}
Also used : Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 79 with Label

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

the class RemoteGraknTxTest method whenPuttingEntityType_EnsureCorrectRequestIsSent.

@Test
public void whenPuttingEntityType_EnsureCorrectRequestIsSent() {
    ConceptId id = ConceptId.of(V123.getValue());
    Label label = Label.of("foo");
    try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
        // The open request
        verify(server.requests()).onNext(any());
        Concept concept = RemoteConcepts.createEntityType(tx, id);
        server.setResponse(GrpcUtil.putEntityTypeRequest(label), GrpcUtil.conceptResponse(concept));
        assertEquals(concept, tx.putEntityType(label));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 80 with Label

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

the class RelationshipProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    // set varName as user defined if reified
    // reified if contains more properties than the RelationshipProperty itself and potential IsaProperty
    boolean isReified = var.getProperties().filter(prop -> !RelationshipProperty.class.isInstance(prop)).anyMatch(prop -> !AbstractIsaProperty.class.isInstance(prop));
    VarPattern relVar = isReified ? var.var().asUserDefined() : var.var();
    for (RelationPlayer rp : relationPlayers()) {
        VarPattern rolePattern = rp.getRole().orElse(null);
        VarPattern rolePlayer = rp.getRolePlayer();
        if (rolePattern != null) {
            Var roleVar = rolePattern.admin().var();
            // look for indirect role definitions
            IdPredicate roleId = getUserDefinedIdPredicate(roleVar, vars, parent);
            if (roleId != null) {
                Concept concept = parent.tx().getConcept(roleId.getPredicate());
                if (concept != null) {
                    if (concept.isRole()) {
                        Label roleLabel = concept.asSchemaConcept().getLabel();
                        rolePattern = roleVar.label(roleLabel);
                    } else {
                        throw GraqlQueryException.nonRoleIdAssignedToRoleVariable(var);
                    }
                }
            }
            relVar = relVar.rel(rolePattern, rolePlayer);
        } else
            relVar = relVar.rel(rolePlayer);
    }
    // isa part
    AbstractIsaProperty isaProp = var.getProperty(AbstractIsaProperty.class).orElse(null);
    IdPredicate predicate = null;
    // if no isa property present generate type variable
    Var typeVariable = isaProp != null ? isaProp.type().var() : Graql.var();
    // Isa present
    if (isaProp != null) {
        VarPatternAdmin isaVar = isaProp.type();
        Label label = isaVar.getTypeLabel().orElse(null);
        if (label != null) {
            predicate = IdPredicate.create(typeVariable, label, parent);
        } else {
            typeVariable = isaVar.var();
            predicate = getUserDefinedIdPredicate(typeVariable, vars, parent);
        }
    }
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    relVar = isaProp instanceof DirectIsaProperty ? relVar.directIsa(typeVariable.asUserDefined()) : relVar.isa(typeVariable.asUserDefined());
    return RelationshipAtom.create(relVar.admin(), typeVariable, predicateId, parent);
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Role(ai.grakn.concept.Role) EquivalentFragmentSets.rolePlayer(ai.grakn.graql.internal.gremlin.sets.EquivalentFragmentSets.rolePlayer) Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) Graql(ai.grakn.graql.Graql) HashSet(java.util.HashSet) UniqueVarProperty(ai.grakn.graql.admin.UniqueVarProperty) Label(ai.grakn.concept.Label) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) GraknTx(ai.grakn.GraknTx) CommonUtil(ai.grakn.util.CommonUtil) QueryOperationExecutor(ai.grakn.graql.internal.query.runner.QueryOperationExecutor) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Collectors.toSet(java.util.stream.Collectors.toSet) CommonUtil.toImmutableSet(ai.grakn.util.CommonUtil.toImmutableSet) GraqlQueryException(ai.grakn.exception.GraqlQueryException) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Set(java.util.Set) IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) Sets(com.google.common.collect.Sets) Collectors.joining(java.util.stream.Collectors.joining) Atomic(ai.grakn.graql.admin.Atomic) ReasonerQuery(ai.grakn.graql.admin.ReasonerQuery) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) EquivalentFragmentSets(ai.grakn.graql.internal.gremlin.sets.EquivalentFragmentSets) Var(ai.grakn.graql.Var) AutoValue(com.google.auto.value.AutoValue) RelationPlayer(ai.grakn.graql.admin.RelationPlayer) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Optional(java.util.Optional) ReasonerUtils.getUserDefinedIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getUserDefinedIdPredicate) Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getUserDefinedIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getUserDefinedIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) VarPattern(ai.grakn.graql.VarPattern) RelationPlayer(ai.grakn.graql.admin.RelationPlayer)

Aggregations

Label (ai.grakn.concept.Label)87 Test (org.junit.Test)41 Role (ai.grakn.concept.Role)25 GraknTx (ai.grakn.GraknTx)22 ConceptId (ai.grakn.concept.ConceptId)21 Concept (ai.grakn.concept.Concept)20 Set (java.util.Set)20 RelationshipType (ai.grakn.concept.RelationshipType)19 SchemaConcept (ai.grakn.concept.SchemaConcept)19 AttributeType (ai.grakn.concept.AttributeType)17 EntityType (ai.grakn.concept.EntityType)17 Relationship (ai.grakn.concept.Relationship)14 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 Type (ai.grakn.concept.Type)12 Stream (java.util.stream.Stream)12 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)11 Schema (ai.grakn.util.Schema)11 Collection (java.util.Collection)11 Pattern (ai.grakn.graql.Pattern)10