Search in sources :

Example 16 with VarPatternAdmin

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

the class ValuePredicate method getVarNames.

@Override
public Set<Var> getVarNames() {
    Set<Var> vars = super.getVarNames();
    VarPatternAdmin innerVar = getPredicate().getInnerVar().orElse(null);
    if (innerVar != null && innerVar.var().isUserDefinedName())
        vars.add(innerVar.var());
    return vars;
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var)

Example 17 with VarPatternAdmin

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

the class HasAttributeProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    // NB: HasAttributeProperty always has (type) label specified
    Var varName = var.var().asUserDefined();
    Var relationVariable = relationship().var();
    Var attributeVariable = attribute().var().asUserDefined();
    Set<ValuePredicate> predicates = getValuePredicates(attributeVariable, attribute(), vars, parent);
    IsaProperty isaProp = attribute().getProperties(IsaProperty.class).findFirst().orElse(null);
    VarPatternAdmin typeVar = isaProp != null ? isaProp.type() : null;
    IdPredicate predicate = typeVar != null ? getIdPredicate(attributeVariable, typeVar, vars, parent) : null;
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    // add resource atom
    VarPatternAdmin resVar = relationVariable.isUserDefinedName() ? varName.has(type(), attributeVariable, relationVariable).admin() : varName.has(type(), attributeVariable).admin();
    return ResourceAtom.create(resVar, attributeVariable, relationVariable, predicateId, predicates, parent);
}
Also used : ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ValuePredicate(ai.grakn.graql.internal.reasoner.atom.predicate.ValuePredicate) ConceptId(ai.grakn.concept.ConceptId)

Example 18 with VarPatternAdmin

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

the class PlaysProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    Var varName = var.var().asUserDefined();
    VarPatternAdmin typeVar = this.role();
    Var typeVariable = typeVar.var().asUserDefined();
    IdPredicate predicate = getIdPredicate(typeVariable, typeVar, vars, parent);
    ConceptId predicateId = predicate == null ? null : predicate.getPredicate();
    return PlaysAtom.create(varName, typeVariable, predicateId, parent);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId)

Example 19 with VarPatternAdmin

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

the class RelationshipProperty method checkValidProperty.

@Override
public void checkValidProperty(GraknTx graph, VarPatternAdmin var) throws GraqlQueryException {
    Set<Label> roleTypes = relationPlayers().stream().map(RelationPlayer::getRole).flatMap(CommonUtil::optionalToStream).map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).collect(toSet());
    Optional<Label> maybeLabel = var.getProperty(IsaProperty.class).map(IsaProperty::type).flatMap(VarPatternAdmin::getTypeLabel);
    maybeLabel.ifPresent(label -> {
        SchemaConcept schemaConcept = graph.getSchemaConcept(label);
        if (schemaConcept == null || !schemaConcept.isRelationshipType()) {
            throw GraqlQueryException.notARelationType(label);
        }
    });
    // Check all role types exist
    roleTypes.forEach(roleId -> {
        SchemaConcept schemaConcept = graph.getSchemaConcept(roleId);
        if (schemaConcept == null || !schemaConcept.isRole()) {
            throw GraqlQueryException.notARoleType(roleId);
        }
    });
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) RelationPlayer(ai.grakn.graql.admin.RelationPlayer)

Example 20 with VarPatternAdmin

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

the class RelatesProperty method buildString.

@Override
public void buildString(StringBuilder builder) {
    VarPatternAdmin superRole = superRole();
    builder.append("relates").append(" ").append(role().getPrintableName());
    if (superRole != null) {
        builder.append(" as ").append(superRole.getPrintableName());
    }
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin)

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