Search in sources :

Example 56 with Label

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);
}
Also used : Label(ai.grakn.concept.Label) GraknAdmin(ai.grakn.kb.admin.GraknAdmin) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 57 with Label

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);
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Label(ai.grakn.concept.Label) VarPattern(ai.grakn.graql.VarPattern)

Example 58 with Label

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);
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) ConceptId(ai.grakn.concept.ConceptId)

Example 59 with Label

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);
}
Also used : Role(ai.grakn.concept.Role) Label(ai.grakn.concept.Label) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 60 with 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()));
}
Also used : Label(ai.grakn.concept.Label) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Label (ai.grakn.concept.Label)87 Test (org.junit.Test)41 Role (ai.grakn.concept.Role)25 GraknTx (ai.grakn.GraknTx)22 ConceptId (ai.grakn.concept.ConceptId)21 Concept (ai.grakn.concept.Concept)20 Set (java.util.Set)20 RelationshipType (ai.grakn.concept.RelationshipType)19 SchemaConcept (ai.grakn.concept.SchemaConcept)19 AttributeType (ai.grakn.concept.AttributeType)17 EntityType (ai.grakn.concept.EntityType)17 Relationship (ai.grakn.concept.Relationship)14 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 Type (ai.grakn.concept.Type)12 Stream (java.util.stream.Stream)12 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)11 Schema (ai.grakn.util.Schema)11 Collection (java.util.Collection)11 Pattern (ai.grakn.graql.Pattern)10