use of ai.grakn.graql.admin.VarPatternAdmin 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.VarPatternAdmin in project grakn by graknlabs.
the class MatchInfer method stream.
@Override
public Stream<Answer> stream(Optional<EmbeddedGraknTx<?>> optionalGraph) {
// If the tx is not embedded, treat it like there is no transaction
// TODO: this is dodgy - when queries don't contain transactions this can be fixed
EmbeddedGraknTx<?> tx = optionalOr(optionalGraph, inner.tx().filter(t -> t instanceof EmbeddedGraknTx).map(t -> (EmbeddedGraknTx<?>) t)).orElseThrow(GraqlQueryException::noTx);
if (!RuleUtils.hasRules(tx))
return inner.stream(optionalGraph);
validatePattern(tx);
try {
Iterator<Conjunction<VarPatternAdmin>> conjIt = getPattern().getDisjunctiveNormalForm().getPatterns().iterator();
Conjunction<VarPatternAdmin> conj = conjIt.next();
ReasonerQuery conjQuery = ReasonerQueries.create(conj, tx);
conjQuery.checkValid();
Stream<Answer> answerStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
while (conjIt.hasNext()) {
conj = conjIt.next();
conjQuery = ReasonerQueries.create(conj, tx);
Stream<Answer> localStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
answerStream = Stream.concat(answerStream, localStream);
}
return answerStream.map(result -> result.project(getSelectedNames()));
} catch (GraqlQueryException e) {
System.err.println(e.getMessage());
return Stream.empty();
}
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class RelatesProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
Var varName = var.var().asUserDefined();
VarPatternAdmin roleVar = this.role();
Var roleVariable = roleVar.var().asUserDefined();
IdPredicate predicate = getIdPredicate(roleVariable, roleVar, vars, parent);
ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
return RelatesAtom.create(varName, roleVariable, predicateId, parent);
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class HasAttributeTypeProperty method of.
/**
* @throws GraqlQueryException if no label is specified on {@code resourceType}
*/
public static HasAttributeTypeProperty of(VarPatternAdmin resourceType, boolean required) {
Label resourceLabel = resourceType.getTypeLabel().orElseThrow(() -> GraqlQueryException.noLabelSpecifiedForHas(resourceType));
VarPattern role = Graql.label(Schema.MetaSchema.ROLE.getLabel());
VarPatternAdmin ownerRole = var().sub(role).admin();
VarPatternAdmin valueRole = var().sub(role).admin();
VarPattern relationType = var().sub(Graql.label(Schema.MetaSchema.RELATIONSHIP.getLabel()));
// If a key, limit only to the implicit key type
if (required) {
ownerRole = ownerRole.label(KEY_OWNER.getLabel(resourceLabel)).admin();
valueRole = valueRole.label(KEY_VALUE.getLabel(resourceLabel)).admin();
relationType = relationType.label(KEY.getLabel(resourceLabel));
}
VarPatternAdmin relationOwner = relationType.relates(ownerRole).admin();
VarPatternAdmin relationValue = relationType.admin().var().relates(valueRole).admin();
return new AutoValue_HasAttributeTypeProperty(resourceType, ownerRole, valueRole, relationOwner, relationValue, required);
}
use of ai.grakn.graql.admin.VarPatternAdmin in project grakn by graknlabs.
the class HasAttributeTypeProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
// NB: HasResourceType is a special case and it doesn't allow variables as resource types
Var varName = var.var().asUserDefined();
Label label = this.resourceType().getTypeLabel().orElse(null);
Var predicateVar = var().asUserDefined();
SchemaConcept schemaConcept = parent.tx().getSchemaConcept(label);
ConceptId predicateId = schemaConcept != null ? schemaConcept.getId() : null;
// isa part
VarPatternAdmin resVar = varName.has(Graql.label(label)).admin();
return HasAtom.create(resVar, predicateVar, predicateId, parent);
}
Aggregations