congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Role
Code IndexAdd Tabnine to your IDE (free)

How to use
Role
in
ai.grakn.concept

Best Java code snippets using ai.grakn.concept.Role (Showing top 20 results out of 315)

origin: ai.grakn/grakn-kb

public void addRolePlayer(Role role, Thing thing) {
  Objects.requireNonNull(role);
  Objects.requireNonNull(thing);
  if(Schema.MetaSchema.isMetaLabel(role.label())) throw GraknTxOperationException.metaTypeImmutable(role.label());
  //Do the actual put of the role and role player
  putRolePlayerEdge(role, thing);
}
origin: ai.grakn/grakn-graql

  @Override
  public Stream<Role> toCompatibleRoles(Role entryRole) {
    return entryRole.subs();
  }
}
origin: ai.grakn/grakn-kb

/**
 *
 * @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();
}
origin: ai.grakn/grakn-graql

/**
 * @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)));
}
origin: ai.grakn/grakn-kb

superRelationType.sups().forEach(rel -> rel.roles().forEach(roleType -> allSuperRolesPlayed.add(roleType.label())));
    errorMessages.add(VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(relate.label(), relationshipType.label(), "super", "super", superRelationType.label()));
boolean subRoleNotFoundInRelates = superRelate.subs().noneMatch(sub -> relatesLabels.contains(sub.label()));
  errorMessages.add(VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(superRelate.label(), superRelationType.label(), "sub", "sub", relationshipType.label()));
origin: ai.grakn/grakn-kb

private void updateAttributeRelationHierarchy(AttributeType attributeType, Schema.ImplicitType has, Schema.ImplicitType hasValue, Schema.ImplicitType hasOwner,
                 Role ownerRole, Role valueRole, RelationshipType relationshipType){
  AttributeType attributeTypeSuper = attributeType.sup();
  Label superLabel = attributeTypeSuper.label();
  Role ownerRoleSuper = vertex().tx().putRoleTypeImplicit(hasOwner.getLabel(superLabel));
  Role valueRoleSuper = vertex().tx().putRoleTypeImplicit(hasValue.getLabel(superLabel));
  RelationshipType relationshipTypeSuper = vertex().tx().putRelationTypeImplicit(has.getLabel(superLabel)).
      relates(ownerRoleSuper).relates(valueRoleSuper);
  //Create the super type edges from sub role/relations to super roles/relation
  ownerRole.sup(ownerRoleSuper);
  valueRole.sup(valueRoleSuper);
  relationshipType.sup(relationshipTypeSuper);
  if (!Schema.MetaSchema.ATTRIBUTE.getLabel().equals(superLabel)) {
    //Make sure the supertype attribute is linked with the role as well
    ((AttributeTypeImpl) attributeTypeSuper).plays(valueRoleSuper);
    updateAttributeRelationHierarchy(attributeTypeSuper, has, hasValue, hasOwner, ownerRoleSuper, valueRoleSuper, relationshipTypeSuper);
  }
}
/**
origin: ai.grakn/grakn-graql

/**
 * 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;
}
origin: ai.grakn/grakn-graql

@Override
public Collection<PropertyExecutor> undefine(Var var) throws GraqlQueryException {
  PropertyExecutor.Method method = executor -> {
    Type type = executor.get(var).asType();
    Role role = executor.get(this.role().var()).asRole();
    if (!type.isDeleted() && !role.isDeleted()) {
      type.unplay(role);
    }
  };
  return ImmutableSet.of(PropertyExecutor.builder(method).requires(var, role().var()).build());
}
origin: ai.grakn/grakn-graql

private Set<String> validateRelationPlayers(Rule rule){
  Set<String> errors = new HashSet<>();
  getRelationPlayers().forEach(rp -> {
    VarPatternAdmin role = rp.getRole().orElse(null);
    if (role == null){
      errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.then(), rule.label()));
    } else {
      Label roleLabel = role.getTypeLabel().orElse(null);
      if (roleLabel == null){
        errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.then(), rule.label()));
      } else {
        if (Schema.MetaSchema.isMetaLabel(roleLabel)) {
          errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.then(), rule.label()));
        }
        Role roleType = tx().getRole(roleLabel.getValue());
        if (roleType != null && roleType.isImplicit()) {
          errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_IMPLICIT_ROLE.getMessage(rule.then(), rule.label()));
        }
      }
    }
  });
  return errors;
}
origin: ai.grakn/migration-owl

@Override
public Concept visit(OWLSubObjectPropertyOfAxiom axiom) {
  if (!axiom.getSubProperty().isOWLObjectProperty() || !axiom.getSuperProperty().isOWLObjectProperty()) {
    return null;
  }
  RelationshipType subRelation = migrator.relation(axiom.getSubProperty().asOWLObjectProperty());
  RelationshipType superRelation = migrator.relation(axiom.getSuperProperty().asOWLObjectProperty());
  Map<Label, Label> roleMap = new HashMap<>();
  roleMap.put(migrator.namer().subjectRole(superRelation.getLabel()), migrator.namer().subjectRole(subRelation.getLabel()));
  roleMap.put(migrator.namer().objectRole(superRelation.getLabel()), migrator.namer().objectRole(subRelation.getLabel()));
  ReasonerUtils.createSubPropertyRule("Sub Property Rule Between [" + superRelation.getLabel() + "] and [" + subRelation.getLabel() +  "]", superRelation, subRelation, roleMap, migrator.tx());
  migrator.subjectRole(subRelation).sup(migrator.subjectRole(superRelation));
  migrator.objectRole(subRelation).sup(migrator.objectRole(superRelation));
  subRelation.sup(superRelation);
  return null;
}
origin: ai.grakn/grakn-graql

@Override
public Collection<PropertyExecutor> undefine(Var var) throws GraqlQueryException {
  PropertyExecutor.Method method = executor -> {
    RelationshipType relationshipType = executor.get(var).asRelationshipType();
    Role role = executor.get(this.role().var()).asRole();
    if (!relationshipType.isDeleted() && !role.isDeleted()) {
      relationshipType.unrelate(role);
    }
  };
  return ImmutableSet.of(PropertyExecutor.builder(method).requires(var, role().var()).build());
}
origin: ai.grakn/grakn-kb

@Override
public String innerToString(){
  StringBuilder description = new StringBuilder();
  description.append("ID [").append(id()).append("] Type [").append(type().label()).append("] Roles and Role Players: \n");
  for (Map.Entry<Role, Set<Thing>> entry : allRolePlayers().entrySet()) {
    if(entry.getValue().isEmpty()){
      description.append("    Role [").append(entry.getKey().label()).append("] not played by any instance \n");
    } else {
      StringBuilder instancesString = new StringBuilder();
      for (Thing thing : entry.getValue()) {
        instancesString.append(thing.id()).append(",");
      }
      description.append("    Role [").append(entry.getKey().label()).append("] played by [").
          append(instancesString.toString()).append("] \n");
    }
  }
  return description.toString();
}
origin: ai.grakn/grakn-test-tools

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;
}
origin: ai.grakn/grakn-graql

/**
 * 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);
  }
}
origin: ai.grakn/grakn-kb

/**
 * 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();
}
origin: ai.grakn/migration-export

/**
 * Add relates edges to a var, given a type
 * @param var var to be modified
 * @param type type from which metadata extracted
 * @return var with appropriate relates edges
 */
