use of ai.grakn.concept.Label in project grakn by graknlabs.
the class GraqlCompleter method create.
public static GraqlCompleter create(GraknSession session) {
ImmutableSet<Label> labels;
try (GraknAdmin tx = session.open(GraknTxType.READ).admin()) {
Stream<SchemaConcept> metaConcepts = Stream.of(tx.getMetaConcept(), tx.getMetaRole(), tx.getMetaRule()).flatMap(SchemaConcept::subs);
labels = metaConcepts.map(SchemaConcept::getLabel).collect(toImmutableSet());
}
return new GraqlCompleter(labels);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class HasAttributeTypeProperty method of.
/**
* @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);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class HasAttributeTypeProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
// NB: HasResourceType is a special case and it doesn't allow variables as resource types
Var varName = var.var().asUserDefined();
Label label = this.resourceType().getTypeLabel().orElse(null);
Var predicateVar = var().asUserDefined();
SchemaConcept schemaConcept = parent.tx().getSchemaConcept(label);
ConceptId predicateId = schemaConcept != null ? schemaConcept.getId() : null;
// isa part
VarPatternAdmin resVar = varName.has(Graql.label(label)).admin();
return HasAtom.create(resVar, predicateVar, predicateId, parent);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCallingGetSchemaConceptWithAnIncorrectGeneric_ItThrows.
@Property
public void whenCallingGetSchemaConceptWithAnIncorrectGeneric_ItThrows(@Open GraknTx graph, @FromTx Type type) {
assumeFalse(type.isRole());
Label label = type.getLabel();
exception.expect(ClassCastException.class);
// We have to assign the result for the cast to happen
// noinspection unused
Role role = graph.getSchemaConcept(label);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCallingGetRule_TheResultIsTheSameAsGetSchemaConcept.
@Property
public void whenCallingGetRule_TheResultIsTheSameAsGetSchemaConcept(@Open GraknTx graph, @FromTx Rule type) {
Label label = type.getLabel();
assertSameResult(() -> graph.getSchemaConcept(label), () -> graph.getRule(label.getValue()));
}
Aggregations