use of ai.grakn.concept.Type in project grakn by graknlabs.
the class RoleTest method whenGettingTypeEntityTypesAllowedToPlayARole_ReturnTheEntityTypes.
@Test
public void whenGettingTypeEntityTypesAllowedToPlayARole_ReturnTheEntityTypes() {
Type type1 = tx.putEntityType("CT1").plays(role);
Type type2 = tx.putEntityType("CT2").plays(role);
Type type3 = tx.putEntityType("CT3").plays(role);
Type type4 = tx.putEntityType("CT4").plays(role);
assertThat(role.playedByTypes().collect(toSet()), containsInAnyOrder(type1, type2, type3, type4));
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class TxCacheTest method whenMutatingSuperTypeOfConceptCreatedInAnotherTransaction_EnsureTransactionBoundConceptIsMutated.
@Test
public void whenMutatingSuperTypeOfConceptCreatedInAnotherTransaction_EnsureTransactionBoundConceptIsMutated() {
EntityType e1 = tx.putEntityType("e1");
EntityType e2 = tx.putEntityType("e2").sup(e1);
EntityType e3 = tx.putEntityType("e3");
tx.commit();
// Check everything is okay
tx = session.open(GraknTxType.WRITE);
assertTxBoundConceptMatches(e2, Type::sup, is(e1));
// Mutate Super Type
e2.sup(e3);
assertTxBoundConceptMatches(e2, Type::sup, is(e3));
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class SchemaConceptMapper method formatBase.
/**
* Create a var with the information underlying all Types
* @param schemaConcept type to be mapped
* @return {@link VarPattern} containing basic information about the given type
*/
private static VarPattern formatBase(SchemaConcept schemaConcept) {
VarPattern var = var().label(schemaConcept.getLabel());
SchemaConcept superType = schemaConcept.sup();
if (schemaConcept.sup() != null) {
var = var.sub(Graql.label(superType.getLabel()));
}
if (schemaConcept.isType()) {
Type type = schemaConcept.asType();
var = plays(var, type);
var = isAbstract(var, type);
}
return var;
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class ResourceAtom method isRuleApplicableViaAtom.
@Override
public boolean isRuleApplicableViaAtom(Atom ruleAtom) {
// findbugs complains about cast without it
if (!(ruleAtom instanceof ResourceAtom))
return false;
ResourceAtom childAtom = (ResourceAtom) ruleAtom;
ReasonerQueryImpl childQuery = (ReasonerQueryImpl) childAtom.getParentQuery();
// check type bindings compatiblity
Type parentType = this.getParentQuery().getVarTypeMap().get(this.getVarName());
Type childType = childQuery.getVarTypeMap().get(childAtom.getVarName());
if (parentType != null && childType != null && areDisjointTypes(parentType, childType) || !childQuery.isTypeRoleCompatible(ruleAtom.getVarName(), parentType))
return false;
// check value predicate compatibility
if (childAtom.getMultiPredicate().isEmpty() || getMultiPredicate().isEmpty())
return true;
for (ValuePredicate childPredicate : childAtom.getMultiPredicate()) {
Iterator<ValuePredicate> parentIt = getMultiPredicate().iterator();
boolean predicateCompatible = false;
while (parentIt.hasNext() && !predicateCompatible) {
ValuePredicate parentPredicate = parentIt.next();
predicateCompatible = parentPredicate.isCompatibleWith(childPredicate);
}
if (!predicateCompatible)
return false;
}
return true;
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class GraknTxPutPropertyTest method whenCallingAnyPutTypeMethod_CreateATypeWithDefaultProperties.
@Property
public void whenCallingAnyPutTypeMethod_CreateATypeWithDefaultProperties(@Open GraknTx graph, @Unused Label label, @From(PutTypeFunctions.class) BiFunction<GraknTx, Label, Type> putType) {
Type type = putType.apply(graph, label);
assertThat("Type should not play any roles", type.plays().collect(toSet()), empty());
assertFalse("Type should not be abstract", type.isAbstract());
}
Aggregations