@Override public Stream<Role> toCompatibleRoles(Type entryType) { return entryType.subs().flatMap(Type::playing); } }
private static void addAllPossibleRelationships(Multimap<Type, RelationshipType> relationshipMap, Type metaType) { metaType.subs().forEach(type -> type.playing().flatMap(Role::relationships) .forEach(relationshipType -> relationshipMap.put(type, relationshipType))); }
private Type type() { Collection<? extends Type> candidates = tx.admin().getMetaConcept().subs().collect(toSet()); return random.choose(candidates); }
public static Collection<? extends SchemaConcept> allSchemaElementsFrom(GraknTx graph) { Set<SchemaConcept> allSchemaConcepts = new HashSet<>(); allSchemaConcepts.addAll(graph.admin().getMetaConcept().subs().collect(toSet())); allSchemaConcepts.addAll(graph.admin().getMetaRole().subs().collect(toSet())); allSchemaConcepts.addAll(graph.admin().getMetaRule().subs().collect(toSet())); return allSchemaConcepts; }
/** * @param typedVar variable of interest * @param parentType to be checked * @return true if typing the typeVar with type is compatible with role configuration of this query */ @Override public boolean isTypeRoleCompatible(Var typedVar, Type parentType){ if (parentType == null || Schema.MetaSchema.isMetaLabel(parentType.label())) return true; Set<Type> parentTypes = parentType.subs().collect(Collectors.toSet()); return getAtoms(RelationshipAtom.class) .filter(ra -> ra.getVarNames().contains(typedVar)) .noneMatch(ra -> ra.getRoleVarMap().entries().stream() //get roles this type needs to play .filter(e -> e.getValue().equals(typedVar)) .filter(e -> !Schema.MetaSchema.isMetaLabel(e.getKey().label())) //check if it can play it .anyMatch(e -> e.getKey().players().noneMatch(parentTypes::contains))); }
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 ImmutableList<SchemaConcept> inferPossibleTypes(ConceptMap sub){ if (getSchemaConcept() != null) return ImmutableList.of(this.getSchemaConcept()); if (sub.containsVar(getPredicateVariable())) return ImmutableList.of(sub.get(getPredicateVariable()).asType()); //determine compatible types from played roles Set<Type> typesFromRoles = getParentQuery().getAtoms(RelationshipAtom.class) .filter(r -> r.getVarNames().contains(getVarName())) .flatMap(r -> r.getRoleVarMap().entries().stream() .filter(e -> e.getValue().equals(getVarName())) .map(Map.Entry::getKey)) .map(role -> role.players().collect(Collectors.toSet())) .reduce(Sets::intersection) .orElse(Sets.newHashSet()); Set<Type> typesFromTypes = getParentQuery().getAtoms(IsaAtom.class) .filter(at -> at.getVarNames().contains(getVarName())) .filter(at -> at != this) .map(Binary::getSchemaConcept) .filter(Objects::nonNull) .filter(Concept::isType) .map(Concept::asType) .collect(Collectors.toSet()); Set<Type> types = typesFromTypes.isEmpty()? typesFromRoles : typesFromRoles.isEmpty()? typesFromTypes: Sets.intersection(typesFromRoles, typesFromTypes); return !types.isEmpty()? ImmutableList.copyOf(ReasonerUtils.top(types)) : tx().admin().getMetaConcept().subs().collect(toImmutableList()); }
Type type = tx.getSchemaConcept(typeLabel); if (type == null) throw GraqlQueryException.labelNotFound(typeLabel); return type.subs(); }) .map(SchemaConcept::label)
/** * 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())); } }
if (type == null) throw GraqlQueryException.labelNotFound(typeLabel); if (type.isRelationshipType()) throw GraqlQueryException.kCoreOnRelationshipType(typeLabel); return type.subs(); }) .map(SchemaConcept::label)
/** * Helper method to get the types to be included in the query scope * * @return stream of Concept Types */ private Stream<Type> scopeTypes() { // Get all types if query.inTypes() is empty, else get all scoped types of each meta type. // Only include attributes and implicit "has-xxx" relationships when user specifically asked for them. if (!query.in().isPresent() || query.in().get().isEmpty()) { ImmutableSet.Builder<Type> typeBuilder = ImmutableSet.builder(); if (scopeIncludesAttributes()) { tx.admin().getMetaConcept().subs().forEach(typeBuilder::add); } else { tx.admin().getMetaEntityType().subs().forEach(typeBuilder::add); tx.admin().getMetaRelationType().subs() .filter(relationshipType -> !relationshipType.isImplicit()).forEach(typeBuilder::add); } return typeBuilder.build().stream(); } else { Stream<Type> subTypes = query.in().get().stream().map(label -> { Type type = tx.getType(label); if (type == null) throw GraqlQueryException.labelNotFound(label); return type; }).flatMap(Type::subs); if (!scopeIncludesAttributes()) { subTypes = subTypes.filter(relationshipType -> !relationshipType.isImplicit()); } return subTypes; } }