def end_class(self, cls: ClassDefinition) -> None: if cls.is_a: self._add_constraint(self.namespaces.uri_for(camelcase(cls.is_a) + "_t")) for mixin in cls.mixins: if self._class_has_expressions(mixin): self._add_constraint(self.namespaces.uri_for(camelcase(mixin) + "_t")) if cls.name in self.synopsis.applytorefs: for applyto in self.synopsis.applytorefs[cls.name].classrefs: if self._class_has_expressions(applyto): self._add_constraint(self.namespaces.uri_for(camelcase(applyto) + '_t')) self.shape.closed = True self.shape.extra = [RDF.type] if self.shape.expression: # TODO: Figure out how to label a single triple expression if isinstance_(self.shape.expression, tripleExprLabel): self.shape.expression = EachOf(expressions=[self.shape.expression, wildcard(None)]) self.shape.expression.id = self.namespaces.uri_for(camelcase(cls.name) + "_t") else: self.shape.expression = wildcard(self.namespaces.uri_for(camelcase(cls.name) + "_t")) if self.class_identifier(cls): self.shape.extra = [RDF.type] type_constraint = TripleConstraint() type_constraint.predicate = RDF.type type_constraint.valueExpr = NodeConstraint(values=[IRIREF(self.namespaces.uri_for(cls.class_uri))]) if not self.shape.expression: self.shape.expression = type_constraint else: self.shape.expression = EachOf(expressions=[self.shape.expression, type_constraint]) shapeExpr = self.shape shapeExpr.id = self._shape_iri(cls.name) self.shapes.append(shapeExpr)
def visit_class_slot(self, cls: ClassDefinition, aliased_slot_name: str, slot: SlotDefinition) -> None: constraint = TripleConstraint() # Juggling to get the constraint to be either a single triple constraint or an eachof construct if not self.shape.expression: self.shape.expression = constraint elif isinstance(self.shape.expression, TripleConstraint): self.shape.expression = EachOf( expressions=[self.shape.expression, constraint]) else: self.shape.expression.expressions.append(constraint) constraint.predicate = self._predicate(slot.name) # JSON-LD generates multi-valued entries as lists constraint.min = 1 if slot.primary_key or slot.required else 0 constraint.max = 1 if not slot.multivalued or self.collections else -1 # TODO: This should not be hard coded -- figure out where to go with it rng = IRIREF(META.SlotRangeTypes) if slot.range == 'anytype' else\ self._type_constraint(slot.range) if slot.range and slot.range not in self.schema.classes else\ self._shapeIRI(slot.range) name_base = ("XSD_" + self.grounded_slot_range(slot.range)) if isinstance( rng, NodeConstraint) else str(rng) constraint.valueExpr = self.gen_multivalued_slot(name_base, rng) \ if slot.multivalued and self.collections else rng
def visit_class_slot(self, cls: ClassDefinition, aliased_slot_name: SlotDefinitionName, slot: SlotDefinition) \ -> None: if not (slot.identifier or slot.abstract or slot.mixin): constraint = TripleConstraint() self._add_constraint(constraint) constraint.predicate = self.namespaces.uri_for(slot.slot_uri) constraint.min = int(bool(slot.required)) constraint.max = 1 if not slot.multivalued else -1 constraint.valueExpr = self._class_or_type_uri(slot.range)