pyLODE icon indicating copy to clipboard operation
pyLODE copied to clipboard

TypeError: unhashable type: 'list' on nested class description

Open bretelerjmw opened this issue 1 year ago • 0 comments

When I run python -m pylode example.ttl on the example ontology below, I receive TypeError: unhashable type: 'list'. Here is the full error trace:

INFO:root:Loading background ontologies from a pickle file
DEBUG:asyncio:Using proactor: IocpProactor
Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python310\lib\site-packages\pylode\__main__.py", line 6, in <module>
    main()
  File "C:\Python310\lib\site-packages\pylode\cli.py", line 87, in main
    print(html.make_html(**pylode_kwargs))
  File "C:\Python310\lib\site-packages\pylode\profiles\ontpub.py", line 146, in make_html
    self._make_body()
  File "C:\Python310\lib\site-packages\pylode\profiles\ontpub.py", line 327, in _make_body
    self._make_main_sections()
  File "C:\Python310\lib\site-packages\pylode\profiles\ontpub.py", line 445, in _make_main_sections
    d = section_html(
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 872, in section_html
    _element_html(
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 811, in _element_html
    prop_obj_pair_html(
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 753, in prop_obj_pair_html
    o = rdf_obj_html(ont, back_onts, ns, obj, fids, rdf_type=obj_type, prop=prop_iri)
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 716, in rdf_obj_html
    return _rdf_obj_single_html(
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 709, in _rdf_obj_single_html
    ret = _bn_html(ont_, back_onts_, ns_, fids_, obj_)
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 702, in _bn_html
    return _setclass_html(ont__, obj__, back_onts__, ns__, fids__)
  File "C:\Python310\lib\site-packages\pylode\utils.py", line 684, in _setclass_html
    class_set.add(
TypeError: unhashable type: 'list'

The ontology input contains a class intersection nested inside a class union. I wonder if that's what's causing the trouble here. When I run pyLODE on either the union or the intersection alone, it's fine. I have tried to look at the code around utils.py:684 and I don't see explicit support for nesting, but admittedly, I struggle to follow exactly what is happening within the larger context of _rdf_obj_single_html.

Also, I have been running pyLODE on my actual ontology with this structure for a while, but I only recently started seeing this error. Could be it's related to some changes in pyLODE or its dependencies.

Example ontology

@prefix ex: <http://example.org/> .

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

ex:onto
  rdf:type owl:Ontology ;
  dcterms:title "Test ontology" ;
  dcterms:description "Test ontology" ;
.
ex:testProp
  rdf:type owl:ObjectProperty ;
  rdfs:range [
    owl:unionOf (
      ex:ClassA
      [
        owl:intersectionOf (
          ex:ClassB
          [
            a owl:Restriction ;
            owl:onProperty ex:propA ;
            owl:hasValue ex:valueA
          ]
        ) ;
      ]
    ) ;
  ] ;
  rdfs:subPropertyOf owl:topObjectProperty ;
.

bretelerjmw avatar Aug 16 '24 12:08 bretelerjmw