use of ai.grakn.concept.Label in project grakn by graknlabs.
the class MigratorTestUtils method getResources.
public static Stream<Attribute> getResources(GraknTx graph, Thing thing, Label label) {
Role roleOwner = graph.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(label));
Role roleOther = graph.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(label));
Stream<Relationship> relations = thing.relationships(roleOwner);
return relations.flatMap(r -> r.rolePlayers(roleOther)).map(Concept::asAttribute);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class EntityTest method whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated.
@Test
public void whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.attribute(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
entity.attribute(attribute);
Relationship relationship = entity.relationships().iterator().next();
checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.HAS, Schema.ImplicitType.HAS_OWNER, Schema.ImplicitType.HAS_VALUE);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class RelationshipAtom method validateRelationPlayers.
private Set<String> validateRelationPlayers(Rule rule) {
Set<String> errors = new HashSet<>();
getRelationPlayers().forEach(rp -> {
VarPatternAdmin role = rp.getRole().orElse(null);
if (role == null) {
errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
} else {
Label roleLabel = role.getTypeLabel().orElse(null);
if (roleLabel == null) {
errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
} else {
if (Schema.MetaSchema.isMetaLabel(roleLabel)) {
errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
}
Role roleType = tx().getRole(roleLabel.getValue());
if (roleType != null && roleType.isImplicit()) {
errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_IMPLICIT_ROLE.getMessage(rule.getThen(), rule.getLabel()));
}
}
}
});
return errors;
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class ConceptBuilder method putSchemaConcept.
private SchemaConcept putSchemaConcept() {
SchemaConcept superConcept = use(SUPER_CONCEPT);
Label label = use(LABEL);
SchemaConcept concept;
if (superConcept.isEntityType()) {
concept = executor.tx().putEntityType(label);
} else if (superConcept.isRelationshipType()) {
concept = executor.tx().putRelationshipType(label);
} else if (superConcept.isRole()) {
concept = executor.tx().putRole(label);
} else if (superConcept.isAttributeType()) {
AttributeType attributeType = superConcept.asAttributeType();
AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.getDataType());
concept = executor.tx().putAttributeType(label, dataType);
} else if (superConcept.isRule()) {
concept = executor.tx().putRule(label, use(WHEN), use(THEN));
} else {
throw GraqlQueryException.insertMetaType(label, superConcept);
}
setSuper(concept, superConcept);
return concept;
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class QueryVisitor method visitPropHas.
@Override
public UnaryOperator<VarPattern> visitPropHas(GraqlParser.PropHasContext ctx) {
Label type = visitLabel(ctx.label());
VarPattern relation = Optional.ofNullable(ctx.relation).map(this::getVariable).orElseGet(Graql::var);
VarPattern resource = Optional.ofNullable(ctx.resource).map(this::getVariable).orElseGet(Graql::var);
if (ctx.predicate() != null) {
resource = resource.val(visitPredicate(ctx.predicate()));
}
VarPattern finalResource = resource;
return var -> var.has(type, finalResource, relation);
}
Aggregations