Search in sources :

Example 1 with HasAttributeProperty

use of ai.grakn.graql.internal.pattern.property.HasAttributeProperty 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();
}
Also used : VarProperty(ai.grakn.graql.admin.VarProperty) Logger(org.slf4j.Logger) VarPattern(ai.grakn.graql.VarPattern) LabelProperty(ai.grakn.graql.internal.pattern.property.LabelProperty) HasAttributeProperty(ai.grakn.graql.internal.pattern.property.HasAttributeProperty) Collection(java.util.Collection) Var(ai.grakn.graql.Var) AutoValue(com.google.auto.value.AutoValue) LoggerFactory(org.slf4j.LoggerFactory) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Set(java.util.Set) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) VarProperty(ai.grakn.graql.admin.VarProperty) HasAttributeProperty(ai.grakn.graql.internal.pattern.property.HasAttributeProperty)

Aggregations

Var (ai.grakn.graql.Var)1 VarPattern (ai.grakn.graql.VarPattern)1 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)1 VarProperty (ai.grakn.graql.admin.VarProperty)1 HasAttributeProperty (ai.grakn.graql.internal.pattern.property.HasAttributeProperty)1 LabelProperty (ai.grakn.graql.internal.pattern.property.LabelProperty)1 AutoValue (com.google.auto.value.AutoValue)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1