emmo-repo / CIF-ontology

Basic crystallography domain ontology based on EMMO and the CIF core dictionary.
Creative Commons Attribution 4.0 International
9 stars 4 forks source link

dic2owl error on building cif_core.dic #194

Open stuchalk opened 6 months ago

stuchalk commented 6 months ago

When using dic2owl to create cif_core.tll I get the following error:

Traceback (most recent call last):
  File "/Users/n00002621/Library/Python/3.11/bin/dic2owl", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/cli.py", line 95, in main
    dic2owl_run(
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 274, in main
    onto = gen.generate()
           ^^^^^^^^^^^^^^
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 118, in generate
    self._add_item(item)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 129, in _add_item
    self._add_data_value(item)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 185, in _add_data_value
    self._add_item(parent)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 127, in _add_item
    self._add_category(item)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 162, in _add_category
    self._add_category(parent_item)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 162, in _add_category
    self._add_category(parent_item)
  File "/Users/n00002621/PycharmProjects/CIF-ontology/dic2owl/dic2owl/dic2owl.py", line 165, in _add_category
    cls = types.new_class(name, (self.onto[parent_name],))
                                 ~~~~~~~~~^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ontopy/ontology.py", line 249, in __getitem__
    item = self.get_by_label(name)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ontopy/ontology.py", line 422, in get_by_label
    raise NoSuchLabelError(f"No label annotations matches '{label}'")
ontopy.utils.NoSuchLabelError: No label annotations matches 'CIF_CORE'

Any ideas how to fix? I am using the most recent version of the cif_core.dic (3.3.0 5/2/24) and the latest version of dic2owl (commits up through Commits on Nov 9, 2023)

Stuart

vaitkus commented 6 months ago

Temporary workaround

Open the cif_core.dic file and do the following changes:

  1. Line 8: "data_CIF_CORE" => data_CIF_CORE_DIC
  2. Line 10: " _dictionary.title CIF_CORE" -> "_dictionary.title CIF_CORE_DIC"
  3. Line 35: " _name.category_id CIF_CORE" -> "_name.category_id CIF_CORE_DIC"

After this, running dic2owl cif_core.dic should successfully build the cif_core.tll file.

The problem

Recently, the CIF_CORE dictionary was internally renamed from CORE_DIC to CIF_CORE to adhere to the newly agreed upon conventions. However, this also resulted in a CIF file in which the data block (top level container) and a save frame (lower level container) both have the same name (CORE_DIC). While this is perfectly valid in CIF, the dic2owl script seems to not process this very well. At least that is my educated guess.

Long term solution

There have been discussions in the CIF_CORE repository to also change the name of the save frame so the issue might just go away on its own. However, it would still make sense to also update the dic2owl script to properly process such valid CIF dictionary files.

vaitkus commented 6 months ago

@stuchalk Ok, so with the recent changes to the CIF_CORE dictionary (https://github.com/COMCIFS/cif_core/pull/492), this bug no longer manifests. Just remove all of the ignored/generated files and rerun the ttl file build command.

While the underlying issue in the software is still present, it is unlikely to manifest again with the IUCr CIF dictionaries given the recently agreed upon naming conventions (https://github.com/COMCIFS/cif_core/issues/488). Patching the bug would be nice, but the issue should be viewed as having a much lower priority.