Skip to content

[mirror] fix(owlgen): decide the kind of a property by all ranges of its slot - #73

Open
jdsika wants to merge 2 commits into
fix/owlgen-literal-enumsfrom
fix/owlgen-any-of-property-kind
Open

jdsika wants to merge 2 commits into
fix/owlgen-literal-enumsfrom
fix/owlgen-any-of-property-kind

Conversation

@jdsika

@jdsika jdsika commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Fork base is fix/owlgen-literal-enums (linkml#4279), so this diff shows only this PR's two commits.

The description below is the one on linkml#4280.

Stacked on linkml#4279; merge after it. Review the last two commits: fix(owlgen): decide the kind of a property by all ranges of its slot and the review follow-up fix(owlgen): give a slot without a range the kind of the one it inherits. The first two commits are linkml#4279.

Summary

gen-owl decides whether a slot is a data property or an object property from its range alone, or from the default range when it has none. It ignores any_of and exactly_one_of, so with the usual default range string:

  • a slot whose any_of lists classes is a data property, with a union of classes as its range;
  • a slot whose any_of lists a type and a class is a data property too, and its range mixes a datatype and a class.

In OWL 2 DL, a data property has literal values, an object property has individuals, and no IRI is both kinds. ROBOT and Protégé therefore report such ontologies as outside OWL 2 DL. kitchen_sink has one class for each case: AnyOfClasses, AnyOfEnums and AnyOfMix.

This PR decides the kind from all ranges of a slot. Where OWL cannot express what the schema says, gen-owl leaves it out with a warning instead of writing invalid OWL.

In plain words: A vehicle's parts are wheels or doors, and its speed is a number or a quantity with a unit. gen-owl only looked at the default range, string, and declared both as text-valued properties, while the same file says their values are wheels, doors and quantities. Now parts links to things. speed can hold a number or a thing, and no OWL property can hold both. So it becomes a property that links to things without saying which, and gen-owl warns about it.

Refs linkml#1483: the default range "should not be applied if there is a any_of with ranges".

Reproduce

vehicles.yaml:

id: https://example.org/vehicles
name: vehicles
prefixes:
  linkml: https://w3id.org/linkml/
  ex: https://example.org/vehicles/
default_prefix: ex
default_range: string
imports:
  - linkml:types
classes:
  Wheel: {}
  Door: {}
  Quantity:
    attributes:
      value:
        range: float
      unit: {}
  Vehicle:
    slots: [parts, speed, seats]
slots:
  parts:
    multivalued: true
    any_of:
      - range: Wheel
      - range: Door
  speed:
    any_of:
      - range: float
      - range: Quantity
  seats:
    range: integer
    exactly_one_of:
      - minimum_value: 1
        maximum_value: 9
      - minimum_value: 20
        maximum_value: 80
gen-owl vehicles.yaml > vehicles.owl.ttl
robot validate-profile --profile DL --input vehicles.owl.ttl --output report.txt

With ROBOT 1.9.11; main (eff06809d) and linkml#4279 give the same:

main this PR
parts owl:DatatypeProperty, range the union of Wheel and Door owl:ObjectProperty, the same range
speed owl:DatatypeProperty, range the union of xsd:float and Quantity owl:ObjectProperty without a range, and the warning "Slot 'speed' ranges over both literals and nodes, which neither an object nor a data property can have, so it has no range and its values are not restricted"
seats exactly_one_of gives untyped unions, intersections and owl:complementOf each is a rdfs:Datatype, with owl:datatypeComplementOf
OWL 2 DL profile 24 violations ("Cannot pun between properties", "Use of reserved vocabulary for class IRI: xsd:float", …) in the profile

Each data file below is concatenated with the ontology and then checked:

data profile violations, main → this PR HermiT, both
ex:car a ex:Vehicle ; ex:parts ex:wheel1 ; ex:seats 4 . ex:wheel1 a ex:Wheel . 26 → 0 consistent
ex:bus a ex:Vehicle ; ex:seats 15 . 24 → 0 inconsistent: 15 is in neither 1–9 nor 20–80
ex:car a ex:Vehicle ; ex:speed ex:q1 . ex:q1 a ex:Quantity ; ex:value "120.0"^^xsd:float ; ex:unit "km/h" . 31 → 0 consistent
ex:car a ex:Vehicle ; ex:speed "120.0"^^xsd:float . 29 → 5 consistent

The 5 remaining violations in the last row are on speed: an object property cannot have a literal value (see Areas of uncertainty).

Why this is wrong

The change

  • The kind of a property comes from all ranges of its slot: range (or else the one it inherits through is_a and its mixins), and those in any_of, all_of, exactly_one_of, none_of, all_members and has_member, or else the default range. A range_expression with slot conditions counts as a class. A branch of any_of without a range, such as one with only a pattern, has the range around it. Any adds nothing beside other ranges. A role declared with implements comes first.
    • Literal values only give a data property, and IRIs or blank nodes only give an object property.
    • Both give an object property, as linkml:Any does, without a range, with a warning.
    • A slot without ranges keeps the kind that the classes narrowing it give it.
  • What OWL cannot state is left out with a warning:
    • a restriction where a class narrows a slot to values its property cannot have, for example a string slot to a class;
    • the any_of or exactly_one_of of a class, a rule or a classification rule, when it has a condition on such a slot, because leaving out only the condition could make the axiom stronger;
    • for all_of and none_of, only the affected operand.
  • Typing of expressions. exactly_one_of and nested boolean expressions take their types from their operands, so over data ranges they are data ranges. An expression over an enum that is a class is no longer typed rdfs:Datatype.
  • Refinements without a range. A class that refines a slot of nodes without giving a range restricts it to owl:Thing, not to the default datatype.
  • Review. A slot without a range of its own has the kind of the range it inherits through is_a and its mixins, as SchemaView.induced_slot gives it, and a class's restriction of it is filled with that range. On main and before, owner: {is_a: ref} with ref ranging over a class was a data property under an object property, and width: {is_a: size} with size ranging over integer was restricted to xsd:string. The metamodel and biolink snapshots change accordingly (12 and 14 lines).
  • Review. The OWL snapshots (kitchen_sink in three formats, and the metamodel) are their previous version with only the changed triples. The kitchen_sink Turtle diff goes from 845 lines to 41, and the metamodel's from 1976 to 290. The description of a slot's ranges in owl.rst is shorter.

No public signatures change.

Other generators

  • gen-shacl (sh:or of sh:datatype and sh:class), gen-json-schema (anyOf) and linkml-validate express a slot that mixes literals and objects, and so accept both values of speed. OWL 2 DL cannot, so gen-owl leaves the restriction out rather than state something false; the ontology then admits more.
  • fix(generators): translate patterns for OWL and SHACL, list allowed strings linkml/linkml#4276 also leaves out expressions that would become stronger without a part, there a pattern with no XML Schema equivalent. For none_of, it leaves out the whole expression, where this PR leaves out only the operand. Both are sound, and whichever merges second can share one mechanism.

How was this tested?

  • test_owlgen.py: 14 new tests with 27 cases.
    • They cover: classes and mixes in any_of, exactly_one_of and has_member; branches without a range; class expressions that OWL cannot state; narrowings to the other kind; attributes that several classes define; Any with any_of; slots narrowed only by classes; and the typing of unions, intersections and complements, with and without a default range and type_objects.
    • 23 of the 27 fail on fix(owlgen): make an enum of literals a datatype linkml/linkml#4279; the other 4 check what stays unchanged.
  • test_owl_annotation_properties.py: a condition on an annotation property is still an error inside an any_of that is left out.
  • Repository schemas. Every *.yaml in the repository (527 files, gen-owl generates 401), fix(owlgen): make an enum of literals a datatype linkml/linkml#4279 against this PR, up to blank-node renaming:
    • 29 files differ with the CLI defaults, 43 with the API defaults, and 16 and 48 with --default-permissible-value-type rdfs:Literal.
    • Ranges and fillers of the wrong kind for their property go from 71 to 10 (CLI), 137 to 71 (API), 24 to 9 and 191 to 78.
    • No file gets worse on any of these checks.
    • The review's inheritance fix changes 9 more files with the API defaults. ROBOT counts fewer OWL 2 DL violations in all 9 (for example the metamodel 149 → 136, biolink 1666 → 1079); in biolink, opposite_of becomes an object property like its parent related_to, and its use as an annotation key now shows as 24 "undeclared annotation property" in place of "cannot pun".
    • ROBOT's OWL 2 DL check of the changed files counts 3671 → 2147 violations with the CLI defaults (27 files fewer, 2 the same, none more). With the API defaults it counts 3541 → 3418 (26 / 2 / 15); the 15 are the facets under type_objects in uncertainty 4.
  • Example. The example above, run against main, fix(owlgen): make an enum of literals a datatype linkml/linkml#4279 and this PR with ROBOT 1.9.11.
  • Time. Generating biolink takes 5.3 s with fix(owlgen): make an enum of literals a datatype linkml/linkml#4279 and 5.7 s with this PR.
  • Suites. CI runs tests/linkml and tests/linkml_runtime in full on this head. Locally, the 612 tests that exercise gen-owl and the 66 slow tests pass on it, and ruff passes.

Areas of uncertainty

  1. Mixed slots become object properties. A slot over both literals and nodes has no OWL 2 DL kind. An object property keeps the nodes, which carry structure, in OWL 2 DL, and makes a literal value the exception (last row above). A data property would do the reverse, and two properties would need an IRI the schema does not name.
  2. Restrictions this PR leaves out. Where a class narrows a slot to values of the other kind, the restriction goes, with a warning: for example, FamilialRelationship SubClassOf type only FamilialRelationshipType in personinfo, and 32 qualifiers in Biolink. None of them was OWL 2 DL; giving the slot a range in the schema fixes them.
  3. Whole expressions left out. When an any_of is left out for one operand, what its other operands say goes too. A rewrite to the strongest expression OWL can state would keep more; this PR only ever says less.
  4. type_objects. Types are classes, so expressions over them are no longer typed rdfs:Datatype. Their facets are still restrictions of datatypes intersected with the type's class, which is not OWL 2 DL with or without this PR. Some files show a few more OWL API violations under the API defaults.
  5. Merge. This conflicts with fix(owlgen): state restrictions on the property a slot is declared as linkml/linkml#4260 and fix(owlgen): restrict a condition to the range of the slot it names linkml/linkml#4273 in transform_class_expression and its fallback, and with fix(generators): translate patterns for OWL and SHACL, list allowed strings linkml/linkml#4276 in the omission logic and the snapshots. Whichever merges later regenerates its snapshots.

Checklist

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

@jdsika
jdsika force-pushed the fix/owlgen-any-of-property-kind branch from dec9b7e to e8a6622 Compare November 25, 2026 15:54
gen-owl took the kind of a property from the range of its slot, or from
the default range for a slot without one, and not from any_of or
exactly_one_of. With a type as the default range, a slot whose any_of
lists classes, or enums that are classes, was a data property with a
union of classes as its range. A slot whose any_of lists a type and a
class was a data property too, and its range and restrictions mixed a
datatype and a class. The values of an object property are individuals
and those of a data property are literals, and in OWL 2 DL an IRI is not
both, so the OWL API reads such a property as both kinds and the
datatype as a class.

The kind of a property now comes from all ranges of its slot, those that
gen-owl already collects for enums of literals: the ranges of its range,
range_expression, any_of, all_of, exactly_one_of, none_of and
all_members, or else the default range, and those of its has_member. A
branch of any_of or exactly_one_of without a range, such as one with
only a pattern, has the range of the expression it is in, or else that
of the slot, or else the default range. Operands of all_of and none_of
only narrow a slot and add no kind, and linkml:Any adds none beside
other ranges, as the documentation of unions as ranges gives a slot the
range Any and lists its ranges in any_of. A role that the slot declares
with implements comes first; otherwise, if the values of each range are
literals, the slot is a data property, and if they are IRIs or blank
nodes, an object property. A slot without ranges, in a schema without a
default range, keeps the kind that the classes that narrow it give it,
and an enum that is a class, or a type under type_objects, now counts as
nodes there, as a class does.

Where OWL cannot state what the schema says, gen-owl now leaves it out
and logs a warning. No OWL property has both literals and individuals as
values, so a slot that ranges over both is an object property, as a slot
of linkml:Any is, without a range, and classes do not restrict its
values. A class that narrows a slot to values that its property cannot
have, such as a slot of strings to a class, does not restrict it there.
A slot whose range_expression, or that of its has_member or of an
expression in it, has a condition that OWL cannot state has no range
either. Of a class, an any_of or exactly_one_of with an operand that has
such a condition is left out, as is a rule or classification rule with
one, since leaving out only the condition could make the axiom stronger;
of all_of and none_of, only the operand is left out.

A class that refined a slot without giving a range restricted it to
owl:Thing if the range of the slot is a class, and else to the default
range, so to a datatype for a slot whose any_of lists classes or whose
range is an enum that is a class. Such a slot now gets owl:Thing too.
The expressions of exactly_one_of were given the types of the slot,
which gen-owl records differently from those of their operands, so over
data ranges they were untyped and their complements were complements of
classes. They now take the types of their operands, as unions do, and
complements and intersections pass their types on to the expressions
that have them as operands, so over data ranges these are data ranges,
with owl:datatypeComplementOf. An expression over an enum that is a
class has the types of a class expression, as one over a class has, so
its intersection with the data range of a constraint, such as
equals_string_in, is no longer typed as a datatype.

Refs linkml#1483

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
@jdsika
jdsika force-pushed the fix/owlgen-literal-enums branch from bae0af3 to d14debb Compare November 25, 2026 16:48
@jdsika
jdsika force-pushed the fix/owlgen-any-of-property-kind branch from e8a6622 to 0d80ae8 Compare November 25, 2026 16:48
@jdsika
jdsika force-pushed the fix/owlgen-any-of-property-kind branch from 0d80ae8 to 9d50bde Compare November 26, 2026 10:42
A slot without a range of its own took the kind of its property from
the default range, so owner with is_a ref, where ref ranges over a
class, became a data property that is a sub-property of an object
property, which OWL 2 DL does not allow (OWL 2 9.2.1, 9.3.1). It now
has the range it inherits through is_a and its mixins, as
SchemaView.induced_slot gives it: of the metaslots that give ranges
only range is inherited, from the first ancestor in slot_ancestors
order that has one, and not by an attribute. A class's restriction of
such a slot is filled with that range too, not with the default range,
unless its values are IRIs or blank nodes, as those of uriorcurie, which
no datatype has. In the snapshots of the metamodel and of biolink, the
slots that inherit boolean or integer get these as fillers, not string.

The OWL snapshots of kitchen_sink and of the metamodel were written
anew, so their blank nodes were renumbered and nearly every line
changed. They are now their previous version with only the triples
that this change adds or removes; the snapshot tests compare them as
graphs, up to blank-node renaming.

Shorten the description of the ranges of a slot in owl.rst.

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
@jdsika
jdsika force-pushed the fix/owlgen-any-of-property-kind branch from 9d50bde to e1cb9e7 Compare November 26, 2026 11:04
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