/** * @param concept which hierarchy should be considered * @return set of {@link SchemaConcept}s consisting of the provided {@link SchemaConcept} and all its supers including meta */ public static Set<SchemaConcept> upstreamHierarchy(SchemaConcept concept){ Set<SchemaConcept> concepts = new HashSet<>(); SchemaConcept superType = concept; while(superType != null) { concepts.add(superType); superType = superType.sup(); } return concepts; }
@Override public final Stream<SchemaConcept> sups(SchemaConcept schemaConcept) { Set<SchemaConcept> superSet = new HashSet<>(); while (schemaConcept != null) { superSet.add(schemaConcept); schemaConcept = schemaConcept.sup(); } return superSet.stream(); }
private boolean superLoops(){ //Check For Loop HashSet<SchemaConcept> foundTypes = new HashSet<>(); SchemaConcept currentSuperType = sup(); while (currentSuperType != null){ foundTypes.add(currentSuperType); currentSuperType = currentSuperType.sup(); if(foundTypes.contains(currentSuperType)){ return true; } } return false; }
/** * @param schemaConcept input type * @return set of all non-meta super types of the role */ public static Set<SchemaConcept> supers(SchemaConcept schemaConcept){ Set<SchemaConcept> superTypes = new HashSet<>(); SchemaConcept superType = schemaConcept.sup(); while(superType != null && !Schema.MetaSchema.isMetaLabel(superType.label())) { superTypes.add(superType); superType = superType.sup(); } return superTypes; }
@Override public Stream<T> sups() { Set<T> superSet= new HashSet<>(); T superParent = getThis(); while(superParent != null && !Schema.MetaSchema.THING.getLabel().equals(superParent.label())){ superSet.add(superParent); //noinspection unchecked superParent = (T) superParent.sup(); } return superSet.stream(); }
/** * @param parent type * @param child type * @return true if child is a subtype of parent */ public static boolean typesCompatible(SchemaConcept parent, SchemaConcept child) { if (parent == null) return true; if (child == null) return false; if (Schema.MetaSchema.isMetaLabel(parent.label())) return true; SchemaConcept superType = child; while(superType != null && !Schema.MetaSchema.isMetaLabel(superType.label())){ if (superType.equals(parent)) return true; superType = superType.sup(); } return false; }
output.append(colorKeyword("label ")).append(colorType(ontoConcept)); SchemaConcept superConcept = ontoConcept.sup();
/** * 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; }
@Override public Collection<PropertyExecutor> undefine(Var var) throws GraqlQueryException { PropertyExecutor.Method method = executor -> { SchemaConcept concept = executor.get(var).asSchemaConcept(); SchemaConcept expectedSuperConcept = executor.get(superType().var()).asSchemaConcept(); SchemaConcept actualSuperConcept = concept.sup(); if (!concept.isDeleted() && expectedSuperConcept.equals(actualSuperConcept)) { concept.delete(); } }; return ImmutableSet.of(PropertyExecutor.builder(method).requires(var, superType().var()).build()); }
@Override protected Json concept(Concept concept) { Json json = Json.object("id", concept.id().getValue()); if (concept.isSchemaConcept()) { json.set("name", concept.asSchemaConcept().label().getValue()); SchemaConcept superConcept = concept.asSchemaConcept().sup(); if (superConcept != null) json.set("sub", superConcept.label().getValue()); } else if (concept.isThing()) { json.set("isa", concept.asThing().type().label().getValue()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } if (concept.isAttribute()) { json.set("value", concept.asAttribute().value()); } if (concept.isRule()) { Pattern when = concept.asRule().when(); if (when != null) { json.set("when", when.toString()); } Pattern then = concept.asRule().then(); if (then != null) { json.set("then", then.toString()); } } return json; }