Skip to content

[mirror] fix(owlgen): state restrictions on the property a slot is declared as - #68

Open
jdsika wants to merge 1 commit into
mainfrom
fix/owlgen-class-expression-slot-uri
Open

jdsika wants to merge 1 commit into
mainfrom
fix/owlgen-class-expression-slot-uri

Conversation

@jdsika

@jdsika jdsika commented Nov 18, 2026 •

Copy link
Copy Markdown

Mirror of linkml#4260, same head. Review there; this PR tracks the fork stack.

The description below is the one on linkml#4260.

Summary

With --no-use-native-uris, gen-owl declares a slot's property under its slot_uri but states some restrictions on a different IRI, one derived from the slot's name. The ontology then restricts properties it never declares. With native URIs, the default, nothing changes.

In plain words: a slot is declared once (note is skos:note). A class may later say something more about it: "in this class note is required", or "either note is present or …". That later mention only names the slot. gen-owl looked for the IRI on the mention itself, found none, and made one up from the name. It now looks the slot up and uses the IRI it was declared with.

Reproduce

restrict.yaml:

id: https://example.org/s
name: s
prefixes:
  ex: https://example.org/
  skos: http://www.w3.org/2004/02/skos/core#
  linkml: https://w3id.org/linkml/
default_prefix: ex
default_range: string
imports:
  - linkml:types
slots:
  note:
    slot_uri: skos:note
    range: string
classes:
  Thing:
    slots:
      - note
    any_of:
      - slot_conditions:
          note:
            required: true
gen-owl --no-use-native-uris --no-metadata restrict.yaml | grep -E "a owl:DatatypeProperty|owl:onProperty" | sort | uniq -c
main (e5ba58b4c) this PR
declared 1 skos:note a owl:DatatypeProperty ; 1 skos:note a owl:DatatypeProperty ;
restrictions 3 owl:onProperty skos:note .
1 owl:onProperty ex:note .
4 owl:onProperty skos:note .

The one restriction on ex:note is the one from the any_of; ex:note is declared nowhere in the output. Without --no-use-native-uris both write ex:note throughout, declaration included, and the output of this PR is byte-identical to that of main.

Affected are all places where the generator handles a slot_usage or slot_conditions entry, which names a slot and holds only what it adds:

  • slot_conditions in a class's any_of, all_of, none_of, exactly_one_of;
  • the pre- and postconditions of rules, and classification_rules;
  • slot_conditions in a range_expression;
  • slot_usage on a slot the class inherits, also from a mixin.

It is in the metamodel's own ontology too. On main, gen-owl --no-use-native-uris packages/linkml_runtime/src/linkml_runtime/linkml_model/model/schema/meta.yaml restricts linkml:ucum_code, linkml:symbol, linkml:iec61360code and linkml:exact_mappings, while it declares qudt:ucumCode, qudt:symbol, qudt:iec61360Code and skos:exactMatch. With this PR no restriction there is on an undeclared property.

Why this is wrong, not only untidy

  • OWL 2 DL requires every property that occurs in an axiom to be declared: "If an object property with an IRI I occurs in some axiom in Ax, then I is declared in Ax as an object property", and likewise for data properties (OWL 2 Structural Specification §5.8.1).
  • In RDF the declaration is also what tells a parser whether owl:onProperty ex:note is an object or a data restriction. Without it the restriction's triples match no pattern of the reverse mapping, which ends with "At the end of this process, the graph G MUST be empty" (OWL 2 Mapping to RDF Graphs §3.2).
  • The restriction does not constrain the data: data uses skos:note, the axiom is about ex:note. Nothing relates the two, since IRIs are compared as strings (RDF 1.1 Concepts §3.2).

The change

  • transform_class_expression and transform_class_slot_expression take the class whose slots the conditions name (owner): the class that states the expression, the class a rule's or classification rule's expression names with is_a (its axiom is about the instances of that class), or, for a range expression, the class the slot ranges over (the expression's own range, else the slot's range in its owner).
  • The restriction takes the slot_uri of the slot the entry names in that class. Two classes with an attribute of the same name each get their own property. A name may be written in its underscored form (exact_mappings for the slot exact mappings), as SchemaView.induced_slot accepts it.
  • Only the slot_uri is taken from the named slot; the IRI derived from a slot's name is computed as before, and with native URIs the entry is used as it is.
  • The annotation-property check in the same loop reads the slot of the same class as the restriction. Before, a like-named top-level slot or attribute of another class could decide whether a condition was refused.
  • Both methods gain an optional keyword parameter owner, which the generator passes on every recursive call. A subclass that overrides either with the previous signature must accept it; nothing in this repository does.
  • Not fixed in SchemaView, because get_uri receives the bare slot_usage entry without its class; only the generator knows the class.

