Search in sources :

Example 41 with SchemaConcept

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

the class QueryAnswerStream method entityTypeFilter.

static boolean entityTypeFilter(Answer answer, Set<TypeAtom> types) {
    if (types.isEmpty())
        return true;
    for (TypeAtom type : types) {
        Var var = type.getVarName();
        SchemaConcept t = type.getSchemaConcept();
        if (t.subs().noneMatch(sub -> sub.equals(answer.get(var).asThing().type()))) {
            return false;
        }
    }
    return true;
}
Also used : Var(ai.grakn.graql.Var) TypeAtom(ai.grakn.graql.internal.reasoner.atom.binary.TypeAtom) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 42 with SchemaConcept

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

the class ReasonerUtils method upstreamHierarchy.

/**
 * @param concept which hierarchy should be considered
 * @return set of {@link SchemaConcept}s consisting of the provided {@link SchemaConcept} and all its supers including meta
 */
public static Set<SchemaConcept> upstreamHierarchy(SchemaConcept concept) {
    Set<SchemaConcept> concepts = new HashSet<>();
    SchemaConcept superType = concept;
    while (superType != null) {
        concepts.add(superType);
        superType = superType.sup();
    }
    return concepts;
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) HashSet(java.util.HashSet)

Example 43 with SchemaConcept

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

the class RemoteConceptsTest method whenCallingSup_GetTheExpectedResult.

@Test
public void whenCallingSup_GetTheExpectedResult() {
    SchemaConcept sup = RemoteConcepts.createEntityType(tx, A);
    mockConceptMethod(GET_DIRECT_SUPER, Optional.of(sup));
    assertEquals(sup, entityType.sup());
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

Example 44 with SchemaConcept

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

the class SchemaConceptPropertyTest method whenAddingADirectSubWhichIsAnIndirectSuper_Throw.

// TODO
@Ignore("Test fails due to incorrect error message")
@Property
public void whenAddingADirectSubWhichIsAnIndirectSuper_Throw(@NonMeta SchemaConcept newSubConcept, long seed) {
    SchemaConcept concept = PropertyUtil.choose(newSubConcept.subs(), seed);
    // Check if the mutation can be performed in a valid manner
    if (concept.isType())
        assumeThat(concept.asType().plays().collect(Collectors.toSet()), is(empty()));
    exception.expect(GraknTxOperationException.class);
    exception.expectMessage(GraknTxOperationException.loopCreated(newSubConcept, concept).getMessage());
    addDirectSub(concept, newSubConcept);
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Ignore(org.junit.Ignore) Property(com.pholser.junit.quickcheck.Property)

Example 45 with SchemaConcept

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

the class TypePropertyTest method whenAddingAPlaysToATypesIndirectSuperType_TheTypePlaysThatRole.

@Property
public void whenAddingAPlaysToATypesIndirectSuperType_TheTypePlaysThatRole(@Open GraknTx tx, @FromTx Type type, @FromTx Role role, long seed) {
    SchemaConcept superConcept = PropertyUtil.choose(tx.admin().sups(type), seed);
    assumeTrue(superConcept.isType());
    assumeFalse(isMetaLabel(superConcept.getLabel()));
    Type superType = superConcept.asType();
    Set<Role> previousPlays = type.plays().collect(toSet());
    superType.plays(role);
    Set<Role> newPlays = type.plays().collect(toSet());
    assertEquals(newPlays, Sets.union(previousPlays, ImmutableSet.of(role)));
}
Also used : Role(ai.grakn.concept.Role) Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) SchemaConcept(ai.grakn.concept.SchemaConcept) Property(com.pholser.junit.quickcheck.Property)

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