use of ai.grakn.concept.Label in project grakn by graknlabs.
the class EntityTypeTest method whenAddingResourcesWithSubTypesToEntityTypes_EnsureImplicitStructureFollowsSubTypes.
@Test
public void whenAddingResourcesWithSubTypesToEntityTypes_EnsureImplicitStructureFollowsSubTypes() {
EntityType entityType1 = tx.putEntityType("Entity Type 1");
EntityType entityType2 = tx.putEntityType("Entity Type 2");
Label superLabel = Label.of("Super Attribute Type");
Label label = Label.of("Attribute Type");
AttributeType rtSuper = tx.putAttributeType(superLabel, AttributeType.DataType.STRING);
AttributeType rt = tx.putAttributeType(label, AttributeType.DataType.STRING).sup(rtSuper);
entityType1.attribute(rtSuper);
entityType2.attribute(rt);
// Check role types are only built explicitly
assertThat(entityType1.plays().collect(toSet()), containsInAnyOrder(tx.getRole(Schema.ImplicitType.HAS_OWNER.getLabel(superLabel).getValue())));
assertThat(entityType2.plays().collect(toSet()), containsInAnyOrder(tx.getRole(Schema.ImplicitType.HAS_OWNER.getLabel(label).getValue())));
// Check Implicit Types Follow SUB Structure
RelationshipType rtSuperRelation = tx.getSchemaConcept(Schema.ImplicitType.HAS.getLabel(rtSuper.getLabel()));
Role rtSuperRoleOwner = tx.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(rtSuper.getLabel()));
Role rtSuperRoleValue = tx.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(rtSuper.getLabel()));
RelationshipType rtRelation = tx.getSchemaConcept(Schema.ImplicitType.HAS.getLabel(rt.getLabel()));
Role reRoleOwner = tx.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(rt.getLabel()));
Role reRoleValue = tx.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(rt.getLabel()));
assertEquals(rtSuperRoleOwner, reRoleOwner.sup());
assertEquals(rtSuperRoleValue, reRoleValue.sup());
assertEquals(rtSuperRelation, rtRelation.sup());
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class AbstractThingGenerator method generateFromTx.
@Override
protected final T generateFromTx() {
T thing;
S type = genFromTx(generatorClass).makeExcludeAbstractTypes().excludeMeta().generate(random, status);
// noinspection unchecked
Collection<T> instances = (Collection<T>) type.instances().collect(toSet());
if (instances.isEmpty()) {
thing = newInstance(type);
} else {
thing = random.choose(instances);
}
if (withResource && !thing.attributes().findAny().isPresent()) {
// A new attribute type is created every time a attribute is lacking.
// Existing attribute types and resources of those types are not used because we end up mutating the
// the schema in strange ways. This approach is less complex but ensures everything has a attribute
// without conflicting with the schema
// Create a new attribute type
AttributeType.DataType<?> dataType = gen(AttributeType.DataType.class);
Label label = genFromTx(Labels.class).mustBeUnused().generate(random, status);
AttributeType attributeType = tx().putAttributeType(label, dataType);
// Create new attribute
Attribute attribute = newResource(attributeType);
// Link everything together
type.attribute(attributeType);
thing.attribute(attribute);
}
return thing;
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class RemoteConceptsTest method whenSettingLabel_ExecuteAConceptMethod.
@Test
public void whenSettingLabel_ExecuteAConceptMethod() {
Label label = Label.of("Dunstan");
assertEquals(schemaConcept, schemaConcept.setLabel(label));
verifyConceptMethodCalled(ConceptMethods.setLabel(label));
}
use of ai.grakn.concept.Label 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.Label in project grakn by graknlabs.
the class MigratorTestUtils method getProperties.
public static Collection<Thing> getProperties(GraknTx graph, Thing thing, String label) {
RelationshipType relation = graph.getRelationshipType(label);
Set<Thing> things = new HashSet<>();
relation.instances().filter(i -> i.rolePlayers().anyMatch(t -> t.equals(thing))).forEach(i -> i.rolePlayers().forEach(things::add));
things.remove(thing);
return things;
}
Aggregations