Search in sources :

Example 41 with Type

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

the class TypePropertyTest method whenAddingAPlaysToATypesIndirectSuperType_TheTypePlaysThatRole.

@Property
public void whenAddingAPlaysToATypesIndirectSuperType_TheTypePlaysThatRole(@Open GraknTx tx, @FromTx Type type, @FromTx Role role, long seed) {
    SchemaConcept superConcept = PropertyUtil.choose(tx.admin().sups(type), seed);
    assumeTrue(superConcept.isType());
    assumeFalse(isMetaLabel(superConcept.getLabel()));
    Type superType = superConcept.asType();
    Set<Role> previousPlays = type.plays().collect(toSet());
    superType.plays(role);
    Set<Role> newPlays = type.plays().collect(toSet());
    assertEquals(newPlays, Sets.union(previousPlays, ImmutableSet.of(role)));
}
Also used : Role(ai.grakn.concept.Role) Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) SchemaConcept(ai.grakn.concept.SchemaConcept) Property(com.pholser.junit.quickcheck.Property)

Example 42 with Type

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

the class ThingImpl method attributeRelationship.

private Relationship attributeRelationship(Attribute attribute, boolean isInferred) {
    Schema.ImplicitType has = Schema.ImplicitType.HAS;
    Schema.ImplicitType hasValue = Schema.ImplicitType.HAS_VALUE;
    Schema.ImplicitType hasOwner = Schema.ImplicitType.HAS_OWNER;
    // Is this attribute a key to me?
    if (type().keys().anyMatch(rt -> rt.equals(attribute.type()))) {
        has = Schema.ImplicitType.KEY;
        hasValue = Schema.ImplicitType.KEY_VALUE;
        hasOwner = Schema.ImplicitType.KEY_OWNER;
    }
    Label label = attribute.type().getLabel();
    RelationshipType hasAttribute = vertex().tx().getSchemaConcept(has.getLabel(label));
    Role hasAttributeOwner = vertex().tx().getSchemaConcept(hasOwner.getLabel(label));
    Role hasAttributeValue = vertex().tx().getSchemaConcept(hasValue.getLabel(label));
    if (hasAttribute == null || hasAttributeOwner == null || hasAttributeValue == null || type().plays().noneMatch(play -> play.equals(hasAttributeOwner))) {
        throw GraknTxOperationException.hasNotAllowed(this, attribute);
    }
    EdgeElement attributeEdge = addEdge(AttributeImpl.from(attribute), Schema.EdgeLabel.ATTRIBUTE);
    if (isInferred)
        attributeEdge.property(Schema.EdgeProperty.IS_INFERRED, true);
    return vertex().tx().factory().buildRelation(attributeEdge, hasAttribute, hasAttributeOwner, hasAttributeValue);
}
Also used : Role(ai.grakn.concept.Role) Arrays(java.util.Arrays) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Type(ai.grakn.concept.Type) Cacheable(ai.grakn.kb.internal.cache.Cacheable) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) LabelId(ai.grakn.concept.LabelId) RelationshipType(ai.grakn.concept.RelationshipType) Cache(ai.grakn.kb.internal.cache.Cache) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) EdgeElement(ai.grakn.kb.internal.structure.EdgeElement) P(org.apache.tinkerpop.gremlin.process.traversal.P) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Set(java.util.Set) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) VertexElement(ai.grakn.kb.internal.structure.VertexElement) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Casting(ai.grakn.kb.internal.structure.Casting) Optional(java.util.Optional) Schema(ai.grakn.util.Schema) EdgeElement(ai.grakn.kb.internal.structure.EdgeElement) Schema(ai.grakn.util.Schema) Label(ai.grakn.concept.Label) RelationshipType(ai.grakn.concept.RelationshipType)

Example 43 with Type

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

the class GraknTxTest method whenGettingSupsOfASchemaConcept_ResultIncludesMetaThing.

@Test
public void whenGettingSupsOfASchemaConcept_ResultIncludesMetaThing() {
    EntityType yes = tx.putEntityType("yes");
    EntityType entity = tx.getMetaEntityType();
    Type thing = tx.getMetaConcept();
    assertThat(tx.sups(yes).collect(toSet()), containsInAnyOrder(yes, entity, thing));
    assertThat(tx.sups(entity).collect(toSet()), containsInAnyOrder(entity, thing));
    assertThat(tx.sups(thing).collect(toSet()), containsInAnyOrder(thing));
}
Also used : EntityType(ai.grakn.concept.EntityType) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) GraknTxType(ai.grakn.GraknTxType) Test(org.junit.Test)

Example 44 with Type

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

the class QueryErrorTest method whenTryingToSetExistingInstanceType_Throw.

@Test
public void whenTryingToSetExistingInstanceType_Throw() {
    Thing movie = rule.tx().getEntityType("movie").instances().iterator().next();
    Type person = rule.tx().getEntityType("person");
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(containsString("person"));
    qb.match(var("x").id(movie.getId())).insert(var("x").isa(label(person.getLabel()))).execute();
}
Also used : Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 45 with Type

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

the class UndefineQueryTest method whenUndefiningById_TheSchemaConceptIsDeleted.

@Test
public void whenUndefiningById_TheSchemaConceptIsDeleted() {
    Type newType = qb.define(x.label(NEW_TYPE).sub(ENTITY)).execute().get(x).asType();
    assertNotNull(tx.getType(NEW_TYPE));
    qb.undefine(var().id(newType.getId()).sub(ENTITY)).execute();
    assertNull(tx.getType(NEW_TYPE));
}
Also used : Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Aggregations

Type (ai.grakn.concept.Type)47 RelationshipType (ai.grakn.concept.RelationshipType)28 AttributeType (ai.grakn.concept.AttributeType)25 Test (org.junit.Test)23 EntityType (ai.grakn.concept.EntityType)21 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Label (ai.grakn.concept.Label)15 Set (java.util.Set)15 GraknTx (ai.grakn.GraknTx)14 Concept (ai.grakn.concept.Concept)13 Collectors (java.util.stream.Collectors)13 Role (ai.grakn.concept.Role)12 ConceptId (ai.grakn.concept.ConceptId)11 Schema (ai.grakn.util.Schema)10 HashSet (java.util.HashSet)10 Stream (java.util.stream.Stream)10 GraqlQueryException (ai.grakn.exception.GraqlQueryException)9 Map (java.util.Map)9 Answer (ai.grakn.graql.admin.Answer)8 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)8