/** * Add relates edges to a var, given a type * @param var var to be modified * @param type type from which metadata extracted * @return var with appropriate relates edges */ private static VarPattern relates(VarPattern var, RelationshipType type){ for(Role role:type.roles().collect(Collectors.toSet())){ var = var.relates(Graql.label(role.label())); } return var; }
@Override public UnaryOperator<VarPattern> visitRelates(GraqlParser.RelatesContext ctx) { VarPattern superRole = ctx.superRole != null ? visitVariable(ctx.superRole) : null; return var -> var.relates(visitVariable(ctx.role), superRole); }
/** * @throws GraqlQueryException if no label is specified on {@code resourceType} */ public static HasAttributeTypeProperty of(VarPatternAdmin resourceType, boolean required) { Label resourceLabel = resourceType.getTypeLabel().orElseThrow(() -> GraqlQueryException.noLabelSpecifiedForHas(resourceType) ); VarPattern role = Graql.label(Schema.MetaSchema.ROLE.getLabel()); VarPatternAdmin ownerRole = var().sub(role).admin(); VarPatternAdmin valueRole = var().sub(role).admin(); VarPattern relationType = var().sub(Graql.label(Schema.MetaSchema.RELATIONSHIP.getLabel())); // If a key, limit only to the implicit key type if(required){ ownerRole = ownerRole.label(KEY_OWNER.getLabel(resourceLabel)).admin(); valueRole = valueRole.label(KEY_VALUE.getLabel(resourceLabel)).admin(); relationType = relationType.label(KEY.getLabel(resourceLabel)); } VarPatternAdmin relationOwner = relationType.relates(ownerRole).admin(); VarPatternAdmin relationValue = relationType.admin().var().relates(valueRole).admin(); return new AutoValue_HasAttributeTypeProperty( resourceType, ownerRole, valueRole, relationOwner, relationValue, required); }