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;
}
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;
}
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());
}
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);
}
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)));
}
Aggregations