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)));
}
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);
}
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));
}
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();
}
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));
}
Aggregations