@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; }
private static Map<Var, Type> getLabelVarTypeMap(EmbeddedGraknTx<?> tx, Set<Fragment> allFragments) { Map<Var, Type> labelVarTypeMap = new HashMap<>(); allFragments.stream() .filter(LabelFragment.class::isInstance) .forEach(fragment -> { // TODO: labels() should return ONE label instead of a set SchemaConcept schemaConcept = tx.getSchemaConcept( Iterators.getOnlyElement(((LabelFragment) fragment).labels().iterator())); if (schemaConcept != null && !schemaConcept.isRole() && !schemaConcept.isRule()) { labelVarTypeMap.put(fragment.start(), schemaConcept.asType()); } }); return labelVarTypeMap; }
/** * 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; }