use of ai.grakn.graql.admin.VarProperty in project grakn by graknlabs.
the class GraqlTraversalPlanner method planFromTraversal.
/**
* @param atoms list of current atoms of interest
* @param queryPattern corresponding pattern
* @return an optimally ordered list of provided atoms
*/
static ImmutableList<Atom> planFromTraversal(List<Atom> atoms, PatternAdmin queryPattern, EmbeddedGraknTx<?> tx) {
Multimap<VarProperty, Atom> propertyMap = HashMultimap.create();
atoms.stream().filter(at -> !(at instanceof OntologicalAtom)).forEach(at -> at.getVarProperties().forEach(p -> propertyMap.put(p, at)));
Set<VarProperty> properties = propertyMap.keySet();
GraqlTraversal graqlTraversal = GreedyTraversalPlan.createTraversal(queryPattern, tx);
ImmutableList<Fragment> fragments = graqlTraversal.fragments().iterator().next();
ImmutableList.Builder<Atom> builder = ImmutableList.builder();
builder.addAll(atoms.stream().filter(at -> at instanceof OntologicalAtom).iterator());
builder.addAll(fragments.stream().map(Fragment::varProperty).filter(Objects::nonNull).filter(properties::contains).distinct().flatMap(p -> propertyMap.get(p).stream()).distinct().iterator());
return builder.build();
}
use of ai.grakn.graql.admin.VarProperty in project grakn by graknlabs.
the class VarPatternImpl method toString.
@Override
public final String toString() {
Collection<VarPatternAdmin> innerVars = innerVarPatterns();
innerVars.remove(this);
getProperties(HasAttributeProperty.class).map(HasAttributeProperty::attribute).flatMap(r -> r.innerVarPatterns().stream()).forEach(innerVars::remove);
if (innerVars.stream().anyMatch(VarPatternImpl::invalidInnerVariable)) {
LOG.warn("printing a query with inner variables, which is not supported in native Graql");
}
StringBuilder builder = new StringBuilder();
String name = var().isUserDefinedName() ? var().toString() : "";
builder.append(name);
if (var().isUserDefinedName() && !properties().isEmpty()) {
// Add a space after the var name
builder.append(" ");
}
boolean first = true;
for (VarProperty property : properties()) {
if (!first) {
builder.append(" ");
}
first = false;
property.buildString(builder);
}
return builder.toString();
}
use of ai.grakn.graql.admin.VarProperty 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.VarProperty in project grakn by graknlabs.
the class PatternPropertyTests method patternsWithDifferentVariablesAndTheSameProperties_ShouldNotBeEquivalent.
@Property
public void patternsWithDifferentVariablesAndTheSameProperties_ShouldNotBeEquivalent(Var var1, Var var2, Set<VarProperty> properties) {
assumeThat(var1, not(is(var2)));
VarPatternAdmin varPattern1 = Patterns.varPattern(var1, properties);
VarPatternAdmin varPattern2 = Patterns.varPattern(var2, properties);
assertNotEquals(varPattern1, varPattern2);
}
use of ai.grakn.graql.admin.VarProperty in project grakn by graknlabs.
the class InsertQueryPropertyTest method anInsertQueryWithoutAnIsaProperty_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 anInsertQueryWithoutAnIsaProperty_CannotBeInserted(@Open GraknTx tx, @Size(max = 5) Set<VarProperty> properties) {
boolean containsIsa = properties.stream().anyMatch(IsaProperty.class::isInstance);
assumeFalse(containsIsa);
VarPatternAdmin pattern = Patterns.varPattern(Graql.var("x"), properties);
exception.expect(GraqlQueryException.class);
tx.graql().insert(pattern).execute();
}
Aggregations