Search in sources :

Example 1 with Type

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));
}
Also used : Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 2 with Type

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));
}
Also used : EntityType(ai.grakn.concept.EntityType) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) GraknTxType(ai.grakn.GraknTxType) Test(org.junit.Test)

Example 3 with Type

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;
}
Also used : AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Type(ai.grakn.concept.Type) VarPattern(ai.grakn.graql.VarPattern) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 4 with Type

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;
}
Also used : Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) ValuePredicate(ai.grakn.graql.internal.reasoner.atom.predicate.ValuePredicate) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl)

Example 5 with Type

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());
}
Also used : Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) AttributeType(ai.grakn.concept.AttributeType) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Type (ai.grakn.concept.Type)47 RelationshipType (ai.grakn.concept.RelationshipType)28 AttributeType (ai.grakn.concept.AttributeType)25 Test (org.junit.Test)23 EntityType (ai.grakn.concept.EntityType)21 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Label (ai.grakn.concept.Label)15 Set (java.util.Set)15 GraknTx (ai.grakn.GraknTx)14 Concept (ai.grakn.concept.Concept)13 Collectors (java.util.stream.Collectors)13 Role (ai.grakn.concept.Role)12 ConceptId (ai.grakn.concept.ConceptId)11 Schema (ai.grakn.util.Schema)10 HashSet (java.util.HashSet)10 Stream (java.util.stream.Stream)10 GraqlQueryException (ai.grakn.exception.GraqlQueryException)9 Map (java.util.Map)9 Answer (ai.grakn.graql.admin.Answer)8 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)8