Search in sources :

Example 46 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class SchemaConceptPropertyTest method whenASchemaElementHasADirectSuper_ItIsADirectSubOfThatSuper.

@Property
public void whenASchemaElementHasADirectSuper_ItIsADirectSubOfThatSuper(SchemaConcept schemaConcept) {
    SchemaConcept superConcept = schemaConcept.sup();
    assumeTrue(superConcept != null);
    assertThat(PropertyUtil.directSubs(superConcept), hasItem(schemaConcept));
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Property(com.pholser.junit.quickcheck.Property)

Example 47 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class ValidateGlobalRules method checkRuleSideInvalid.

/**
 * @param graph The graph to query against
 * @param rule The rule the pattern was extracted from
 * @param side The side from which the pattern was extracted
 * @param pattern The pattern from which we will extract the types in the pattern
 * @return A list of errors if the pattern refers to any non-existent types in the graph
 */
private static Set<String> checkRuleSideInvalid(GraknTx graph, Rule rule, Schema.VertexProperty side, Pattern pattern) {
    Set<String> errors = new HashSet<>();
    pattern.admin().varPatterns().stream().flatMap(v -> v.innerVarPatterns().stream()).flatMap(v -> v.getTypeLabels().stream()).forEach(typeLabel -> {
        SchemaConcept schemaConcept = graph.getSchemaConcept(typeLabel);
        if (schemaConcept == null) {
            errors.add(ErrorMessage.VALIDATION_RULE_MISSING_ELEMENTS.getMessage(side, rule.getLabel(), typeLabel));
        } else {
            if (Schema.VertexProperty.RULE_WHEN.equals(side)) {
                if (schemaConcept.isType()) {
                    RuleImpl.from(rule).addHypothesis(schemaConcept.asType());
                }
            } else if (Schema.VertexProperty.RULE_THEN.equals(side)) {
                if (schemaConcept.isType()) {
                    RuleImpl.from(rule).addConclusion(schemaConcept.asType());
                }
            } else {
                throw GraknTxOperationException.invalidPropertyUse(rule, side);
            }
        }
    });
    return errors;
}
Also used : RuleImpl(ai.grakn.kb.internal.concept.RuleImpl) Iterables(com.google.common.collect.Iterables) VALIDATION_CASTING(ai.grakn.util.ErrorMessage.VALIDATION_CASTING) VALIDATION_REQUIRED_RELATION(ai.grakn.util.ErrorMessage.VALIDATION_REQUIRED_RELATION) Role(ai.grakn.concept.Role) SchemaConcept(ai.grakn.concept.SchemaConcept) RelationshipTypeImpl(ai.grakn.kb.internal.concept.RelationshipTypeImpl) Type(ai.grakn.concept.Type) Rule(ai.grakn.concept.Rule) Attribute(ai.grakn.concept.Attribute) TypeImpl(ai.grakn.kb.internal.concept.TypeImpl) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) RelationshipType(ai.grakn.concept.RelationshipType) GraknTx(ai.grakn.GraknTx) CommonUtil(ai.grakn.util.CommonUtil) Map(java.util.Map) Relationship(ai.grakn.concept.Relationship) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) ErrorMessage(ai.grakn.util.ErrorMessage) VALIDATION_RELATION_TYPES_ROLES_SCHEMA(ai.grakn.util.ErrorMessage.VALIDATION_RELATION_TYPES_ROLES_SCHEMA) SchemaConceptImpl(ai.grakn.kb.internal.concept.SchemaConceptImpl) Conjunction(ai.grakn.graql.admin.Conjunction) VALIDATION_RELATION_TYPE(ai.grakn.util.ErrorMessage.VALIDATION_RELATION_TYPE) Collection(java.util.Collection) Set(java.util.Set) VALIDATION_ROLE_TYPE_MISSING_RELATION_TYPE(ai.grakn.util.ErrorMessage.VALIDATION_ROLE_TYPE_MISSING_RELATION_TYPE) Collectors(java.util.stream.Collectors) Atomic(ai.grakn.graql.admin.Atomic) ReasonerQuery(ai.grakn.graql.admin.ReasonerQuery) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) VALIDATION_RELATION_CASTING_LOOP_FAIL(ai.grakn.util.ErrorMessage.VALIDATION_RELATION_CASTING_LOOP_FAIL) Casting(ai.grakn.kb.internal.structure.Casting) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Optional(java.util.Optional) Schema(ai.grakn.util.Schema) Pattern(ai.grakn.graql.Pattern) Collections(java.util.Collections) VALIDATION_NOT_EXACTLY_ONE_KEY(ai.grakn.util.ErrorMessage.VALIDATION_NOT_EXACTLY_ONE_KEY) SchemaConcept(ai.grakn.concept.SchemaConcept) HashSet(java.util.HashSet)

