Skip to content

OWLAnonymousIndividual not implemented #217

Description

@htmai-880

The issue

Anonymous individuals are not implemented in OWLAPY. For example, attempting to load the following ontology (e.g., ontology_with_anonymous_individual.ttl):

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix ex: <http://example.org/> .

# Ontology declarations
<http://example.org/ontology> a owl:Ontology ;
    rdfs:label "Example Ontology with Anonymous Individual" .

# Class definitions
ex:Person a owl:Class ;
    rdfs:label "Person" .

ex:knows a owl:ObjectProperty ;
    rdfs:label "knows" ;
    rdfs:domain ex:Person ;
    rdfs:range ex:Person .

# Name

ex:Alice a ex:Person ;
    rdfs:label "Alice" ;
    ex:knows [ a ex:Person ] .

Using:

from owlapy.owl_ontology import SyncOntology
ontology = SyncOntology("ontology_with_anonymous_individual.ttl")
abox_axioms = ontology.get_abox_axioms()

Results in:

Traceback (most recent call last):
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 832, in dispatch
    impl = dispatch_cache[cls]
           ~~~~~~~~~~~~~~^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/weakref.py", line 415, in __getitem__
    return self.data[ref(key)]
           ~~~~~~~~~^^^^^^^^^^
KeyError: <weakref at 0x713b5ac1f4c0; to '_jpype._JClass' at 0x6067a4bbad50 (uk.ac.manchester.cs.owl.owlapi.OWLAnonymousIndividualImpl)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 835, in dispatch
    impl = registry[cls]
           ~~~~~~~~^^^^^
KeyError: <java class 'uk.ac.manchester.cs.owl.owlapi.OWLAnonymousIndividualImpl'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/XXX/Documents/owlapy-fix/owlapy-fixed/owlapy/owl_ontology.py", line 1346, in get_abox_axioms
    return self.mapper.map_(self.owlapi_ontology.getABoxAxioms(self._get_imports_enum(include_imports_closure)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 946, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/Documents/owlapy-fix/owlapy-fixed/owlapy/owlapi_mapper.py", line 644, in _
    python_list.append(self.map_(obj))
                       ^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 946, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/Documents/owlapy-fix/owlapy-fixed/owlapy/owlapi_mapper.py", line 432, in _
    return OWLClassAssertionAxiom(self.map_(e.getIndividual()), self.map_(e.getClassExpression()),
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 945, in _method
    method = self.dispatcher.dispatch(args[0].__class__)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 837, in dispatch
    impl = _find_impl(cls, registry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 784, in _find_impl
    mro = _compose_mro(cls, registry.keys())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 772, in _compose_mro
    return _c3_mro(cls, abcs=mro)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 725, in _c3_mro
    other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 725, in <listcomp>
    other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases]
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 725, in _c3_mro
    other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 725, in <listcomp>
    other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases]
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 726, in _c3_mro
    return _c3_merge(
           ^^^^^^^^^^
  File "/home/XXX/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 680, in _c3_merge
    raise RuntimeError("Inconsistent hierarchy")

Such a feature could be helpful for purposes such as class membership inference, in case not all individuals are known in advance, but some anonymous placeholders can be inserted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions