/** * Throws an exception when adding a {@link SchemaConcept} using a {@link Label} which is already taken */ private GraknTxOperationException labelTaken(SchemaConcept schemaConcept) { if (Schema.MetaSchema.isMetaLabel(schemaConcept.label())) { return GraknTxOperationException.reservedLabel(schemaConcept.label()); } return PropertyNotUniqueException.cannotCreateProperty(schemaConcept, Schema.VertexProperty.SCHEMA_LABEL, schemaConcept.label()); }
/** * Caches a concept so it does not have to be rebuilt later. * * @param concept The concept to be cached. */ public void cacheConcept(Concept concept){ conceptCache.put(concept.id(), concept); if(concept.isSchemaConcept()){ SchemaConcept schemaConcept = concept.asSchemaConcept(); schemaConceptCache.put(schemaConcept.label(), schemaConcept); labelCache.put(schemaConcept.label(), schemaConcept.labelId()); } }
/** * Thrown when setting {@code superType} as the super type of {@code type} and a loop is created */ public static GraknTxOperationException loopCreated(SchemaConcept type, SchemaConcept superElement){ return create(ErrorMessage.SUPER_LOOP_DETECTED.getMessage(type.label(), superElement.label())); }
/** * Copies the {@link SchemaConcept} and it's subs into the {@link TxCache}. * This is important as lookups for {@link SchemaConcept}s based on {@link Label} depend on this caching. * * @param schemaConcept the {@link SchemaConcept} to be copied into the {@link TxCache} */ private void copyToCache(SchemaConcept schemaConcept) { schemaConcept.subs().forEach(concept -> { getGlobalCache().cacheLabel(concept.label(), concept.labelId()); getGlobalCache().cacheType(concept.label(), concept); }); }
/** * @param schemaConcepts entry {@link SchemaConcept} set * @return top {@link SchemaConcept}s from within the provided set or meta concept if it exists */ public static <T extends SchemaConcept> Set<T> topOrMeta(Set<T> schemaConcepts) { Set<T> concepts = top(schemaConcepts); T meta = concepts.stream() .filter(c -> Schema.MetaSchema.isMetaLabel(c.label())) .findFirst().orElse(null); return meta != null ? Collections.singleton(meta) : concepts; }
private Set<SchemaConcept> getTypes(SchemaConcept type, boolean direct) { Set<SchemaConcept> types = direct ? Sets.newHashSet(type) : type.subs().collect(Collectors.toSet()); return type.isImplicit()? types.stream().flatMap(t -> Stream.of(t, tx.getSchemaConcept(Schema.ImplicitType.explicitLabel(t.label())))).collect(Collectors.toSet()): types; }
/** * Color-codes the given type if colorization enabled * @param schemaConcept a type to color-code using ANSI colors * @return the type, color-coded */ private String colorType(SchemaConcept schemaConcept) { if(colorize) { return ANSI.color(typeLabelToString(schemaConcept.label()), ANSI.PURPLE); } else { return typeLabelToString(schemaConcept.label()); } } }
@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(); }
/** * Thrown when a {@link Type} has incoming edges and therefore cannot be deleted */ public static GraknTxOperationException cannotBeDeleted(SchemaConcept schemaConcept){ return create(ErrorMessage.CANNOT_DELETE.getMessage(schemaConcept.label())); }
public static GraqlQueryException insertMetaType(Label label, SchemaConcept schemaConcept) { return new GraqlQueryException(ErrorMessage.INSERT_METATYPE.getMessage(label, schemaConcept.label())); }
/** * @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; }
public static GraqlQueryException insertAbstractOnNonType(SchemaConcept concept) { return new GraqlQueryException(INSERT_ABSTRACT_NOT_TYPE.getMessage(concept.label())); }
@Override public String toString(){ String typeString = getSchemaConcept() != null? getSchemaConcept().label().getValue() : "{" + inferPossibleTypes(new ConceptMapImpl()).stream().map(rt -> rt.label().getValue()).collect(Collectors.joining(", ")) + "}"; String relationString = (isUserDefined()? getVarName() + " ": "") + typeString + (getPredicateVariable().isUserDefinedName()? "(" + getPredicateVariable() + ")" : "") + (isDirect()? "!" : "") + getRelationPlayers().toString(); return relationString + getPredicates(Predicate.class).map(Predicate::toString).collect(Collectors.joining("")); }
@Override public String toString(){ String multiPredicateString = getMultiPredicate().isEmpty()? getPredicateVariable().toString() : getMultiPredicate().stream().map(Predicate::getPredicate).collect(Collectors.toSet()).toString(); return getVarName() + " has " + getSchemaConcept().label() + " " + multiPredicateString + getPredicates(Predicate.class).map(Predicate::toString).collect(Collectors.joining("")) + (getRelationVariable().isUserDefinedName()? "(" + getRelationVariable() + ")" : ""); }
@Override public String toString(){ String typeString = (getSchemaConcept() != null? getSchemaConcept().label() : "") + "(" + getVarName() + ")"; return typeString + (getPredicateVariable().isUserDefinedName()? "(" + getPredicateVariable() + ")" : "") + (isDirect()? "!" : "") + getPredicates().map(Predicate::toString).collect(Collectors.joining("")); }
private String summaryFormat(Object object) { if (object instanceof SchemaConcept) { return ((SchemaConcept) object).label().getValue().replaceAll("-", "_"); } else if (object instanceof Thing) { Thing thing = (Thing) object; return summaryFormat(thing.type()) + thing.id().getValue(); } else if (object instanceof Label) { return valueToString(((Label) object).getValue()); } else { return object.toString(); } }
/** * Get all the {@link SchemaConcept}s in a graph. * @return a stream of all {@link SchemaConcept}s with non-reserved IDs */ private Stream<? extends SchemaConcept> schemaConcepts(){ Stream<? extends Type> types = tx.admin().getMetaConcept().subs(); Stream<Role> roles = tx.admin().getMetaRole().subs(); Stream<Rule> rules = tx.admin().getMetaRule().subs(); return Stream.of(types, roles, rules) .flatMap(Function.identity()) .filter(t -> !Schema.MetaSchema.isMetaLabel(t.label())); } }
@Override protected Pattern createCombinedPattern(){ if (getPredicateVariable().isUserDefinedName()) return super.createCombinedPattern(); return getSchemaConcept() == null? relationPattern() : isDirect()? relationPattern().isaExplicit(getSchemaConcept().label().getValue()): relationPattern().isa(getSchemaConcept().label().getValue()); }
@Override protected Pattern createCombinedPattern(){ if (getPredicateVariable().isUserDefinedName()) return super.createCombinedPattern(); return getSchemaConcept() == null? getVarName().isa(getPredicateVariable()) : isDirect()? getVarName().isaExplicit(getSchemaConcept().label().getValue()) : getVarName().isa(getSchemaConcept().label().getValue()) ; }
@Override public ResourceAtom rewriteWithRelationVariable(){ Var attributeVariable = getPredicateVariable(); Var relationVariable = getRelationVariable().asUserDefined(); VarPattern newVar = getVarName().has(getSchemaConcept().label(), attributeVariable, relationVariable); return create(newVar.admin(), attributeVariable, relationVariable, getTypeId(), getMultiPredicate(), getParentQuery()); }