How was this tested?

  • test_owlgen.py, 57 new tests:
    • 17 schemas, each in both URI modes: every owl:onProperty is a property the ontology declares; with --no-use-native-uris each class's restrictions are on exactly the expected slot_uris. The schemas cover boolean expressions (any_of, all_of, none_of, exactly_one_of, nested four operators deep), slot_usage of an inherited slot, of a mixin slot and of an inherited attribute, rule conditions, classification rules (also with is_a naming another class), range expressions (plain, over a class with a like-named attribute, inside a condition on a slot whose range the owner refines, on any_of branches with their own range, in nested slot expressions and all_members), same-named attributes in two classes, and a slot named in its underscored form.
    • A slot imported from a schema with another default_prefix, refined in slot_usage and named in slot_conditions: its restrictions stay on the property of the defining schema, in both modes.
    • kitchen_sink.yaml, both modes: every restricted property is declared.
    • The annotation-property check follows the owner: refused where the owner's slot is rdfs:label, not refused where only another class's is.
  • Without the fix 37 of the 57 fail. The 20 that pass are the 17 native-URI cases, the imported-slot test in native mode and both kitchen-sink tests; the kitchen sink does not trigger the bug and passes on main in both modes. They guard that default output and the restrictions on imported slots stay as they are.
  • Fourteen mutations of the fix (owner not passed on one of the paths, not used, range class ignored, the named slot taken wholesale, no underscored names, annotation check without the owner, …) each fail tests.
  • Original against fixed generator over every *.yaml in the repository (549 files; gen-owl generates from 409, the other 140 fail identically before and after), compared up to blank-node renaming:
    • default flags: 409 identical;
    • --no-use-native-uris: 401 identical, 8 differ (meta.yaml and units.yaml, each in two places, biolink-model.yaml, container_test.yaml, validation_datamodel.yaml, __snapshots__/multi_usages_2.yaml). In all 8 the set of declared properties is unchanged, every difference moves a restriction from an undeclared property to a declared one, and none is left on an undeclared one; e.g. 504 in biolink from biolink:subject / object / predicate / type to rdf:subject / rdf:object / rdf:predicate / rdf:type.
  • tests/linkml as CI runs it: 12879 passed, no snapshot changed.

Areas of uncertainty

  • An any_of / all_of operand with is_a (any_of: [{is_a: A, slot_conditions: …}]) keeps the stating class as owner, since gen-owl does not emit that is_a. With same-named attributes in the stating class and in A, the condition names the stating class's. Where the stating class has no such slot and several classes have an attribute of that name, the restriction stays on the name-derived IRI, which is not declared.
  • A slot_usage that sets its own slot_uri is restricted on that IRI, which the ontology does not declare. Unchanged for that class; a subclass that refines the slot further now follows it to the same IRI.
  • unique_keys and the type designator still resolve their slots by name alone. Unchanged.
  • The annotation-property check now refuses a condition on a slot that is an annotation property in its owner where a like-named slot elsewhere used to hide that. No schema in the repository is affected (549 files, both URI modes).

Checklist

  • My code follows the contributor guidelines
  • I have added tests that prove my fix/feature works
  • Existing tests pass locally with my changes

With --no-use-native-uris gen-owl declares a slot's property under its
slot_uri, but it stated the restrictions that come from a slot_usage or
slot_conditions entry on an IRI derived from the slot's name. Such an
entry names a slot and holds only what it adds, so it carries no
slot_uri. The restrictions of class-level boolean expressions, of rule
and classification-rule conditions, of range expressions, and of
slot_usage on an inherited slot were therefore on properties the
ontology does not declare, such as ex:note where the slot is skos:note,
which OWL 2 DL does not allow (Structural Specification 5.8.1).

The restriction now takes the slot_uri of the slot that the entry names
in the class the condition is about: the class that states the
expression, the class a rule's expression names with is_a, or, for a
range expression, the class the slot ranges over. Two classes with an
attribute of the same name each get their own property, and a name may
be written in its underscored form. Only the slot_uri is taken from the
named slot; the IRI derived from a slot's name is computed as before, so
with native URIs, the default, the output is unchanged.

The annotation-property check in the same loop reads the slot of the
same class, so a like-named slot elsewhere no longer decides whether a
condition is refused.

Signed-off-by: jdsika <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant