@Nullable @Override public RelationshipType getRelationshipType(String label) { SchemaConcept concept = getSchemaConcept(Label.of(label)); if (concept == null || !concept.isRelationshipType()) return null; return concept.asRelationshipType(); }
@Override public Set<String> validateOntologically() { Set<String> errors = new HashSet<>(); SchemaConcept type = getSchemaConcept(); if (type != null && !type.isRelationshipType()){ errors.add(ErrorMessage.VALIDATION_RULE_INVALID_RELATION_TYPE.getMessage(type.label())); return errors; } //check role-type compatibility Map<Var, Type> varTypeMap = getParentQuery().getVarTypeMap(); for (Map.Entry<Role, Collection<Var>> e : getRoleVarMap().asMap().entrySet() ){ Role role = e.getKey(); if (!Schema.MetaSchema.isMetaLabel(role.label())) { //check whether this role can be played in this relation if (type != null && type.asRelationshipType().roles().noneMatch(r -> r.equals(role))) { errors.add(ErrorMessage.VALIDATION_RULE_ROLE_CANNOT_BE_PLAYED.getMessage(role.label(), type.label())); } //check whether the role player's type allows playing this role for (Var player : e.getValue()) { Type playerType = varTypeMap.get(player); if (playerType != null && playerType.playing().noneMatch(plays -> plays.equals(role))) { errors.add(ErrorMessage.VALIDATION_RULE_TYPE_CANNOT_PLAY_ROLE.getMessage(playerType.label(), role.label(), type == null? "" : type.label())); } } } } return errors; }
/** * Map a Type to the Graql string representation * @param schemaConcept type to be mapped * @return Graql var equivalent to the given type */ public static VarPattern map(SchemaConcept schemaConcept) { VarPattern mapped = formatBase(schemaConcept); if (schemaConcept.isRelationshipType()) { mapped = map(mapped, schemaConcept.asRelationshipType()); } else if (schemaConcept.isAttributeType()) { mapped = map(mapped, schemaConcept.asAttributeType()); } return mapped; }
Role metaRole = graph.admin().getMetaRole(); List<RelationPlayer> allocatedRelationPlayers = new ArrayList<>(); RelationshipType relType = getSchemaConcept() != null? getSchemaConcept().asRelationshipType() : null;
@Override public Stream<ConceptMap> materialise(){ RelationshipType relationType = getSchemaConcept().asRelationshipType(); Multimap<Role, Var> roleVarMap = getRoleVarMap(); ConceptMap substitution = getParentQuery().getSubstitution(); //if the relation already exists, only assign roleplayers, otherwise create a new relation Relationship relationship = substitution.containsVar(getVarName())? substitution.get(getVarName()).asRelationship() : RelationshipTypeImpl.from(relationType).addRelationshipInferred(); roleVarMap.asMap().forEach((key, value) -> value.forEach(var -> relationship.assign(key, substitution.get(var).asThing()))); ConceptMap relationSub = getRoleSubstitution().merge( getVarName().isUserDefinedName()? new ConceptMapImpl(ImmutableMap.of(getVarName(), relationship)) : new ConceptMapImpl() ); return Stream.of(substitution.merge(relationSub)); }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ public static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.label(), superConcept); } }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ private static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.getLabel(), superConcept); } } }