@Nullable @Override public <T extends Type> T getType(Label label) { SchemaConcept concept = getSchemaConcept(label); if (concept == null || !concept.isType()) return null; return (T) concept.asType(); }
@Override public Long getShardCount(EmbeddedGraknTx<?> tx) { return labels().stream() .map(tx::<SchemaConcept>getSchemaConcept) .filter(schemaConcept -> schemaConcept != null && schemaConcept.isType()) .flatMap(SchemaConcept::subs) .mapToLong(schemaConcept -> tx.getShardCount(schemaConcept.asType())) .sum(); } }
private Map<Var, Type> getVarTypeMap(Stream<IsaAtomBase> isas){ HashMap<Var, Type> map = new HashMap<>(); isas .map(at -> new Pair<>(at.getVarName(), at.getSchemaConcept())) .filter(p -> Objects.nonNull(p.getValue())) .filter(p -> p.getValue().isType()) .forEach(p -> { Var var = p.getKey(); Type newType = p.getValue().asType(); Type type = map.get(var); if (type == null) map.put(var, newType); else { boolean isSubType = type.subs().anyMatch(t -> t.equals(newType)); if (isSubType) map.put(var, newType); } }); return map; }
@Override public final void checkValidProperty(GraknTx graph, VarPatternAdmin var) throws GraqlQueryException { type().getTypeLabel().ifPresent(typeLabel -> { SchemaConcept theSchemaConcept = graph.getSchemaConcept(typeLabel); if (theSchemaConcept != null && !theSchemaConcept.isType()) { throw GraqlQueryException.cannotGetInstancesOfNonType(typeLabel); } }); }
/** * Create a var with the information underlying all Types * @param schemaConcept type to be mapped * @return {@link VarPattern} containing basic information about the given type */ private static VarPattern formatBase(SchemaConcept schemaConcept) { VarPattern var = var().label(schemaConcept.label()); SchemaConcept superType = schemaConcept.sup(); if (schemaConcept.sup() != null) { var = var.sub(Graql.label(superType.label())); } if(schemaConcept.isType()) { Type type = schemaConcept.asType(); var = plays(var, type); var = isAbstract(var, type); } return var; }