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