.sorted(Comparator.comparing(p -> -p.getValue())) .sorted(Comparator.comparing(e -> e.getKey().isImplicit())) .map(Pair::getKey)
/** * Map a {@link Relationship} to a var, along with all of the roleplayers * Exclude any relations that are mapped to an encountered resource * @param relationship {@link Relationship} to be mapped * @return var patterns representing the given instance */ //TODO resources on relations private static VarPattern map(Relationship relationship){ if(relationship.type().isImplicit()){ return var(); } VarPattern var = base(relationship); var = roleplayers(var, relationship); return var; }
/** * 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; } }
/** * Deletes the concept as an Thing */ @Override public void delete() { //Remove links to relationships and return them Set<Relationship> relationships = castingsInstance().map(casting -> { Relationship relationship = casting.getRelationship(); Role role = casting.getRole(); relationship.unassign(role, this); return relationship; }).collect(toSet()); vertex().tx().txCache().removedInstance(type().id()); deleteNode(); relationships.forEach(relation -> { if(relation.type().isImplicit()){//For now implicit relationships die relation.delete(); } else { RelationshipImpl rel = (RelationshipImpl) relation; rel.cleanUp(); } }); }