Example 48 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class GlobalCache method populateSchemaTxCache.

void populateSchemaTxCache(TxCache txCache) {
    try {
        lock.writeLock().lock();
        Map<Label, SchemaConcept> cachedSchemaSnapshot = getCachedTypes();
        Map<Label, LabelId> cachedLabelsSnapshot = getCachedLabels();
        // Read central cache into txCache cloning only base concepts. Sets clones later
        for (SchemaConcept type : cachedSchemaSnapshot.values()) {
            txCache.cacheConcept(type);
        }
        // Load Labels Separately. We do this because the TypeCache may have expired.
        cachedLabelsSnapshot.forEach(txCache::cacheLabel);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) LabelId(ai.grakn.concept.LabelId)

Example 49 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class GraknTxTest method whenClosingReadOnlyGraph_EnsureTypesAreCached.

@Test
public void whenClosingReadOnlyGraph_EnsureTypesAreCached() {
    assertCacheOnlyContainsMetaTypes();
    // noinspection ResultOfMethodCallIgnored
    // This loads some types into transaction cache
    tx.getMetaConcept().subs();
    tx.abort();
    // Ensure central cache is empty
    assertCacheOnlyContainsMetaTypes();
    tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.READ);
    Set<SchemaConcept> finalTypes = new HashSet<>();
    finalTypes.addAll(tx.getMetaConcept().subs().collect(toSet()));
    finalTypes.add(tx.getMetaRole());
    finalTypes.add(tx.getMetaRule());
    tx.abort();
    for (SchemaConcept type : tx.getGlobalCache().getCachedTypes().values()) {
        assertTrue("Type [" + type + "] is missing from central cache after closing read only graph", finalTypes.contains(type));
    }
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class DeleteQueryTest method whenDeletingASchemaConcept_Throw.

@Test
public void whenDeletingASchemaConcept_Throw() {
    SchemaConcept newType = qb.define(x.label("new-type").sub(ENTITY)).execute().get(x).asSchemaConcept();
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(GraqlQueryException.deleteSchemaConcept(newType).getMessage());
    qb.match(x.label("new-type")).delete(x).execute();
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

Aggregations

SchemaConcept (ai.grakn.concept.SchemaConcept)51 Label (ai.grakn.concept.Label)19 Set (java.util.Set)15 Type (ai.grakn.concept.Type)14 GraknTx (ai.grakn.GraknTx)12 HashSet (java.util.HashSet)12 ConceptId (ai.grakn.concept.ConceptId)11 Stream (java.util.stream.Stream)11 Test (org.junit.Test)11 AttributeType (ai.grakn.concept.AttributeType)10 Property (com.pholser.junit.quickcheck.Property)10 Role (ai.grakn.concept.Role)9 Concept (ai.grakn.concept.Concept)8 Sets (com.google.common.collect.Sets)8 Optional (java.util.Optional)8 RelationshipType (ai.grakn.concept.RelationshipType)7 Rule (ai.grakn.concept.Rule)7 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)7 ErrorMessage (ai.grakn.util.ErrorMessage)7 Var (ai.grakn.graql.Var)6