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