Skip to content

Conversation

wb0206
Copy link

@wb0206 wb0206 commented Sep 25, 2025

Add support for ObjectHasValue constraints in OWL import engine

Summary

This PR adds support for ObjectHasValue constraints in the OWL import engine, which was previously missing and causing conversion errors.

Problem

When converting OWL ontologies that contain ObjectHasValue constraints (e.g., SubClassOf(:SomeClass ObjectHasValue(:hasState :SomeState))), the schema-automator would log errors like:

ERROR:root:cannot handle anon parent classes for SubClassOf(subClassExpression=Class(v='soma:DissolvedGas'), superClassExpression=ObjectHasValue(objectPropertyExpression=ObjectPropertyExpression(v=ObjectProperty(v='sorel:hasState')), individual=Individual(v=NamedIndividual(v='sostp:Gas'))), annotations=[])

This resulted in loss of important semantic constraints during OWL-to-LinkML conversion.

Solution

Added support for ObjectHasValue constraints by:

  1. Added ObjectHasValue handling: New elif isinstance(a.superClassExpression, ObjectHasValue) branch in the SubClassOf processing logic
  2. Converts to equals_string: Maps ObjectHasValue constraints to LinkML's slot_usage.equals_string pattern, similar to existing DataHasValue handling
  3. Preserves semantic information: No information is lost during conversion

Technical Details

The implementation follows the same pattern as the existing DataHasValue handler:

elif isinstance(a.superClassExpression, ObjectHasValue):
    x = a.superClassExpression
    p = self.iri_to_name(x.objectPropertyExpression)
    # Get the individual name
    individual_name = self.iri_to_name(x.individual)
    # Store as equals_string constraint (LinkML doesn't have object equals, so we use string)
    set_slot_usage(p, 'equals_string', individual_name)

Before/After Comparison

Before (with errors):

DissolvedGas:
  is_a: DissolvedSubstance
  class_uri: soma:DissolvedGas

After (constraints preserved):

DissolvedGas:
  is_a: DissolvedSubstance
  slot_usage:
    hasState:
      equals_string: Gas
  class_uri: soma:DissolvedGas

Testing

  • Added comprehensive test case in tests/test_importers/test_owl_object_has_value.py
  • Test verifies ObjectHasValue constraints are correctly converted to slot_usage.equals_string
  • All existing tests continue to pass
  • Tested with real-world SWEET ontology examples

Impact

  • No breaking changes: Existing functionality unchanged
  • Backward compatible: No impact on existing workflows
  • Semantic preservation: Previously lost constraints are now preserved
  • Error reduction: Eliminates "cannot handle anon parent classes" errors for ObjectHasValue

This enhancement makes schema-automator more robust for converting complex OWL ontologies that use ObjectHasValue constraints, which are common in scientific domain ontologies.

- Add handling for ObjectHasValue expressions in SubClassOf axioms
- Convert ObjectHasValue to slot_usage.equals_string constraints
- Preserve semantic information that was previously lost
- Fix "cannot handle anon parent classes" errors
- Add comprehensive test coverage
- Maintain backward compatibility
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