/** * convert a given type to a map of relation types in which it can play roles * and the corresponding role types including entity type hierarchy * @param entryConcept to be converted * @return map of relation types in which it can play roles and the corresponding role types */ default Multimap<RelationshipType, Role> toRelationshipMultimap(T entryConcept){ Multimap<RelationshipType, Role> relationMap = HashMultimap.create(); toCompatibleRoles(entryConcept) .forEach(role -> role.relationships() .forEach(rel -> relationMap.put(rel, role))); return relationMap; }
/** * * @param role The Role to validate * @return An error message if the relates does not have a single incoming RELATES edge */ static Optional<String> validateHasSingleIncomingRelatesEdge(Role role){ if(!role.relationships().findAny().isPresent()) { return Optional.of(VALIDATION_ROLE_TYPE_MISSING_RELATION_TYPE.getMessage(role.label())); } return Optional.empty(); }
/** * Checks if the {@link Role} of the {@link Casting} has been linked to the {@link RelationshipType} of * the {@link Relationship} which the {@link Casting} connects to. * * @param role the {@link Role} which the {@link Casting} refers to * @param relationshipType the {@link RelationshipType} which should connect to the role * @param relationship the {@link Relationship} which the {@link Casting} refers to * @return an error if one is found */ private static Optional<String> roleNotLinkedToRelationShip(Role role, RelationshipType relationshipType, Relationship relationship){ boolean notFound = role.relationships(). noneMatch(innerRelationType -> innerRelationType.label().equals(relationshipType.label())); if(notFound){ return Optional.of(VALIDATION_RELATION_CASTING_LOOP_FAIL.getMessage(relationship.id(), role.label(), relationshipType.label())); } return Optional.empty(); }