Search in sources :

Example 21 with VarPatternAdmin

use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.

the class RelatesProperty method match.

@Override
public Collection<EquivalentFragmentSet> match(Var start) {
    VarPatternAdmin superRole = superRole();
    EquivalentFragmentSet relates = relates(this, start, role().var());
    if (superRole == null) {
        return ImmutableSet.of(relates);
    } else {
        return ImmutableSet.of(relates, sub(this, role().var(), superRole.var()));
    }
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet)

Example 22 with VarPatternAdmin

use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.

the class RelatesProperty method define.

@Override
public Collection<PropertyExecutor> define(Var var) throws GraqlQueryException {
    Var roleVar = role().var();
    PropertyExecutor.Method relatesMethod = executor -> {
        Role role = executor.get(roleVar).asRole();
        executor.get(var).asRelationshipType().relates(role);
    };
    PropertyExecutor relatesExecutor = PropertyExecutor.builder(relatesMethod).requires(var, roleVar).build();
    // This allows users to skip stating `$roleVar sub role` when they say `$var relates $roleVar`
    PropertyExecutor.Method isRoleMethod = executor -> executor.builder(roleVar).isRole();
    PropertyExecutor isRoleExecutor = PropertyExecutor.builder(isRoleMethod).produces(roleVar).build();
    VarPatternAdmin superRoleVarPattern = superRole();
    if (superRoleVarPattern != null) {
        Var superRoleVar = superRoleVarPattern.var();
        PropertyExecutor.Method subMethod = executor -> {
            Role superRole = executor.get(superRoleVar).asRole();
            executor.builder(roleVar).sub(superRole);
        };
        PropertyExecutor subExecutor = PropertyExecutor.builder(subMethod).requires(superRoleVar).produces(roleVar).build();
        return ImmutableSet.of(relatesExecutor, isRoleExecutor, subExecutor);
    } else {
        return ImmutableSet.of(relatesExecutor, isRoleExecutor);
    }
}
Also used : GraqlQueryException(ai.grakn.exception.GraqlQueryException) ImmutableSet(com.google.common.collect.ImmutableSet) Role(ai.grakn.concept.Role) Collection(java.util.Collection) Set(java.util.Set) IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) EquivalentFragmentSets.sub(ai.grakn.graql.internal.gremlin.sets.EquivalentFragmentSets.sub) EquivalentFragmentSets.relates(ai.grakn.graql.internal.gremlin.sets.EquivalentFragmentSets.relates) Atomic(ai.grakn.graql.admin.Atomic) ReasonerQuery(ai.grakn.graql.admin.ReasonerQuery) Stream(java.util.stream.Stream) RelationshipType(ai.grakn.concept.RelationshipType) Var(ai.grakn.graql.Var) AutoValue(com.google.auto.value.AutoValue) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) RelatesAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelatesAtom) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Nullable(javax.annotation.Nullable) Role(ai.grakn.concept.Role) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var)

Example 23 with VarPatternAdmin

use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.

the class AbstractVarPattern method innerVarPatterns.

@Override
public final Collection<VarPatternAdmin> innerVarPatterns() {
    Stack<VarPatternAdmin> newVars = new Stack<>();
    List<VarPatternAdmin> vars = new ArrayList<>();
    newVars.add(this);
    while (!newVars.isEmpty()) {
        VarPatternAdmin var = newVars.pop();
        vars.add(var);
        var.getProperties().flatMap(VarProperty::innerVarPatterns).forEach(newVars::add);
    }
    return vars;
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) ArrayList(java.util.ArrayList) Stack(java.util.Stack)

Example 24 with VarPatternAdmin

use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.

the class DefineQueryPropertyTest method aDefineQueryWithoutASubOrPlaysOrRelatesProperty_CannotBeInserted.

@Ignore("Currently no error message is returned when trying to insert an empty set of propoerties. I am not entirely sure this is correct")
@Property
public void aDefineQueryWithoutASubOrPlaysOrRelatesProperty_CannotBeInserted(@Open GraknTx tx, @Size(max = 5) Set<VarProperty> properties) {
    boolean containsSub = properties.stream().anyMatch(SubProperty.class::isInstance);
    boolean containsPlays = properties.stream().anyMatch(PlaysProperty.class::isInstance);
    boolean containsRelates = properties.stream().anyMatch(RelatesProperty.class::isInstance);
    assumeFalse(containsSub || containsPlays || containsRelates);
    VarPatternAdmin pattern = Patterns.varPattern(Graql.var("x"), properties);
    exception.expect(GraqlQueryException.class);
    tx.graql().define(pattern).execute();
}
Also used : RelatesProperty(ai.grakn.graql.internal.pattern.property.RelatesProperty) SubProperty(ai.grakn.graql.internal.pattern.property.SubProperty) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) PlaysProperty(ai.grakn.graql.internal.pattern.property.PlaysProperty) Ignore(org.junit.Ignore) Property(com.pholser.junit.quickcheck.Property) SubProperty(ai.grakn.graql.internal.pattern.property.SubProperty) VarProperty(ai.grakn.graql.admin.VarProperty) PlaysProperty(ai.grakn.graql.internal.pattern.property.PlaysProperty) RelatesProperty(ai.grakn.graql.internal.pattern.property.RelatesProperty)

Example 25 with VarPatternAdmin

use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.

the class HasAttributeProperties method generate.

@Override
public HasAttributeProperty generate() {
    VarPatternAdmin varPatternAttribute;
    VarPatternAdmin varPatternRelationship;
    // `HasAttributeProperty` will implicitly attach an `IsaProperty`, so must not clash
    do {
        varPatternAttribute = gen(VarPatternAdmin.class);
    } while (varPatternAttribute.hasProperty(IsaProperty.class) || varPatternAttribute.hasProperty(DirectIsaProperty.class));
    do {
        varPatternRelationship = gen(VarPatternAdmin.class);
    } while (varPatternRelationship.hasProperty(IsaProperty.class) || varPatternRelationship.hasProperty(DirectIsaProperty.class));
    return HasAttributeProperty.of(gen(Label.class), varPatternAttribute, varPatternRelationship);
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) IsaProperty(ai.grakn.graql.internal.pattern.property.IsaProperty) DirectIsaProperty(ai.grakn.graql.internal.pattern.property.DirectIsaProperty) Label(ai.grakn.concept.Label) DirectIsaProperty(ai.grakn.graql.internal.pattern.property.DirectIsaProperty)

Aggregations

VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)55 Test (org.junit.Test)20 Var (ai.grakn.graql.Var)17 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)17 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)16 Unifier (ai.grakn.graql.admin.Unifier)15 ConceptId (ai.grakn.concept.ConceptId)13 Label (ai.grakn.concept.Label)13 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)13 Role (ai.grakn.concept.Role)11 GraknTx (ai.grakn.GraknTx)10 VarProperty (ai.grakn.graql.admin.VarProperty)10 Collection (java.util.Collection)10 Set (java.util.Set)10 Stream (java.util.stream.Stream)10 SchemaConcept (ai.grakn.concept.SchemaConcept)9 GraqlQueryException (ai.grakn.exception.GraqlQueryException)9 VarPattern (ai.grakn.graql.VarPattern)9 ReasonerQuery (ai.grakn.graql.admin.ReasonerQuery)9 RelationPlayer (ai.grakn.graql.admin.RelationPlayer)9