private static VarPattern relates(VarPattern var, RelationshipType type){
  for(Role role:type.roles().collect(Collectors.toSet())){
    var = var.relates(Graql.label(role.label()));
  }
  return var;
}
origin: ai.grakn/grakn-test-tools

private Role role() {
  return random.choose(tx.admin().getMetaRole().subs().collect(toSet()));
}
origin: ai.grakn/grakn-grpc

  /**
   * 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);
    }
  }
}
origin: ai.grakn/migration-export

/**
 * Add plays edges to a var, given a type
 * @param var var to be modified
 * @param type type from which metadata extracted
 * @return var with appropriate plays edges
 */
private static VarPattern plays(VarPattern var, Type type) {
  for(Role role:type.playing().collect(Collectors.toSet())){
    var = var.plays(Graql.label(role.label()));
  }
  return var;
}
origin: ai.grakn/migration-export

  /**
   * 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()));
  }
}
ai.grakn.conceptRole

Javadoc

An SchemaConcept which defines a role which can be played in a RelationshipType

This ontological element defines the Role which make up a RelationshipType. It behaves similarly to SchemaConcept when relating to other types.

Most used methods

  • label
    Changes the Label of this Concept to a new one.
  • subs
    Returns the sub of this Role.
  • sup
  • relationships
    Returns the RelationshipTypes that this Role takes part in.
  • isDeleted
  • isImplicit
  • labelId
  • players
    Returns a collection of the Types that can play this Role.

Popular in Java

  • Parsing JSON documents to java classes using gson
  • runOnUiThread (Activity)
  • addToBackStack (FragmentTransaction)
  • getSharedPreferences (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JFileChooser (javax.swing)
  • JList (javax.swing)
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now