private static VarPattern createIdVar(Var varName, Label label, GraknTx graph){ SchemaConcept schemaConcept = graph.getSchemaConcept(label); if (schemaConcept == null) throw GraqlQueryException.labelNotFound(label); return varName.id(schemaConcept.id()); }
@Override public RelationshipAtom addType(SchemaConcept type) { if (getTypeId() != null) return this; //NB: do not cache possible types return create(this.getPattern(), this.getPredicateVariable(), type.id(), this.getParentQuery()); }
public static IsaAtom create(Var var, Var predicateVar, SchemaConcept type, boolean isDirect, ReasonerQuery parent) { VarPatternAdmin pattern = isDirect ? var.isaExplicit(predicateVar).admin() : var.isa(predicateVar).admin(); return new AutoValue_IsaAtom(var, type.id(), predicateVar, pattern, parent); } private static IsaAtom create(IsaAtom a, ReasonerQuery parent) {
@Override public Stream<SchemaConcept> sups(SchemaConcept schemaConcept) { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setSchemaConceptSupsReq(ConceptProto.SchemaConcept.Sups.Req.getDefaultInstance()).build(); SessionProto.Transaction.Res response = runConceptMethod(schemaConcept.id(), method); int iteratorId = response.getConceptMethodRes().getResponse().getSchemaConceptSupsIter().getId(); Iterable<? extends Concept> iterable = () -> new Iterator<>( this, iteratorId, res -> RemoteConcept.of(res.getConceptMethodIterRes().getSchemaConceptSupsIterRes().getSchemaConcept(), this) ); Stream<? extends Concept> sups = StreamSupport.stream(iterable.spliterator(), false); return Objects.requireNonNull(sups).map(Concept::asSchemaConcept); }
@Override public IsaAtom addType(SchemaConcept type) { if (getTypeId() != null) return this; return create(getVarName(), getPredicateVariable(), type.id(), this.isDirect(), this.getParentQuery()); }
@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.id() : null; //isa part VarPatternAdmin resVar = varName.has(Graql.label(label)).admin(); return HasAtom.create(resVar, predicateVar, predicateId, parent); } }
@Override public RelationshipAtom toRelationshipAtom(){ SchemaConcept type = getSchemaConcept(); if (type == null) throw GraqlQueryException.illegalAtomConversion(this, RelationshipAtom.class); GraknTx tx = getParentQuery().tx(); Label typeLabel = Schema.ImplicitType.HAS.getLabel(type.label()); return RelationshipAtom.create( Graql.var() .rel(Schema.ImplicitType.HAS_OWNER.getLabel(type.label()).getValue(), getVarName()) .rel(Schema.ImplicitType.HAS_VALUE.getLabel(type.label()).getValue(), getPredicateVariable()) .isa(typeLabel.getValue()) .admin(), getPredicateVariable(), tx.getSchemaConcept(typeLabel).id(), getParentQuery() ); }