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; }
/** * Expand a {@link LabelFragmentSet} to match all sub-concepts of the single existing {@link Label}. * * Returns null if there is not exactly one label any of the {@link Label}s mentioned are not in the knowledge base. */ @Nullable LabelFragmentSet tryExpandSubs(Var typeVar, GraknTx tx) { if (labels().size() != 1) return null; Label oldLabel = Iterables.getOnlyElement(labels()); SchemaConcept concept = tx.getSchemaConcept(oldLabel); if (concept == null) return null; Set<Label> newLabels = concept.subs().map(SchemaConcept::label).collect(toSet()); return new AutoValue_LabelFragmentSet(varProperty(), typeVar, ImmutableSet.copyOf(newLabels)); }
@Override public boolean isUnifiableWith(Atom atom) { return atom.getSchemaConcept() == null || //ensure not ontological atom query (atom instanceof IsaAtomBase) && atom.getSchemaConcept().subs().anyMatch(sub -> sub.equals(this.getSchemaConcept())); }
@Override protected final T generateFromTx() { Collection<T> schemaConcepts; if (!includeNonMeta()) { schemaConcepts = Sets.newHashSet(otherMetaSchemaConcepts()); schemaConcepts.add(metaSchemaConcept()); } else { schemaConcepts = (Collection<T>) metaSchemaConcept().subs().collect(toSet()); } schemaConcepts = schemaConcepts.stream().filter(this::filter).collect(toSet()); if (!includeMeta()) { schemaConcepts.remove(metaSchemaConcept()); schemaConcepts.removeAll(otherMetaSchemaConcepts()); } if (schemaConcepts.isEmpty() && includeNonMeta()) { Label label = genFromTx(Labels.class).mustBeUnused().generate(random, status); assert tx().getSchemaConcept(label) == null; return newSchemaConcept(label); } else { return random.choose(schemaConcepts); } }
/** * 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); }); }