public RelationshipType relation(OWLDataProperty property) { RelationshipType relType = tx.putRelationshipType(namer.resourceRelation(property.getIRI())); AttributeType<?> attributeType = resourceType(property); relType.relates(entityRole(owlThingEntityType(), attributeType)); relType.relates(resourceRole(attributeType)); return relType; }
public RelationshipType relation(OWLObjectProperty property) { RelationshipType relType = tx.putRelationshipType(namer.objectPropertyName(property.getIRI())); Role subjectRole = subjectRole(relType); Role objectRole = objectRole(relType); relType.relates(subjectRole); relType.relates(objectRole); EntityType top = this.owlThingEntityType(); top.plays(subjectRole); top.plays(objectRole); return relType; }
public RelationshipType relation(OWLAnnotationProperty property) { RelationshipType relType = tx.putRelationshipType(namer.resourceRelation(property.getIRI())); AttributeType<?> attributeType = tx.putAttributeType(namer.fromIri(property.getIRI()), AttributeType.DataType.STRING); relType.relates(entityRole(owlThingEntityType(), attributeType)); relType.relates(resourceRole(attributeType)); return relType; }
public static ConceptMethod<Void> setRelatedRole(Role role) { return ConceptMethod.builder(ConceptResponseType.UNIT) .requestSetter(builder -> builder.setSetRelatedRole(convert(role))) .functionVoid(concept -> concept.asRelationshipType().relates(role)) .build(); }
public Entity putEntity(String id, EntityType type) { Entity current = getEntity(id, owlIriResource()); if(current != null) return current; Label hasIriResourceId = Label.of(OwlModel.IRI.owlname()); AttributeType<String> iriResource = owlIriResource(); Role hasIriOwner = entityRole(type, iriResource); Role hasIriValue = resourceRole(iriResource); RelationshipType hasIriRelation = tx.putRelationshipType(namer.resourceRelation(hasIriResourceId)) .relates(hasIriOwner).relates(hasIriValue); Entity entity = type.addEntity(); Attribute attributeInstance = iriResource.putAttribute(id); hasIriRelation.addRelationship() .addRolePlayer(hasIriOwner, entity) .addRolePlayer(hasIriValue, attributeInstance); return entity; }
public OwlGraknTxStoringVisitor prepareOWL() { migrator.entityType(migrator.ontology().getOWLOntologyManager().getOWLDataFactory().getOWLClass(OwlModel.THING.owlname())); migrator.relation(migrator.ontology().getOWLOntologyManager().getOWLDataFactory().getOWLObjectProperty(OwlModel.OBJECT_PROPERTY.owlname())) .relates(migrator.tx().putRole(OwlModel.OBJECT.owlname())) .relates(migrator.tx().putRole(OwlModel.SUBJECT.owlname())); return this; }
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); } } /**
work = tx.putRole("work"); author = tx.putRole("author"); authoredBy = tx.putRelationshipType("authored-by").relates(work).relates(author); .relates(productionBeingDirected).relates(director); characterBeingPlayed = tx.putRole("character-being-played"); hasCast = tx.putRelationshipType("has-cast") .relates(productionWithCast).relates(actor).relates(characterBeingPlayed); .relates(genreOfProduction).relates(productionWithGenre); .relates(clusterOfProduction).relates(productionWithCluster);
/** * Creates a relation type which allows this type and a {@link ai.grakn.concept.Attribute} type to be linked. * @param attributeType The {@link AttributeType} which instances of this type should be allowed to play. * @param has the implicit relation type to build * @param hasValue the implicit role type to build for the {@link AttributeType} * @param hasOwner the implicit role type to build for the type * @param required Indicates if the {@link ai.grakn.concept.Attribute} is required on the entity * @return The {@link Type} itself */ private T has(AttributeType attributeType, Schema.ImplicitType has, Schema.ImplicitType hasValue, Schema.ImplicitType hasOwner, boolean required){ Label attributeLabel = attributeType.label(); Role ownerRole = vertex().tx().putRoleTypeImplicit(hasOwner.getLabel(attributeLabel)); Role valueRole = vertex().tx().putRoleTypeImplicit(hasValue.getLabel(attributeLabel)); RelationshipType relationshipType = vertex().tx().putRelationTypeImplicit(has.getLabel(attributeLabel)). relates(ownerRole). relates(valueRole); //this plays ownerRole; this.play(ownerRole, required); //TODO: Use explicit cardinality of 0-1 rather than just false //attributeType plays valueRole; ((AttributeTypeImpl) attributeType).play(valueRole, false); updateAttributeRelationHierarchy(attributeType, has, hasValue, hasOwner, ownerRole, valueRole, relationshipType); return getThis(); }
@Override public Concept visit(OWLObjectPropertyRangeAxiom axiom) { if (!axiom.getProperty().isOWLObjectProperty()) { return null; } RelationshipType objectRelation = migrator.relation(axiom.getProperty().asOWLObjectProperty()); if (axiom.getRange().isOWLClass()) { EntityType entityType = migrator.entityType(axiom.getRange().asOWLClass()); Role range = migrator.objectRole(objectRelation); objectRelation.relates(range); migrator.owlThingEntityType().deletePlays(range); entityType.plays(range); } return objectRelation; }
@Override public Collection<PropertyExecutor> define(Var var) throws GraqlQueryException { Var roleVar = role().var(); PropertyExecutor.Method relatesMethod = executor -> { Role role = executor.get(roleVar).asRole(); executor.get(var).asRelationshipType().relates(role); }; PropertyExecutor relatesExecutor = PropertyExecutor.builder(relatesMethod).requires(var, roleVar).build(); // This allows users to skip stating `$roleVar sub role` when they say `$var relates $roleVar` PropertyExecutor.Method isRoleMethod = executor -> executor.builder(roleVar).isRole(); PropertyExecutor isRoleExecutor = PropertyExecutor.builder(isRoleMethod).produces(roleVar).build(); VarPatternAdmin superRoleVarPattern = superRole(); if (superRoleVarPattern != null) { Var superRoleVar = superRoleVarPattern.var(); PropertyExecutor.Method subMethod = executor -> { Role superRole = executor.get(superRoleVar).asRole(); executor.builder(roleVar).sub(superRole); }; PropertyExecutor subExecutor = PropertyExecutor.builder(subMethod) .requires(superRoleVar).produces(roleVar).build(); return ImmutableSet.of(relatesExecutor, isRoleExecutor, subExecutor); } else { return ImmutableSet.of(relatesExecutor, isRoleExecutor); } }
@Override public Concept visit(OWLObjectPropertyDomainAxiom axiom) { if (!axiom.getProperty().isOWLObjectProperty()) { return null; } RelationshipType objectRelation = migrator.relation(axiom.getProperty().asOWLObjectProperty()); if (axiom.getDomain().isOWLClass()) { EntityType entityType = migrator.entityType(axiom.getDomain().asOWLClass()); Role domain = migrator.subjectRole(objectRelation); migrator.owlThingEntityType().deletePlays(domain); entityType.plays(domain); objectRelation.relates(domain); // System.out.println("Replaced domain thing with " + entityType.getLabel()); } return objectRelation; }
@Override public void buildSchema(GraknTx tx) { key = tx.putAttributeType("name", AttributeType.DataType.STRING); geoEntity = tx.putRole("geo-entity"); entityLocation = tx.putRole("entity-location"); isLocatedIn = tx.putRelationshipType("is-located-in") .relates(geoEntity).relates(entityLocation); geographicalObject = tx.putEntityType("geoObject") .plays(geoEntity) .plays(entityLocation); geographicalObject.has(key); continent = tx.putEntityType("continent") .sup(geographicalObject) .plays(entityLocation); country = tx.putEntityType("country") .sup(geographicalObject) .plays(geoEntity) .plays(entityLocation); region = tx.putEntityType("region") .sup(geographicalObject) .plays(geoEntity) .plays(entityLocation); city = tx.putEntityType("city") .sup(geographicalObject) .plays(geoEntity) .plays(entityLocation); university = tx.putEntityType("university") .plays(geoEntity); university.has(key); }