@Nullable @CheckReturnValue public static MetaSchema valueOf(Label label){ for (MetaSchema metaSchema : MetaSchema.values()) { if (metaSchema.getLabel().equals(label)) return metaSchema; } return null; } }
@Override public Stream<T> sups() { Set<T> superSet= new HashSet<>(); T superParent = getThis(); while(superParent != null && !Schema.MetaSchema.THING.getLabel().equals(superParent.label())){ superSet.add(superParent); //noinspection unchecked superParent = (T) superParent.sup(); } return superSet.stream(); }
/** * Get the root of all the Entity Types. * * @return The meta entity type -> entity-type. */ @CheckReturnValue default EntityType getMetaEntityType(){ return getSchemaConcept(Schema.MetaSchema.ENTITY.getLabel()); }
@SuppressWarnings("unchecked") private boolean initialiseMetaConcepts() { boolean schemaInitialised = false; if (isMetaSchemaNotInitialised()) { VertexElement type = addTypeVertex(Schema.MetaSchema.THING.getId(), Schema.MetaSchema.THING.getLabel(), Schema.BaseType.TYPE); VertexElement entityType = addTypeVertex(Schema.MetaSchema.ENTITY.getId(), Schema.MetaSchema.ENTITY.getLabel(), Schema.BaseType.ENTITY_TYPE); VertexElement relationType = addTypeVertex(Schema.MetaSchema.RELATIONSHIP.getId(), Schema.MetaSchema.RELATIONSHIP.getLabel(), Schema.BaseType.RELATIONSHIP_TYPE); VertexElement resourceType = addTypeVertex(Schema.MetaSchema.ATTRIBUTE.getId(), Schema.MetaSchema.ATTRIBUTE.getLabel(), Schema.BaseType.ATTRIBUTE_TYPE); addTypeVertex(Schema.MetaSchema.ROLE.getId(), Schema.MetaSchema.ROLE.getLabel(), Schema.BaseType.ROLE); addTypeVertex(Schema.MetaSchema.RULE.getId(), Schema.MetaSchema.RULE.getLabel(), Schema.BaseType.RULE); relationType.property(Schema.VertexProperty.IS_ABSTRACT, true); resourceType.property(Schema.VertexProperty.IS_ABSTRACT, true); entityType.property(Schema.VertexProperty.IS_ABSTRACT, true); relationType.addEdge(type, Schema.EdgeLabel.SUB); resourceType.addEdge(type, Schema.EdgeLabel.SUB); entityType.addEdge(type, Schema.EdgeLabel.SUB); schemaInitialised = true; } //Copy entire schema to the graph cache. This may be a bad idea as it will slow down graph initialisation copyToCache(getMetaConcept()); //Role and rule have to be copied separately due to not being connected to meta schema copyToCache(getMetaRole()); copyToCache(getMetaRule()); return schemaInitialised; }
/** * @throws GraqlQueryException if no label is specified on {@code resourceType} */ public static HasAttributeTypeProperty of(VarPatternAdmin resourceType, boolean required) { Label resourceLabel = resourceType.getTypeLabel().orElseThrow(() -> GraqlQueryException.noLabelSpecifiedForHas(resourceType) ); VarPattern role = Graql.label(Schema.MetaSchema.ROLE.getLabel()); VarPatternAdmin ownerRole = var().sub(role).admin(); VarPatternAdmin valueRole = var().sub(role).admin(); VarPattern relationType = var().sub(Graql.label(Schema.MetaSchema.RELATIONSHIP.getLabel())); // If a key, limit only to the implicit key type if(required){ ownerRole = ownerRole.label(KEY_OWNER.getLabel(resourceLabel)).admin(); valueRole = valueRole.label(KEY_VALUE.getLabel(resourceLabel)).admin(); relationType = relationType.label(KEY.getLabel(resourceLabel)); } VarPatternAdmin relationOwner = relationType.relates(ownerRole).admin(); VarPatternAdmin relationValue = relationType.admin().var().relates(valueRole).admin(); return new AutoValue_HasAttributeTypeProperty( resourceType, ownerRole, valueRole, relationOwner, relationValue, required); }
public static void printWholeCompletionMessage(MigrationOptions options){ System.out.println("Migration complete."); if(options.isVerbose()) { System.out.println("Gathering information about migrated data. If in a hurry, you can ctrl+c now."); GraknTx tx = new Grakn(options.getUri()).session(options.getKeyspace()).transaction(GraknTxType.WRITE); QueryBuilder qb = tx.graql(); StringBuilder builder = new StringBuilder(); builder.append("Graph schema contains:\n"); builder.append("\t ").append(tx.admin().getMetaEntityType().instances().count()).append(" entity types\n"); builder.append("\t ").append(tx.admin().getMetaRelationType().instances().count()).append(" relation types\n"); builder.append("\t ").append(tx.admin().getMetaRole().subs().count()).append(" roles\n\n"); builder.append("\t ").append(tx.admin().getMetaAttributeType().instances().count()).append(" resource types\n"); builder.append("\t ").append(tx.admin().getMetaRule().subs().count()).append(" rules\n\n"); builder.append("Graph data contains:\n"); builder.append("\t ").append(qb.match(var("x").isa(label(ENTITY.getLabel()))).aggregate(count()).execute()).append(" entities\n"); builder.append("\t ").append(qb.match(var("x").isa(label(RELATIONSHIP.getLabel()))).aggregate(count()).execute()).append(" relations\n"); builder.append("\t ").append(qb.match(var("x").isa(label(ATTRIBUTE.getLabel()))).aggregate(count()).execute()).append(" resources\n"); builder.append("\t ").append(qb.match(var("x").isa(label(RULE.getLabel()))).aggregate(count()).execute()).append(" rules\n\n"); System.out.println(builder); tx.close(); } }
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); } } /**
private Thing putInstance() { Type type = use(TYPE); if (type.isEntityType()) { return type.asEntityType().create(); } else if (type.isRelationshipType()) { return type.asRelationshipType().create(); } else if (type.isAttributeType()) { return type.asAttributeType().create(use(VALUE)); } else if (type.label().equals(Schema.MetaSchema.THING.getLabel())) { throw GraqlQueryException.createInstanceOfMetaConcept(var, type); } else { throw CommonUtil.unreachableStatement("Can't recognize type " + type); } }
@Override public boolean isTinkerPopGraphClosed() { return !rootGraph.traversal().V().has(Schema.VertexProperty.SCHEMA_LABEL.name(), Schema.MetaSchema.ENTITY.getLabel().getValue()).hasNext(); }
/** * @param graph of interest * @return true if at least one inference rule is present in the graph */ public static boolean hasRules(GraknTx graph) { return graph.admin().getMetaRule().subs().anyMatch(rule -> !rule.label().equals(Schema.MetaSchema.RULE.getLabel())); }
/** * Get the root of all {@link Rule}s; * * @return The meta {@link Rule} */ @CheckReturnValue default Rule getMetaRule(){ return getSchemaConcept(Schema.MetaSchema.RULE.getLabel()); }
/** * Get the root of all the {@link AttributeType}. * * @return The meta resource type -> resource-type. */ @CheckReturnValue default AttributeType getMetaAttributeType(){ return getSchemaConcept(Schema.MetaSchema.ATTRIBUTE.getLabel()); }
private void checkIfHasTargetMeta(AttributeType attributeType){ //Check if attribute type is the meta if(Schema.MetaSchema.ATTRIBUTE.getLabel().equals(attributeType.label())){ throw GraknTxOperationException.metaTypeImmutable(attributeType.label()); } }
/** * Get the root of all Types. * * @return The meta type -> type. */ @CheckReturnValue default Type getMetaConcept(){ return getSchemaConcept(Schema.MetaSchema.THING.getLabel()); }
/** * Get the root of all {@link RelationshipType}. * * @return The meta relation type -> relation-type. */ @CheckReturnValue default RelationshipType getMetaRelationType(){ return getSchemaConcept(Schema.MetaSchema.RELATIONSHIP.getLabel()); }
/** * Get the root of all the {@link Role}. * * @return The meta role type -> role-type. */ @CheckReturnValue default Role getMetaRole(){ return getSchemaConcept(Schema.MetaSchema.ROLE.getLabel()); }