From 99778b5326edae08401afd3eab2ce866a1a489d0 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Wed, 18 Aug 2021 08:58:27 +0200 Subject: [PATCH 1/9] Initial work on updated generator script - Added workaround for EMMO-python. --- dic2owl/dic2owl/dic2owl.py | 253 +++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 dic2owl/dic2owl/dic2owl.py diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py new file mode 100644 index 0000000..553771a --- /dev/null +++ b/dic2owl/dic2owl/dic2owl.py @@ -0,0 +1,253 @@ +#!/usr/bin/env python +"""Python script for generating an ontology corresponding to a CIF dictionary. +""" +from pathlib import Path +import textwrap +import types +from typing import Union +import urllib.request + +from emmo import World + +import owlready2 +from owlready2 import locstr + +from CifFile import CifDic + + +# Workaround for EMMO-Python +# Make sure that we can load cif-ddl.ttl which doesn't import SKOS +import emmo.ontology +emmo.ontology.DEFAULT_LABEL_ANNOTATIONS = [ + 'http://www.w3.org/2000/01/rdf-schema#label', +] + + +def en(s): + """Returns `s` converted to a localised string in english.""" + return locstr(s, lang="en") + + +def ontology_dir() -> Path: + """Return the absolute, normalized path to the `ontology` directory in this repository""" + return Path(__file__).resolve().parent.parent.parent.joinpath("ontology") + + +class Generator: + """Class for generating CIF ontology from a CIF dictionary. + + Parameters: + dicfile : string + File name of CIF dictionary to generate an ontology for. + base_iri : string + Base IRI of the generated ontology. + """ + + def __init__(self, + dicfile: str, + base_iri: str): + self.dic = CifDic(dicfile, do_dREL=False) + + # Load cif-ddl ontology + self.world = World() + cif_ddl = ontology_dir() / 'cif-ddl.ttl' + self.ddl = self.world.get_ontology(str(cif_ddl)).load() + self.ddl.sync_python_names() + + # Create new ontology + self.onto = self.world.get_ontology(base_iri) + self.onto.imported_ontologies.append(self.ddl) + + self.categories = set() + + def generate(self): + """Generate ontology for the CIF dictionary.""" + self._add_dic_top() + + for item in self.dic: + if "_definition.scope" in item and '_definition.id' in item: + self._add_category(item) + else: + self._add_data_value(item) + return self.onto + + def _add_dic_top(self): + """Add the top class of the generated ontology.""" + pass + + def _add_category(self, item): + """Add category.""" + if item in self.categories: + return + self.categories.add(item) + + print('*** category', item) + name = item['_definition.id'] + parent_name = item['_name.category_id'] + parent_item = self.dic[parent_name] + #if parent_item not in self.categories: + # self._add_category(parent_item) + # + #with self.onto: + # + # cat = types.new_class(name, (self.onto[parent_name], )) + + + + +# name = item["_definition.id"] +# descr = item.get("_description.text") +# lname = "_" + name.lstrip("_").lower() +# with self.onto: +# if item.get("_definition.class"): +# loop = types.new_class(lname + "_LOOP", (self.top.LOOP,)) +# loop.prefLabel.append(en(loop.name.lstrip("_"))) +# packet = types.new_class(lname + "_PACKET", (self.top.PACKET,)) +# packet.prefLabel.append(en(packet.name.lstrip("_"))) +# cat = types.new_class(name, (self.top.CATEGORY,)) +# cat.prefLabel.append(en(cat.name.lstrip("_"))) +# if descr: +# cat.comment.append(en(textwrap.dedent(descr))) +# loop.is_a.append(self.top.hasSpatialDirectPart.some(packet)) +# loop.is_a.append(self.top.hasSpatialPart.only(cat)) +# else: +# print("** ignoring category:", name) + + def _add_data_value(self, item): + """Add data item.""" + realname = item["_definition.id"] +# name = realname.replace(".", "_") +# descr = item.get("_description.text") +# units = item.get("_units.code") +# aliases = item.get("_alias.definition_id") +# examples = item.get("_description_example.detail", []) +# examples.extend(item.get("_description_example.case", [])) +# dimension = item.get("_type.dimension") +# +# container_name = item.get("_type.container", "Single") +# datatype_name = item.get("_type.contents", "Text") +# category_name = item["_name.category_id"].upper() +# packet_name = "_%s_PACKET" % item["_name.category_id"] +# +# container = self.onto[container_name] +# datatype = self.onto[datatype_name] +# category = self.onto[category_name] +# +# with self.onto: +# +# if container_name == "Single": +# e = types.new_class(name, (datatype,)) +# elif container_name in ("Matrix", "Array"): +# dims = dimension.strip("[]") +# if dims: +# subarr = self.subarray(dims.split(","), datatype, container_name) +# e = types.new_class(name, (subarr,)) +# else: +# e = types.new_class(name, (datatype,)) +# else: +# e = types.new_class(name, (container,)) +# if container_name == "List": +# e.is_a.append(self.top.hasSpatialDirectPart.some(datatype)) +# else: +# e.is_a.append(self.top.hasSpatialPart.some(datatype)) +# +# if category.disjoint_unions: +# category.disjoint_unions[0].append(e) +# else: +# category.disjoint_unions.append([e]) +# e.prefLabel.append(en(realname.lstrip("_"))) +# if name != realname: +# e.altLabel.append(en(name.lstrip("_"))) +# +# # Hmm, _name is already used internally by owlready2.Ontology +# # so `e._name.append(name)` won't work. +# # We have to add the tripple the hard way... +# o, d = owlready2.to_literal(realname) # not localised +# self.onto._set_data_triple_spod( +# s=e.storid, p=self.onto.world._props["_name"].storid, o=o, d=d +# ) +# +# if aliases: +# e.altLabel.extend(en(a) for a in aliases) +# if descr: +# e.comment.append(en(textwrap.dedent(descr))) +# if examples: +# e.example.extend(en(textwrap.dedent(ex)) for ex in examples) +# if units: +# e._unit.append(units) # not localised +# if dimension: +# e._dimension.append(dimension) # not localised +# if datatype: +# e._datatype.append(datatype) # not localised +# if packet_name in self.onto: +# packet = self.onto[packet_name] +# packet.is_a.append(self.top.hasSpatialDirectPart.max(1, e)) +# else: +# print("** no packet:", realname) + +# def subarray(self, dimensions, datatype, container_name): +# """Returns a reference to an array or matrix corresponding to: +# - dimensions: list of dimension values +# - typename: type of elements +# - container_name: "Array" or "Matrix" +# If it does not already exists, the subarray is created. All +# its spatial direct parts are also generated recursively. +# """ +# if not dimensions or not dimensions[0]: +# return datatype +# name = "Shape" + "x".join(dimensions) + datatype.name + container_name +# if name not in self.onto: +# e = types.new_class(name, (self.onto[container_name],)) +# d = int(dimensions.pop(0)) +# e.is_a.append( +# self.top.hasSpatialDirectPart.exactly( +# d, self.subarray(dimensions, datatype, container_name) +# ) +# ) +# return self.onto[name] + + +def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: + base_iri = "http://emmo.info/CIF-ontology/ontology/cif_core#" + + dicfile = dicfile if isinstance(dicfile, str) else str(dicfile.resolve()) + + # Download the CIF dictionaries to current directory + baseurl = "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" + for dic in ("ddl.dic", "templ_attr.cif", "templ_enum.cif", dicfile): + if not Path(dic).resolve().exists(): + print("downloading", dic) + urllib.request.urlretrieve(baseurl + dic, dic) + + gen = Generator(dicfile=dicfile, base_iri=base_iri) + onto = gen.generate() + +# # Annotate ontology +# onto.sync_attributes() +# onto.set_version(version="0.0.1") +# onto.metadata.abstract = ( +# "CIF core ontology generated from the CIF core definitions at " +# "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" +# ) +# +# if ttlfile is None: +# ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" + + onto.save( + ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()), + overwrite=True, + ) + + return gen # XXX - just for debugging + + +if __name__ == "__main__": + # main() + + # for debugging and testing... + self = gen = main("cif_core.dic", "cif_core.ttl") + dic = self.dic + ddl = self.ddl + onto = self.onto + #sid = cd["space_group_symop.id"] + #s = cd["SPACE_GROUP_SYMOP"] From 9f739b3abdf8d6cabf0721fa1d7431336809d5f3 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Wed, 18 Aug 2021 13:25:34 +0200 Subject: [PATCH 2/9] Remove owlready2 import printing Update doc-strings and type information. --- dic2owl/dic2owl/cli.py | 4 +- dic2owl/dic2owl/dic2owl.py | 181 ++++++++++++++++++++------------ dic2owl/dic2owl/generate_cif.py | 17 ++- 3 files changed, 130 insertions(+), 72 deletions(-) diff --git a/dic2owl/dic2owl/cli.py b/dic2owl/dic2owl/cli.py index 8297de3..a8f1694 100644 --- a/dic2owl/dic2owl/cli.py +++ b/dic2owl/dic2owl/cli.py @@ -6,7 +6,7 @@ LOGGING_LEVELS = [logging.getLevelName(level).lower() for level in range(0, 51, 10)] -def main(args: list = None): +def main(argv: list = None) -> None: """Ontologize CIF dictionaries (`.dic`) using OWL. Produce an OWL Turtle (`.ttl`) file from a CIF dictionary (`.dic`) file. @@ -54,7 +54,7 @@ def main(args: list = None): help="The CIF dictionary file from which to generate an OWL ontologized Turtle file.", ) - args = parser.parse_args(args) + args = parser.parse_args(argv) if args.ttlfile is None: args.ttlfile = args.dicfile.resolve().name[: -len(args.dicfile.suffix)] + ".ttl" diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index 553771a..a7c4924 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -1,16 +1,27 @@ #!/usr/bin/env python -"""Python script for generating an ontology corresponding to a CIF dictionary. """ +# Generate ontology + +Python script for generating an ontology corresponding to a CIF dictionary. +""" +from contextlib import redirect_stderr +from os import devnull as DEVNULL from pathlib import Path -import textwrap -import types + +# import textwrap +# import types from typing import Union import urllib.request -from emmo import World +# Remove the print statement concerning 'owlready2_optimized' +# when importing owlready2 (which is imported also in emmo). +with open(DEVNULL, "w") as handle: + with redirect_stderr(handle): + from emmo import World + from emmo.ontology import Ontology -import owlready2 -from owlready2 import locstr + # import owlready2 + from owlready2 import locstr from CifFile import CifDic @@ -18,39 +29,47 @@ # Workaround for EMMO-Python # Make sure that we can load cif-ddl.ttl which doesn't import SKOS import emmo.ontology + emmo.ontology.DEFAULT_LABEL_ANNOTATIONS = [ - 'http://www.w3.org/2000/01/rdf-schema#label', + "http://www.w3.org/2000/01/rdf-schema#label", ] +"""Return the absolute, normalized path to the `ontology` directory in this repository""" +ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath("ontology") -def en(s): - """Returns `s` converted to a localised string in english.""" - return locstr(s, lang="en") +def en(string: str) -> locstr: + """Converted to an English-localized string. + + Parameters: + string: The string to be converted. + + Returns: + An English-localized string. `locstr` is a `str`-based type. -def ontology_dir() -> Path: - """Return the absolute, normalized path to the `ontology` directory in this repository""" - return Path(__file__).resolve().parent.parent.parent.joinpath("ontology") + """ + return locstr(string, lang="en") class Generator: """Class for generating CIF ontology from a CIF dictionary. Parameters: - dicfile : string - File name of CIF dictionary to generate an ontology for. - base_iri : string - Base IRI of the generated ontology. + dicfile (str): File name of CIF dictionary to generate an ontology for. + base_iri (str): Base IRI of the generated ontology. + """ - def __init__(self, - dicfile: str, - base_iri: str): + def __init__( + self, + dicfile: str, + base_iri: str, + ) -> None: self.dic = CifDic(dicfile, do_dREL=False) # Load cif-ddl ontology self.world = World() - cif_ddl = ontology_dir() / 'cif-ddl.ttl' + cif_ddl = ONTOLOGY_DIR / "cif-ddl.ttl" self.ddl = self.world.get_ontology(str(cif_ddl)).load() self.ddl.sync_python_names() @@ -60,62 +79,76 @@ def __init__(self, self.categories = set() - def generate(self): - """Generate ontology for the CIF dictionary.""" + def generate(self) -> Ontology: + """Generate ontology for the CIF dictionary. + + Returns: + The generated ontology. + + """ self._add_dic_top() for item in self.dic: - if "_definition.scope" in item and '_definition.id' in item: + if "_definition.scope" in item and "_definition.id" in item: self._add_category(item) else: self._add_data_value(item) return self.onto - def _add_dic_top(self): + def _add_dic_top(self) -> None: """Add the top class of the generated ontology.""" pass - def _add_category(self, item): - """Add category.""" + def _add_category(self, item: dict) -> None: + """Add category. + + Parameters: + item: Item to be added to the list of categories. + + """ if item in self.categories: return self.categories.add(item) - print('*** category', item) - name = item['_definition.id'] - parent_name = item['_name.category_id'] + print("*** category", item) + name = item["_definition.id"] + parent_name = item["_name.category_id"] parent_item = self.dic[parent_name] - #if parent_item not in self.categories: + # if parent_item not in self.categories: # self._add_category(parent_item) # - #with self.onto: + # with self.onto: # # cat = types.new_class(name, (self.onto[parent_name], )) + # name = item["_definition.id"] + # descr = item.get("_description.text") + # lname = "_" + name.lstrip("_").lower() + # with self.onto: + # if item.get("_definition.class"): + # loop = types.new_class(lname + "_LOOP", (self.top.LOOP,)) + # loop.prefLabel.append(en(loop.name.lstrip("_"))) + # packet = types.new_class(lname + "_PACKET", (self.top.PACKET,)) + # packet.prefLabel.append(en(packet.name.lstrip("_"))) + # cat = types.new_class(name, (self.top.CATEGORY,)) + # cat.prefLabel.append(en(cat.name.lstrip("_"))) + # if descr: + # cat.comment.append(en(textwrap.dedent(descr))) + # loop.is_a.append(self.top.hasSpatialDirectPart.some(packet)) + # loop.is_a.append(self.top.hasSpatialPart.only(cat)) + # else: + # print("** ignoring category:", name) + + def _add_data_value(self, item: dict) -> None: + """Add data item. + + Parameters: + item: Item to be added as a datum. + + """ + realname = item["_definition.id"] - -# name = item["_definition.id"] -# descr = item.get("_description.text") -# lname = "_" + name.lstrip("_").lower() -# with self.onto: -# if item.get("_definition.class"): -# loop = types.new_class(lname + "_LOOP", (self.top.LOOP,)) -# loop.prefLabel.append(en(loop.name.lstrip("_"))) -# packet = types.new_class(lname + "_PACKET", (self.top.PACKET,)) -# packet.prefLabel.append(en(packet.name.lstrip("_"))) -# cat = types.new_class(name, (self.top.CATEGORY,)) -# cat.prefLabel.append(en(cat.name.lstrip("_"))) -# if descr: -# cat.comment.append(en(textwrap.dedent(descr))) -# loop.is_a.append(self.top.hasSpatialDirectPart.some(packet)) -# loop.is_a.append(self.top.hasSpatialPart.only(cat)) -# else: -# print("** ignoring category:", name) - - def _add_data_value(self, item): - """Add data item.""" - realname = item["_definition.id"] # name = realname.replace(".", "_") # descr = item.get("_description.text") # units = item.get("_units.code") @@ -208,6 +241,22 @@ def _add_data_value(self, item): def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: + """Main function for ontology generation. + + Parameters: + dicfile: Absolute or relative path to the `.dic`-file to be converted to an ontology. + This can be either a local path or a URL path. + ttlfile: Absolute or relative path to the Turtle (`.ttl`) file to be created from the + `dicfile`. The Turtle file contains the generated ontology in OWL. This **must** be a + local path. + + !!! important + The file will be overwritten if it already exists. + + Returns: + The setup ontology generator class. This is mainly returned for debugging reasons. + + """ base_iri = "http://emmo.info/CIF-ontology/ontology/cif_core#" dicfile = dicfile if isinstance(dicfile, str) else str(dicfile.resolve()) @@ -222,16 +271,16 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: gen = Generator(dicfile=dicfile, base_iri=base_iri) onto = gen.generate() -# # Annotate ontology -# onto.sync_attributes() -# onto.set_version(version="0.0.1") -# onto.metadata.abstract = ( -# "CIF core ontology generated from the CIF core definitions at " -# "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" -# ) -# -# if ttlfile is None: -# ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" + # # Annotate ontology + # onto.sync_attributes() + # onto.set_version(version="0.0.1") + # onto.metadata.abstract = ( + # "CIF core ontology generated from the CIF core definitions at " + # "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" + # ) + # + # if ttlfile is None: + # ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" onto.save( ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()), @@ -249,5 +298,5 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: dic = self.dic ddl = self.ddl onto = self.onto - #sid = cd["space_group_symop.id"] - #s = cd["SPACE_GROUP_SYMOP"] + # sid = cd["space_group_symop.id"] + # s = cd["SPACE_GROUP_SYMOP"] diff --git a/dic2owl/dic2owl/generate_cif.py b/dic2owl/dic2owl/generate_cif.py index 777d1ac..55f7ce8 100644 --- a/dic2owl/dic2owl/generate_cif.py +++ b/dic2owl/dic2owl/generate_cif.py @@ -1,15 +1,24 @@ #!/usr/bin/env python -"""Python script for generating an ontology corresponding to a CIF dictionary. """ +# Generate ontology + +Python script for generating an ontology corresponding to a CIF dictionary. +""" +from contextlib import redirect_stderr +from os import devnull as DEVNULL from pathlib import Path import textwrap import types from typing import Union import urllib.request -from emmo import World -import owlready2 -from owlready2 import locstr +# Remove the print statement concerning 'owlready2_optimized' +# when importing owlready2 (which is imported also in emmo). +with open(DEVNULL, "w") as handle: + with redirect_stderr(handle): + from emmo import World + import owlready2 + from owlready2 import locstr from CifFile import CifDic From 9aa17062bc8dcd0d12d1997966ff5ee97a9f863b Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Thu, 19 Aug 2021 10:02:02 +0200 Subject: [PATCH 3/9] Fixed adding top-level classes Fixed the problem with adding top-level class in generated ontology. Also added annotations. --- .github/workflows/ci.yml | 2 +- dic2owl/dic2owl/dic2owl.py | 138 ++++++++++++++++++++++++------------- 2 files changed, 91 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91d99a4..2ef258f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,4 +22,4 @@ jobs: pip install pre-commit - name: Run pre-commit - run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) \ No newline at end of file + run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index a7c4924..da0ca6e 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -9,7 +9,7 @@ from pathlib import Path # import textwrap -# import types +import types from typing import Union import urllib.request @@ -20,7 +20,7 @@ from emmo import World from emmo.ontology import Ontology - # import owlready2 + import owlready2 from owlready2 import locstr from CifFile import CifDic @@ -34,7 +34,7 @@ "http://www.w3.org/2000/01/rdf-schema#label", ] -"""Return the absolute, normalized path to the `ontology` directory in this repository""" +"""The absolute, normalized path to the `ontology` directory in this repository""" ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath("ontology") @@ -86,8 +86,6 @@ def generate(self) -> Ontology: The generated ontology. """ - self._add_dic_top() - for item in self.dic: if "_definition.scope" in item and "_definition.id" in item: self._add_category(item) @@ -95,11 +93,68 @@ def generate(self) -> Ontology: self._add_data_value(item) return self.onto - def _add_dic_top(self) -> None: - """Add the top class of the generated ontology.""" - pass + def _create_annotation(self, annotation_name): + """Create annotation with given name.""" + if annotation_name in self.onto: + return self.onto[annotation_name] + + if annotation_name == "DDL_DIC": + parent = owlready2.AnnotationProperty + elif annotation_name == "ATTRIBUTE": + parent_name = "DDL_DIC" + parent = self._create_annotation(parent_name) + elif "." in annotation_name: + parent_name = annotation_name.split(".")[0].lstrip("_").upper() + parent = self._create_annotation(parent_name) + elif "_" in annotation_name: + assert annotation_name.isupper() + parent_name = annotation_name.rsplit("_", 1)[0] + parent = self._create_annotation(parent_name) + else: + parent_name = "ATTRIBUTE" + parent = self._create_annotation(parent_name) + + # How to refer to annotation in ddl instead of creating one in + # onto? + with self.onto: + return types.new_class(annotation_name, (parent,)) + # return types.new_class(f'{self.ddl.base_iri}:{annotation_name}', + # (parent, )) + + def _add_annotations(self, cls, item) -> None: + """Add annotations for dic item `item` to generated on ontology + class `cls`. + + Parameters: + cls: Generated ontology class to wich the annotations should + be added. + item: Dic item with annotation info. + + """ + for annotation_name, value in item.items(): - def _add_category(self, item: dict) -> None: + # Add new annotation to generated ontology + if annotation_name not in self.onto: + self._create_annotation(annotation_name) + + # Assign annotation + annot = getattr(cls, annotation_name) + annot.append(en(value)) + + def _add_top(self, item) -> None: + """Add the top class of the generated ontology. + + Parameters: + item: Item to be added to the list of categories. + + """ + with self.onto: + top = types.new_class( + item["_dictionary.title"], (self.ddl.DictionaryDefinedItem,) + ) + self._add_annotations(top, item) + + def _add_category(self, item) -> None: """Add category. Parameters: @@ -110,34 +165,21 @@ def _add_category(self, item: dict) -> None: return self.categories.add(item) - print("*** category", item) - name = item["_definition.id"] - parent_name = item["_name.category_id"] - parent_item = self.dic[parent_name] - # if parent_item not in self.categories: - # self._add_category(parent_item) - # - # with self.onto: - # - # cat = types.new_class(name, (self.onto[parent_name], )) - - # name = item["_definition.id"] - # descr = item.get("_description.text") - # lname = "_" + name.lstrip("_").lower() - # with self.onto: - # if item.get("_definition.class"): - # loop = types.new_class(lname + "_LOOP", (self.top.LOOP,)) - # loop.prefLabel.append(en(loop.name.lstrip("_"))) - # packet = types.new_class(lname + "_PACKET", (self.top.PACKET,)) - # packet.prefLabel.append(en(packet.name.lstrip("_"))) - # cat = types.new_class(name, (self.top.CATEGORY,)) - # cat.prefLabel.append(en(cat.name.lstrip("_"))) - # if descr: - # cat.comment.append(en(textwrap.dedent(descr))) - # loop.is_a.append(self.top.hasSpatialDirectPart.some(packet)) - # loop.is_a.append(self.top.hasSpatialPart.only(cat)) - # else: - # print("** ignoring category:", name) + if "_definition.id" not in item: + self._add_top(item) + else: + name = item["_definition.id"] + parent_name = item["_name.category_id"] + + print(f"*** {name} -> {parent_name}") + + parent_item = self.dic[parent_name] + if parent_item not in self.categories: + self._add_category(parent_item) + + with self.onto: + cls = types.new_class(name, (self.onto[parent_name],)) + self._add_annotations(cls, item) def _add_data_value(self, item: dict) -> None: """Add data item. @@ -146,7 +188,7 @@ def _add_data_value(self, item: dict) -> None: item: Item to be added as a datum. """ - realname = item["_definition.id"] + # realname = item["_definition.id"] # name = realname.replace(".", "_") @@ -271,16 +313,16 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: gen = Generator(dicfile=dicfile, base_iri=base_iri) onto = gen.generate() - # # Annotate ontology - # onto.sync_attributes() - # onto.set_version(version="0.0.1") - # onto.metadata.abstract = ( - # "CIF core ontology generated from the CIF core definitions at " - # "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" - # ) - # - # if ttlfile is None: - # ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" + # # Annotate ontology + # onto.sync_attributes() + # onto.set_version(version="0.0.1") + # onto.metadata.abstract = ( + # "CIF core ontology generated from the CIF core definitions at " + # "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" + # ) + + # if ttlfile is None: + # ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" onto.save( ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()), From 1457b7344bb1a3a418f96af1b5adeeac33352f3e Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 19 Aug 2021 14:50:39 +0200 Subject: [PATCH 4/9] Fixed annotation from DDL Started on adding values. --- dic2owl/dic2owl/dic2owl.py | 71 ++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index da0ca6e..6edb5d3 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -50,6 +50,10 @@ def en(string: str) -> locstr: """ return locstr(string, lang="en") +class MissingAnnotationError(Exception): + """Raised when using a cif-dictionary annotation not defined in ddl + """ + class Generator: """Class for generating CIF ontology from a CIF dictionary. @@ -77,7 +81,7 @@ def __init__( self.onto = self.world.get_ontology(base_iri) self.onto.imported_ontologies.append(self.ddl) - self.categories = set() + self.items = set() def generate(self) -> Ontology: """Generate ontology for the CIF dictionary. @@ -93,34 +97,6 @@ def generate(self) -> Ontology: self._add_data_value(item) return self.onto - def _create_annotation(self, annotation_name): - """Create annotation with given name.""" - if annotation_name in self.onto: - return self.onto[annotation_name] - - if annotation_name == "DDL_DIC": - parent = owlready2.AnnotationProperty - elif annotation_name == "ATTRIBUTE": - parent_name = "DDL_DIC" - parent = self._create_annotation(parent_name) - elif "." in annotation_name: - parent_name = annotation_name.split(".")[0].lstrip("_").upper() - parent = self._create_annotation(parent_name) - elif "_" in annotation_name: - assert annotation_name.isupper() - parent_name = annotation_name.rsplit("_", 1)[0] - parent = self._create_annotation(parent_name) - else: - parent_name = "ATTRIBUTE" - parent = self._create_annotation(parent_name) - - # How to refer to annotation in ddl instead of creating one in - # onto? - with self.onto: - return types.new_class(annotation_name, (parent,)) - # return types.new_class(f'{self.ddl.base_iri}:{annotation_name}', - # (parent, )) - def _add_annotations(self, cls, item) -> None: """Add annotations for dic item `item` to generated on ontology class `cls`. @@ -133,13 +109,13 @@ class `cls`. """ for annotation_name, value in item.items(): - # Add new annotation to generated ontology - if annotation_name not in self.onto: - self._create_annotation(annotation_name) + # Add new annotation to generated ontology + if annotation_name not in self.ddl: + raise MissingAnnotationError(annotation_name) - # Assign annotation - annot = getattr(cls, annotation_name) - annot.append(en(value)) + # Assign annotation + annot = getattr(cls, annotation_name) + annot.append(en(value)) def _add_top(self, item) -> None: """Add the top class of the generated ontology. @@ -161,9 +137,9 @@ def _add_category(self, item) -> None: item: Item to be added to the list of categories. """ - if item in self.categories: + if item in self.items: return - self.categories.add(item) + self.items.add(item) if "_definition.id" not in item: self._add_top(item) @@ -174,7 +150,7 @@ def _add_category(self, item) -> None: print(f"*** {name} -> {parent_name}") parent_item = self.dic[parent_name] - if parent_item not in self.categories: + if parent_item not in self.items: self._add_category(parent_item) with self.onto: @@ -188,6 +164,25 @@ def _add_data_value(self, item: dict) -> None: item: Item to be added as a datum. """ + if item in self.items: + return + self.items.add(item) + + name = item["_definition.id"] + parents = [] + + + parent_name = item["_name.category_id"] + print(f"*** {name} -> {parent_name}") + parent = self.dic[parent_name] + if "_definition.scope" and "_definition.id" in parent: + self._add_category(parent) + else: + self._add_data_value(parent) + parents.append(self.onto[parent_name]) + with self.onto: + cls = types.new_class(name, parents) + # realname = item["_definition.id"] From 1ea157b68e44372da33e1aa4dd90bcb97e31616b Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Fri, 20 Aug 2021 11:48:57 +0200 Subject: [PATCH 5/9] Added data values Now the generation works - just two special cases left to handle + cleanup Also corrected some typos in cif-ddl.ttl. Added metadata to generated ontology. --- dic2owl/dic2owl/.gitignore | 2 + dic2owl/dic2owl/dic2owl.py | 271 ++++++++++++------------------ ontology/cif-ddl.ttl | 328 ++++++++++++++++++------------------- 3 files changed, 268 insertions(+), 333 deletions(-) create mode 100644 dic2owl/dic2owl/.gitignore diff --git a/dic2owl/dic2owl/.gitignore b/dic2owl/dic2owl/.gitignore new file mode 100644 index 0000000..e7871c4 --- /dev/null +++ b/dic2owl/dic2owl/.gitignore @@ -0,0 +1,2 @@ +cif_core.ttl +catalog-v001.xml diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index 6edb5d3..129a1c3 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -10,9 +10,11 @@ # import textwrap import types -from typing import Union +from typing import Union, Sequence import urllib.request +from CifFile import CifDic + # Remove the print statement concerning 'owlready2_optimized' # when importing owlready2 (which is imported also in emmo). with open(DEVNULL, "w") as handle: @@ -20,22 +22,20 @@ from emmo import World from emmo.ontology import Ontology - import owlready2 from owlready2 import locstr -from CifFile import CifDic - - -# Workaround for EMMO-Python -# Make sure that we can load cif-ddl.ttl which doesn't import SKOS -import emmo.ontology +# Workaround for flaw in EMMO-Python +# To be removed when EMMO-Python doesn't requires ontologies to import SKOS +import emmo.ontology # noqa: E402 emmo.ontology.DEFAULT_LABEL_ANNOTATIONS = [ "http://www.w3.org/2000/01/rdf-schema#label", ] -"""The absolute, normalized path to the `ontology` directory in this repository""" -ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath("ontology") +"""The absolute, normalized path to the `ontology` directory in this +repository""" +ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath( + "ontology") def en(string: str) -> locstr: @@ -50,6 +50,7 @@ def en(string: str) -> locstr: """ return locstr(string, lang="en") + class MissingAnnotationError(Exception): """Raised when using a cif-dictionary annotation not defined in ddl """ @@ -59,28 +60,38 @@ class Generator: """Class for generating CIF ontology from a CIF dictionary. Parameters: - dicfile (str): File name of CIF dictionary to generate an ontology for. - base_iri (str): Base IRI of the generated ontology. - + dicfile: File name of CIF dictionary to generate an ontology for. + base_iri: Base IRI of the generated ontology. + comments: Sequence of comments to add to the ontology itself. """ + # TODO: + # Should `comments` be replaced with a dict `annotations` for annotating + # the ontology itself? If so, we should import Dublin Core. def __init__( - self, - dicfile: str, - base_iri: str, + self, + dicfile: str, + base_iri: str, + comments: Sequence[str] = (), ) -> None: + self.dicfile = dicfile self.dic = CifDic(dicfile, do_dREL=False) + self.comments = comments - # Load cif-ddl ontology + # Create new ontology self.world = World() + self.onto = self.world.get_ontology(base_iri) + + # Load cif-ddl ontology and append it to imported ontologies cif_ddl = ONTOLOGY_DIR / "cif-ddl.ttl" self.ddl = self.world.get_ontology(str(cif_ddl)).load() self.ddl.sync_python_names() - - # Create new ontology - self.onto = self.world.get_ontology(base_iri) self.onto.imported_ontologies.append(self.ddl) + # Load Dublin core for metadata and append it to imported ontologies + #dcterms = self.world.get_ontology('http://purl.org/dc/terms/').load() + #self.onto.imported_ontologies.append(dcterms) + self.items = set() def generate(self) -> Ontology: @@ -91,31 +102,18 @@ def generate(self) -> Ontology: """ for item in self.dic: - if "_definition.scope" in item and "_definition.id" in item: - self._add_category(item) - else: - self._add_data_value(item) - return self.onto - - def _add_annotations(self, cls, item) -> None: - """Add annotations for dic item `item` to generated on ontology - class `cls`. - - Parameters: - cls: Generated ontology class to wich the annotations should - be added. - item: Dic item with annotation info. + self._add_item(item) - """ - for annotation_name, value in item.items(): - - # Add new annotation to generated ontology - if annotation_name not in self.ddl: - raise MissingAnnotationError(annotation_name) + self._add_metadata() + self.onto.sync_attributes() + return self.onto - # Assign annotation - annot = getattr(cls, annotation_name) - annot.append(en(value)) + def _add_item(self, item) -> None: + """Add dic block `item` to the generated ontology.""" + if "_definition.scope" in item and "_definition.id" in item: + self._add_category(item) + else: + self._add_data_value(item) def _add_top(self, item) -> None: """Add the top class of the generated ontology. @@ -126,7 +124,7 @@ def _add_top(self, item) -> None: """ with self.onto: top = types.new_class( - item["_dictionary.title"], (self.ddl.DictionaryDefinedItem,) + item["_dictionary.title"], (self.ddl.DictionaryDefinedItem, ) ) self._add_annotations(top, item) @@ -146,9 +144,6 @@ def _add_category(self, item) -> None: else: name = item["_definition.id"] parent_name = item["_name.category_id"] - - print(f"*** {name} -> {parent_name}") - parent_item = self.dic[parent_name] if parent_item not in self.items: self._add_category(parent_item) @@ -169,129 +164,81 @@ def _add_data_value(self, item: dict) -> None: self.items.add(item) name = item["_definition.id"] + parents = [] - - - parent_name = item["_name.category_id"] - print(f"*** {name} -> {parent_name}") - parent = self.dic[parent_name] - if "_definition.scope" and "_definition.id" in parent: - self._add_category(parent) - else: - self._add_data_value(parent) + parent_name1 = item["_name.category_id"] + parent = self.dic[parent_name1] + parent_name = parent['_definition.id'] + self._add_item(parent) parents.append(self.onto[parent_name]) + + for ddl_name, value in item.items(): + if ddl_name.startswith('_type.'): + if ddl_name == '_type.dimension': + # TODO - fix special case + pass + elif value == 'Implied': + # TODO - fix special case + pass + else: + parents.append(self.ddl[value]) + with self.onto: - cls = types.new_class(name, parents) - - # realname = item["_definition.id"] - - -# name = realname.replace(".", "_") -# descr = item.get("_description.text") -# units = item.get("_units.code") -# aliases = item.get("_alias.definition_id") -# examples = item.get("_description_example.detail", []) -# examples.extend(item.get("_description_example.case", [])) -# dimension = item.get("_type.dimension") -# -# container_name = item.get("_type.container", "Single") -# datatype_name = item.get("_type.contents", "Text") -# category_name = item["_name.category_id"].upper() -# packet_name = "_%s_PACKET" % item["_name.category_id"] -# -# container = self.onto[container_name] -# datatype = self.onto[datatype_name] -# category = self.onto[category_name] -# -# with self.onto: -# -# if container_name == "Single": -# e = types.new_class(name, (datatype,)) -# elif container_name in ("Matrix", "Array"): -# dims = dimension.strip("[]") -# if dims: -# subarr = self.subarray(dims.split(","), datatype, container_name) -# e = types.new_class(name, (subarr,)) -# else: -# e = types.new_class(name, (datatype,)) -# else: -# e = types.new_class(name, (container,)) -# if container_name == "List": -# e.is_a.append(self.top.hasSpatialDirectPart.some(datatype)) -# else: -# e.is_a.append(self.top.hasSpatialPart.some(datatype)) -# -# if category.disjoint_unions: -# category.disjoint_unions[0].append(e) -# else: -# category.disjoint_unions.append([e]) -# e.prefLabel.append(en(realname.lstrip("_"))) -# if name != realname: -# e.altLabel.append(en(name.lstrip("_"))) -# -# # Hmm, _name is already used internally by owlready2.Ontology -# # so `e._name.append(name)` won't work. -# # We have to add the tripple the hard way... -# o, d = owlready2.to_literal(realname) # not localised -# self.onto._set_data_triple_spod( -# s=e.storid, p=self.onto.world._props["_name"].storid, o=o, d=d -# ) -# -# if aliases: -# e.altLabel.extend(en(a) for a in aliases) -# if descr: -# e.comment.append(en(textwrap.dedent(descr))) -# if examples: -# e.example.extend(en(textwrap.dedent(ex)) for ex in examples) -# if units: -# e._unit.append(units) # not localised -# if dimension: -# e._dimension.append(dimension) # not localised -# if datatype: -# e._datatype.append(datatype) # not localised -# if packet_name in self.onto: -# packet = self.onto[packet_name] -# packet.is_a.append(self.top.hasSpatialDirectPart.max(1, e)) -# else: -# print("** no packet:", realname) - -# def subarray(self, dimensions, datatype, container_name): -# """Returns a reference to an array or matrix corresponding to: -# - dimensions: list of dimension values -# - typename: type of elements -# - container_name: "Array" or "Matrix" -# If it does not already exists, the subarray is created. All -# its spatial direct parts are also generated recursively. -# """ -# if not dimensions or not dimensions[0]: -# return datatype -# name = "Shape" + "x".join(dimensions) + datatype.name + container_name -# if name not in self.onto: -# e = types.new_class(name, (self.onto[container_name],)) -# d = int(dimensions.pop(0)) -# e.is_a.append( -# self.top.hasSpatialDirectPart.exactly( -# d, self.subarray(dimensions, datatype, container_name) -# ) -# ) -# return self.onto[name] + cls = types.new_class(name, tuple(parents)) + + self._add_annotations(cls, item) + + def _add_annotations(self, cls, item) -> None: + """Add annotations for dic item `item` to generated on ontology + class `cls`. + + Parameters: + cls: Generated ontology class to wich the annotations should + be added. + item: Dic item with annotation info. + + """ + for annotation_name, value in item.items(): + + # Add new annotation to generated ontology + if annotation_name not in self.ddl: + raise MissingAnnotationError(annotation_name) + + # Assign annotation + annot = getattr(cls, annotation_name) + annot.append(en(value)) + + def _add_metadata(self): + """Adds metadata to the generated ontology.""" + # TODO: + # Is there a way to extract metadata from the dic object like + # _dictionary_audit.version? + #onto.set_version(version="XXX") + + for comment in self.comments: + self.onto.metadata.comment.append(comment) + self.onto.metadata.comment.append( + f'Generated with dic2owl from {self.dicfile}') def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: """Main function for ontology generation. Parameters: - dicfile: Absolute or relative path to the `.dic`-file to be converted to an ontology. + dicfile: Absolute or relative path to the `.dic`-file to be converted + to an ontology. This can be either a local path or a URL path. - ttlfile: Absolute or relative path to the Turtle (`.ttl`) file to be created from the - `dicfile`. The Turtle file contains the generated ontology in OWL. This **must** be a - local path. + ttlfile: Absolute or relative path to the Turtle (`.ttl`) file to + be created from the `dicfile`. + The Turtle file contains the generated ontology in OWL. + This **must** be a local path. !!! important The file will be overwritten if it already exists. Returns: - The setup ontology generator class. This is mainly returned for debugging reasons. + The setup ontology generator class. This is mainly returned for + debugging reasons. """ base_iri = "http://emmo.info/CIF-ontology/ontology/cif_core#" @@ -307,18 +254,6 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: gen = Generator(dicfile=dicfile, base_iri=base_iri) onto = gen.generate() - - # # Annotate ontology - # onto.sync_attributes() - # onto.set_version(version="0.0.1") - # onto.metadata.abstract = ( - # "CIF core ontology generated from the CIF core definitions at " - # "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" - # ) - - # if ttlfile is None: - # ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" - onto.save( ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()), overwrite=True, @@ -335,5 +270,3 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: dic = self.dic ddl = self.ddl onto = self.onto - # sid = cd["space_group_symop.id"] - # s = cd["SPACE_GROUP_SYMOP"] diff --git a/ontology/cif-ddl.ttl b/ontology/cif-ddl.ttl index 88a64d7..245f528 100644 --- a/ontology/cif-ddl.ttl +++ b/ontology/cif-ddl.ttl @@ -7,15 +7,15 @@ a owl:Ontology ; rdfs:comment "Avoid the Block to Loop to Packet to Value parthood by simply declaring a Loop as a singe list of Values (one row)." , "Drop Source and Purpose classes, since they are suggested and not mandatory." . -# -# +# +# # ################################################################# # # # # Annotation properties # # # ################################################################# -# -# +# +# # http://emmo.info/emmo/cif-ddl#ALIAS :ALIAS a owl:AnnotationProperty ; @@ -31,7 +31,7 @@ _:genid1 :_category_key.name "_alias.definition_id" . :ALIAS rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#ATTRIBUTE :ATTRIBUTE a owl:AnnotationProperty ; @@ -43,19 +43,19 @@ _:genid1 :_category_key.name "_alias.definition_id" . :_name.category_id "DDL_DIC" ; :_name.object_id "ATTRIBUTES" ; rdfs:subPropertyOf :DDL_DIC . -# +# # http://emmo.info/emmo/cif-ddl#CATEGORY :CATEGORY a owl:AnnotationProperty ; :_definition.scope "Set" ; rdfs:comment "not defined in ddl.dic" ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#CATEGORY_KEY :CATEGORY_KEY a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#DDL_DIC :DDL_DIC a owl:AnnotationProperty ; @@ -67,77 +67,77 @@ _:genid1 :_category_key.name "_alias.definition_id" . :_dictionary.title "DDL_DIC" ; :_dictionary.uri "https://raw.githubusercontent.com/COMCIFS/cif_core/master/ddl.dic" ; :_dictionary.version "4.0.1" . -# +# # http://emmo.info/emmo/cif-ddl#DEFINITION :DEFINITION a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#DEFINITION_REPLACED :DEFINITION_REPLACED a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION . -# +# # http://emmo.info/emmo/cif-ddl#DESCRIPTION :DESCRIPTION a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#DESCRIPTION_EXAMPLE :DESCRIPTION_EXAMPLE a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION . -# +# # http://emmo.info/emmo/cif-ddl#DICTIONARY :DICTIONARY a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#DICTIONARY_AUDIT :DICTIONARY_AUDIT a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#DICTIONARY_VALID :DICTIONARY_VALID a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#ENUMERATION :ENUMERATION a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#ENUMERATION_DEFAULT :ENUMERATION_DEFAULT a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#ENUMERATION_SET :ENUMERATION_SET a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#IMPORT :IMPORT a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#IMPORT_DETAILS :IMPORT_DETAILS a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT . -# +# # http://emmo.info/emmo/cif-ddl#METHOD :METHOD a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#NAME :NAME a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#TYPE :TYPE a owl:AnnotationProperty ; @@ -149,12 +149,12 @@ _:genid1 :_category_key.name "_alias.definition_id" . :_name.category_id "ATTRIBUTES" ; :_name.object_id "TYPE" ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#UNITS :UNITS a owl:AnnotationProperty ; rdfs:subPropertyOf :ATTRIBUTE . -# +# # http://emmo.info/emmo/cif-ddl#_alias.definition_id :_alias.definition_id a owl:AnnotationProperty ; @@ -166,280 +166,280 @@ _:genid1 :_category_key.name "_alias.definition_id" . :_name.object_id "definition_id" ; :_type.contents "Tag" ; :_type.source "Assigned" ; - :_type:container "Single" ; - :_type:purpose "Encode" ; + :_type.container "Single" ; + :_type.purpose "Encode" ; rdfs:subPropertyOf :ALIAS . -# +# # http://emmo.info/emmo/cif-ddl#_alias.deprecation_date :_alias.deprecation_date a owl:AnnotationProperty ; rdfs:subPropertyOf :ALIAS . -# +# # http://emmo.info/emmo/cif-ddl#_alias.dictionary_uri :_alias.dictionary_uri a owl:AnnotationProperty ; rdfs:subPropertyOf :ALIAS . -# +# # http://emmo.info/emmo/cif-ddl#_category.key_id :_category.key_id a owl:AnnotationProperty ; :_name.category_id "category" ; rdfs:comment "not defined in ddl.dic" ; rdfs:subPropertyOf :CATEGORY . -# +# # http://emmo.info/emmo/cif-ddl#_category_key.name :_category_key.name a owl:AnnotationProperty ; rdfs:subPropertyOf :CATEGORY_KEY . -# +# # http://emmo.info/emmo/cif-ddl#_definition.class :_definition.class a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION ; rdfs:range xsd:string . -# +# # http://emmo.info/emmo/cif-ddl#_definition.id :_definition.id a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION ; rdfs:range xsd:string . -# +# # http://emmo.info/emmo/cif-ddl#_definition.scope :_definition.scope a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION . -# +# # http://emmo.info/emmo/cif-ddl#_definition.update :_definition.update a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION . -# +# # http://emmo.info/emmo/cif-ddl#_definition_replaced.by :_definition_replaced.by a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION_REPLACED . -# +# # http://emmo.info/emmo/cif-ddl#_definition_replaced.id :_definition_replaced.id a owl:AnnotationProperty ; rdfs:subPropertyOf :DEFINITION_REPLACED . -# +# # http://emmo.info/emmo/cif-ddl#_description.common :_description.common a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION . -# +# # http://emmo.info/emmo/cif-ddl#_description.key_words :_description.key_words a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION . -# +# # http://emmo.info/emmo/cif-ddl#_description.text :_description.text a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION . -# +# # http://emmo.info/emmo/cif-ddl#_description_example.case :_description_example.case a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION_EXAMPLE . -# +# # http://emmo.info/emmo/cif-ddl#_description_example.detail :_description_example.detail a owl:AnnotationProperty ; rdfs:subPropertyOf :DESCRIPTION_EXAMPLE . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.class :_dictionary.class a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.date :_dictionary.date a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.ddl_conformance :_dictionary.ddl_conformance a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.formalism :_dictionary.formalism a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.namespace :_dictionary.namespace a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.title :_dictionary.title a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.uri :_dictionary.uri a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY ; rdfs:range xsd:anyURI . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary.version :_dictionary.version a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_audit.date :_dictionary_audit.date a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_AUDIT . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_audit.revision :_dictionary_audit.revision a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_AUDIT . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_audit.version :_dictionary_audit.version a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_AUDIT . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_valid.application :_dictionary_valid.application a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_VALID . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_valid.attributes :_dictionary_valid.attributes a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_VALID . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_valid.option :_dictionary_valid.option a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_VALID . -# +# # http://emmo.info/emmo/cif-ddl#_dictionary_valid.scope :_dictionary_valid.scope a owl:AnnotationProperty ; rdfs:subPropertyOf :DICTIONARY_VALID . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration.def_index_id :_enumeration.def_index_id a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration.default :_enumeration.default a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration.mandatory :_enumeration.mandatory a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration.range :_enumeration.range a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration_default.index :_enumeration_default.index a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION_DEFAULT . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration_default.value :_enumeration_default.value a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION_DEFAULT . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration_set.detail :_enumeration_set.detail a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION_SET . -# +# # http://emmo.info/emmo/cif-ddl#_enumeration_set.state :_enumeration_set.state a owl:AnnotationProperty ; rdfs:subPropertyOf :ENUMERATION_SET . -# +# # http://emmo.info/emmo/cif-ddl#_import.get :_import.get a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.file_id :_import_details.file_id a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.file_version :_import_details.file_version a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.frame_id :_import_details.frame_id a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.if_dupl :_import_details.if_dupl a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.if_miss :_import_details.if_miss a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.mode :_import_details.mode a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.order :_import_details.order a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.single :_import_details.single a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_import_details.single_index :_import_details.single_index a owl:AnnotationProperty ; rdfs:subPropertyOf :IMPORT_DETAILS . -# +# # http://emmo.info/emmo/cif-ddl#_method.expression :_method.expression a owl:AnnotationProperty ; rdfs:subPropertyOf :METHOD . -# +# # http://emmo.info/emmo/cif-ddl#_method.purpose :_method.purpose a owl:AnnotationProperty ; rdfs:subPropertyOf :METHOD . -# +# # http://emmo.info/emmo/cif-ddl#_name.category_id :_name.category_id a owl:AnnotationProperty ; rdfs:subPropertyOf :NAME . -# +# # http://emmo.info/emmo/cif-ddl#_name.linked_item_id :_name.linked_item_id a owl:AnnotationProperty ; rdfs:subPropertyOf :NAME . -# +# # http://emmo.info/emmo/cif-ddl#_name.object_id :_name.object_id a owl:AnnotationProperty ; rdfs:subPropertyOf :NAME . -# +# # http://emmo.info/emmo/cif-ddl#_type.contents :_type.contents a owl:AnnotationProperty ; @@ -470,125 +470,125 @@ Note that descriptions of text syntax are relevant only to those formats that en _:genid2 :_enumeration_set.detail "case-sensitive sequence of CIF2 characters" ; :_enumeration_set.state "Text" . -:_type.contents :_type:container "Single" ; - :_type:purpose "State" ; +:_type.contents :_type.container "Single" ; + :_type.purpose "State" ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_type.contents_referenced_id :_type.contents_referenced_id a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_type.dimension :_type.dimension a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_type.indeces :_type.indeces a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_type.indices_referenced_id :_type.indices_referenced_id a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_type.source :_type.source a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# +# # http://emmo.info/emmo/cif-ddl#_units.code :_units.code a owl:AnnotationProperty ; rdfs:subPropertyOf :UNITS . -# +# # http://emmo.info/emmo/cif-ddl#loop_ :loop_ a owl:AnnotationProperty . -# -# http://emmo.info/emmo/cif-ddl#_type:container +# +# http://emmo.info/emmo/cif-ddl#_type.container -:_type:container a owl:AnnotationProperty ; +:_type.container a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# -# http://emmo.info/emmo/cif-ddl#_type:purpose +# +# http://emmo.info/emmo/cif-ddl#_type.purpose -:_type:purpose a owl:AnnotationProperty ; +:_type.purpose a owl:AnnotationProperty ; rdfs:subPropertyOf :TYPE . -# -# -# +# +# +# # ################################################################# # # # # Object Properties # # # ################################################################# -# -# +# +# # http://emmo.info/emmo/cif-ddl#hasCIFDirectPart :hasCIFDirectPart a owl:ObjectProperty ; rdfs:subPropertyOf :hasDirectPart . -# +# # http://emmo.info/emmo/cif-ddl#hasDirectPart :hasDirectPart a owl:ObjectProperty ; rdfs:subPropertyOf :hasProperPart ; a owl:InverseFunctionalProperty , owl:AsymmetricProperty , owl:IrreflexiveProperty . -# +# # http://emmo.info/emmo/cif-ddl#hasPart :hasPart a owl:ObjectProperty ; rdfs:subPropertyOf owl:topObjectProperty ; a owl:TransitiveProperty , owl:ReflexiveProperty . -# +# # http://emmo.info/emmo/cif-ddl#hasProperPart :hasProperPart a owl:ObjectProperty ; rdfs:subPropertyOf :hasPart ; a owl:TransitiveProperty . -# -# -# +# +# +# # ################################################################# # # # # Data properties # # # ################################################################# -# -# +# +# # http://emmo.info/emmo/cif-ddl#hasUniqueValue :hasUniqueValue a owl:DatatypeProperty ; rdfs:subPropertyOf owl:topDataProperty ; a owl:FunctionalProperty . -# -# -# +# +# +# # ################################################################# # # # # Classes # # # ################################################################# -# -# +# +# # http://emmo.info/emmo/cif-ddl#Array :Array a owl:Class ; rdfs:comment "Ordered set of values of the same type. Operations across arrays are equivalent to operations across elements of the Array." . -# +# # http://emmo.info/emmo/cif-ddl#Assigned :Assigned a owl:Class ; rdfs:comment "A value (numerical or otherwise) assigned as part of the data collection, analysis or modelling required for a specific domain instance. These assignments often represent a decision made that determines the course of the experiment (and therefore may be deemed PRIMITIVE) or a particular choice in the way the data was analysed (and therefore may be considered NOT PRIMITIVE)." . -# +# # http://emmo.info/emmo/cif-ddl#ByReference :ByReference a owl:Class ; rdfs:comment "The contents have the same form as those of the attribute referenced by _type.contents_referenced_id." . -# +# # http://emmo.info/emmo/cif-ddl#Code :Code a owl:Class ; @@ -599,7 +599,7 @@ _:genid3 a owl:Restriction ; owl:someValuesFrom xsd:string . :Code rdfs:comment "Case-insensitive sequence of CIF2 characters containing no ASCII whitespace." . -# +# # http://emmo.info/emmo/cif-ddl#Complex :Complex a owl:Class ; @@ -610,12 +610,12 @@ _:genid4 a owl:Restriction ; owl:someValuesFrom xsd:string . :Complex rdfs:comment "A complex number" . -# +# # http://emmo.info/emmo/cif-ddl#Composite :Composite a owl:Class ; rdfs:comment "Used to type items with value strings composed of separate parts. These will usually need to be separated and parsed for complete interpretation and application." . -# +# # http://emmo.info/emmo/cif-ddl#Container :Container a owl:Class ; @@ -640,7 +640,7 @@ _:genid6 a rdf:List ; _:genid5 a rdf:List ; rdf:first :Table ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Contents :Contents a owl:Class ; @@ -709,7 +709,7 @@ _:genid11 a rdf:List ; _:genid10 a rdf:List ; rdf:first :Version ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Data :Data a owl:Class ; @@ -732,7 +732,7 @@ Data appear either as key/value pairs, or within loops.""" , """data-block = dat data-heading = data-token, container-code ; data-token = ( 'D' | 'd' ), ( 'A' | 'a' ), ( 'T' | 't' ), ( 'A' | 'a' ), '_'; data = ( data-name, wspace-data-value ) | data-loop ;""" . -# +# # http://emmo.info/emmo/cif-ddl#DataBlock :DataBlock a owl:Class ; @@ -769,7 +769,7 @@ _:genid34 a owl:Restriction ; :DataBlock rdfs:comment "A datablock consists of a data heading followed by zero or more data items and save frames." , """data-block = data-heading, { block-content } ; data-heading = data-token, container-code ; data-token = ( 'D' | 'd' ), ( 'A' | 'a' ), ( 'T' | 't' ), ( 'A' | 'a' ), '_';""" . -# +# # http://emmo.info/emmo/cif-ddl#DataBlockName :DataBlockName a owl:Class ; @@ -780,7 +780,7 @@ _:genid35 a owl:Restriction ; owl:allValuesFrom owl:Nothing . :DataBlockName rdfs:comment "container-code = non-blank-char, { non-blank-char } ;" . -# +# # http://emmo.info/emmo/cif-ddl#Date :Date a owl:Class ; @@ -791,7 +791,7 @@ _:genid36 a owl:Restriction ; owl:someValuesFrom xsd:dateTime . :Date rdfs:comment "ISO standard date format --
. Use DateTime for all new dictionaries" . -# +# # http://emmo.info/emmo/cif-ddl#DateTime :DateTime a owl:Class ; @@ -802,21 +802,21 @@ _:genid37 a owl:Restriction ; owl:someValuesFrom xsd:string . :DateTime rdfs:comment "A timestamp. Text formats must use date-time or full-date productions of RFC 3339 ABNF" . -# +# # http://emmo.info/emmo/cif-ddl#Derived :Derived a owl:Class ; rdfs:comment "A quantity derived from other data items within the domain instance. This item is NOT PRIMITIVE." . -# +# # http://emmo.info/emmo/cif-ddl#Describe :Describe a owl:Class ; rdfs:comment "Used to type items with values that are descriptive text intended for human interpretation." . -# +# # http://emmo.info/emmo/cif-ddl#DictionaryDefinedItem :DictionaryDefinedItem a owl:Class . -# +# # http://emmo.info/emmo/cif-ddl#Dimension :Dimension a owl:Class ; @@ -827,12 +827,12 @@ _:genid38 a owl:Restriction ; owl:someValuesFrom xsd:string . :Dimension rdfs:comment "Size of an Array/Matrix/List expressed as a text string. The text string itself consists of zero or more non-negative integers separated by commas placed within bounding square brackets. Empty square brackets represent a list of unknown size" . -# +# # http://emmo.info/emmo/cif-ddl#Encode :Encode a owl:Class ; rdfs:comment "Used to type items with values that are text or codes that are formatted to be machine parsable." . -# +# # http://emmo.info/emmo/cif-ddl#File :File a owl:Class ; @@ -847,7 +847,7 @@ _:genid39 a owl:Restriction ; _:genid40 a owl:Restriction ; owl:onProperty :hasCIFDirectPart ; owl:allValuesFrom :DataBlock . -# +# # http://emmo.info/emmo/cif-ddl#Imag :Imag a owl:Class ; @@ -858,7 +858,7 @@ _:genid41 a owl:Restriction ; owl:someValuesFrom owl:real . :Imag rdfs:comment "Floating-point imaginary number" . -# +# # http://emmo.info/emmo/cif-ddl#Indices :Indices a owl:Class ; @@ -894,7 +894,7 @@ _:genid44 a rdf:List ; _:genid43 a rdf:List ; rdf:first :Version ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Integer :Integer a owl:Class ; @@ -905,27 +905,27 @@ _:genid50 a owl:Restriction ; owl:someValuesFrom xsd:integer . :Integer rdfs:comment "Positive or negative integer number" . -# +# # http://emmo.info/emmo/cif-ddl#Internal :Internal a owl:Class ; rdfs:comment "Used to type items that serve only internal purposes of the dictionary in which they appear. The particular purpose served is not defined by this state." . -# +# # http://emmo.info/emmo/cif-ddl#Key :Key a owl:Class ; rdfs:comment "Used to type an item with a value that is unique within the looped list of these items, and does not contain encoded information." . -# +# # http://emmo.info/emmo/cif-ddl#Link :Link a owl:Class ; rdfs:comment "Used to type an item that acts as a foreign key between two categories. The definition of the item must additionally contain the attribute \"_name.linked_item_id\" specifying the data name of the item with unique values in the linked category. The values of the defined item are drawn from the set of values in the referenced item. Cross referencing items from the same category is allowed." . -# +# # http://emmo.info/emmo/cif-ddl#List :List a owl:Class ; rdfs:comment "Ordered set of values. Elements need not be of same contents type." . -# +# # http://emmo.info/emmo/cif-ddl#Loop :Loop a owl:Class ; @@ -942,12 +942,12 @@ _:genid52 a owl:Restriction ; owl:allValuesFrom :Packet . :Loop rdfs:comment "A data loop consists of a loop header (the case-insensitive word \"loop_\" followed by a sequence of datanames) and then a sequence of one or more whitespace-separated values. Though it cannot be expressed in EBNF, CIF requires that a loop whose header contains N data names must contain an integral multiple of N data values." , "data-loop = loop-token, wspace, data-name, { wspace, data-name }, wspace-data-value, { wspace-data-value } ;" . -# +# # http://emmo.info/emmo/cif-ddl#Matrix :Matrix a owl:Class ; rdfs:comment "Ordered set of numerical values for a tensor. Tensor operations such as dot and cross products, are valid cross matrix objects. A matrix with a single dimension is interpreted as a row or column vector as required." . -# +# # http://emmo.info/emmo/cif-ddl#Measurand :Measurand a owl:Class ; @@ -956,7 +956,7 @@ _:genid52 a owl:Restriction ; or 2) as a separate, explicit value for the associated SU item. These alternatives are semantically equivalent.""" . -# +# # http://emmo.info/emmo/cif-ddl#Name :Name a owl:Class ; @@ -967,12 +967,12 @@ _:genid53 a owl:Restriction ; owl:allValuesFrom xsd:string . :Name rdfs:comment "Case-insensitive sequence of ASCII alpha-numeric characters or underscore" . -# +# # http://emmo.info/emmo/cif-ddl#Number :Number a owl:Class ; rdfs:comment "Used to type items that are numerical and exact (i.e. no standard uncertainty value)." . -# +# # http://emmo.info/emmo/cif-ddl#Packet :Packet a owl:Class ; @@ -987,7 +987,7 @@ _:genid54 a owl:Restriction ; _:genid55 a owl:Restriction ; owl:onProperty :hasCIFDirectPart ; owl:allValuesFrom :Value . -# +# # http://emmo.info/emmo/cif-ddl#Purpose :Purpose a owl:Class ; @@ -1032,7 +1032,7 @@ _:genid57 a rdf:List ; _:genid56 a rdf:List ; rdf:first :State ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Range :Range a owl:Class ; @@ -1043,7 +1043,7 @@ _:genid66 a owl:Restriction ; owl:someValuesFrom xsd:string . :Range rdfs:comment "Inclusive range of numerical values min:max" . -# +# # http://emmo.info/emmo/cif-ddl#Real :Real a owl:Class ; @@ -1054,27 +1054,27 @@ _:genid67 a owl:Restriction ; owl:someValuesFrom owl:real . :Real rdfs:comment "Floating-point real number" . -# +# # http://emmo.info/emmo/cif-ddl#Recorded :Recorded a owl:Class ; rdfs:comment "A value (numerical or otherwise) recorded by observation or measurement during the experimental collection of data. This item is PRIMITIVE." . -# +# # http://emmo.info/emmo/cif-ddl#Related :Related a owl:Class ; rdfs:comment "A value or tag used in the construction of looped lists of data. Typically identifying an item whose unique value is the reference key for a loop category and/or an item which has values in common with those of another loop category and is considered a Link between these lists." . -# +# # http://emmo.info/emmo/cif-ddl#SU :SU a owl:Class ; rdfs:comment "Used to type an item with a numerical value that is the standard uncertainty of another dataname. The definition of an SU item must include the attribute \"_name.linked_item_id\" which explicitly identifies the associated measurand item. SU values must be non-negative." . -# +# # http://emmo.info/emmo/cif-ddl#Single :Single a owl:Class ; rdfs:comment "Single value" . -# +# # http://emmo.info/emmo/cif-ddl#Source :Source a owl:Class ; @@ -1095,12 +1095,12 @@ _:genid69 a rdf:List ; _:genid68 a rdf:List ; rdf:first :Related ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#State :State a owl:Class ; rdfs:comment "Used to type items with values that are restricted to codes present in their \"enumeration_set.state\" lists." . -# +# # http://emmo.info/emmo/cif-ddl#Structure :Structure a owl:Class ; @@ -1129,7 +1129,7 @@ _:genid73 a rdf:List ; _:genid72 a rdf:List ; rdf:first :Value ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Symop :Symop a owl:Class ; @@ -1140,12 +1140,12 @@ _:genid78 a owl:Restriction ; owl:someValuesFrom xsd:string . :Symop rdfs:comment "A string composed of an integer optionally followed by an underscore or space and three or more digits" . -# +# # http://emmo.info/emmo/cif-ddl#Table :Table a owl:Class ; rdfs:comment "An unordered set of id:value elements" . -# +# # http://emmo.info/emmo/cif-ddl#Tag :Tag a owl:Class ; @@ -1156,7 +1156,7 @@ _:genid79 a owl:Restriction ; owl:someValuesFrom xsd:string . :Tag rdfs:comment "Case-insensitive CIF2 character sequence with leading underscore and no ASCII whitespace" . -# +# # http://emmo.info/emmo/cif-ddl#Text :Text a owl:Class ; @@ -1167,7 +1167,7 @@ _:genid80 a owl:Restriction ; owl:someValuesFrom xsd:string . :Text rdfs:comment "Case-sensitive sequence of CIF2 characters" . -# +# # http://emmo.info/emmo/cif-ddl#Type :Type a owl:Class ; @@ -1191,7 +1191,7 @@ _:genid83 a rdf:List ; _:genid82 a rdf:List ; rdf:first :Source ; rdf:rest rdf:nil . -# +# # http://emmo.info/emmo/cif-ddl#Uri :Uri a owl:Class ; @@ -1202,7 +1202,7 @@ _:genid86 a owl:Restriction ; owl:someValuesFrom xsd:anyURI . :Uri rdfs:comment "Uniform Resource Identifier reference as defined in RFC 3986 Section 4.1" . -# +# # http://emmo.info/emmo/cif-ddl#Value :Value a owl:Class ; @@ -1225,7 +1225,7 @@ _:genid88 a rdf:List ; _:genid87 a owl:Class . :Value rdfs:comment "A dataname begins with an underscore character, and contains one or more additional, non-blank characters." , "Data from Instance dictionaries." , "data-name = '_' , non-blank-char, { non-blank-char } ;" , "data-name is the class name, and the data is attached to it" . -# +# # http://emmo.info/emmo/cif-ddl#Version :Version a owl:Class ; @@ -1236,7 +1236,7 @@ _:genid91 a owl:Restriction ; owl:someValuesFrom xsd:string . :Version rdfs:comment "Version digit string of the form .." . -# +# _:genid92 rdfs:comment :_category_key.name . # Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi From e5b1f00984291670f5d536a702a444ced46f9b88 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Sat, 21 Aug 2021 12:05:50 +0200 Subject: [PATCH 6/9] Style and linting - Run pre-commit. - Add some typing. - Make bandit check skip `urlretrieve` line, since `file://` will never be used as input. - Satisfy pylint + mypy. - Add pylint configuration in setup.cfg. - Add mypy cache folder to .gitignore. - Ensure `safety` checks the installed dependencies. - Exchange `flake8` with `pylint` in pre-commit - updating files accordingly. - Use `pyproject.toml` instead of `setup.cfg`. - Set line-length to 79 (80) in `black` (`pylint`) tools. Remove old ontology generation file. Update requirements to be more lenient. Minimize CI runs: Only run `dic2owl` CI if a file change under `dic2owl/` and only run the CI for `push`. Update authors. Mention CLI in doc-string for setup.py. Remove `__main__` section in dic2owl.py. --- .github/static/get_dic2owl_deps.py | 53 +++ .github/workflows/ci.yml | 2 +- .github/workflows/dic2owl_ci.yml | 11 +- .gitignore | 2 + .pre-commit-config.yaml | 18 +- dic2owl/dic2owl/__init__.py | 20 +- dic2owl/dic2owl/cli.py | 30 +- dic2owl/dic2owl/dic2owl.py | 75 ++-- dic2owl/dic2owl/generate_cif.py | 239 ----------- dic2owl/pyproject.toml | 651 +++++++++++++++++++++++++++++ dic2owl/requirements.txt | 4 +- dic2owl/requirements_dev.txt | 6 +- dic2owl/setup.py | 21 +- 13 files changed, 820 insertions(+), 312 deletions(-) create mode 100644 .github/static/get_dic2owl_deps.py delete mode 100644 dic2owl/dic2owl/generate_cif.py create mode 100644 dic2owl/pyproject.toml diff --git a/.github/static/get_dic2owl_deps.py b/.github/static/get_dic2owl_deps.py new file mode 100644 index 0000000..f97d707 --- /dev/null +++ b/.github/static/get_dic2owl_deps.py @@ -0,0 +1,53 @@ +""" +# Retrieve dependencies + +Retrieve dependencies from a `requirements.txt`-style file. +""" +import argparse +from pathlib import Path +import re +from typing import Set + + +def main(argv_input: list = None) -> Set[str]: + """Retrieve dependencies""" + parser = argparse.ArgumentParser( + description=main.__doc__, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser.add_argument( + "requirements_files", + metavar="FILE", + type=Path, + nargs="+", + help="The path(s) to one or several requirements.txt-style file(s).", + ) + args = parser.parse_args(argv_input) + + requirements_regex = re.compile( + r"^(?P[A-Za-z0-9_-]+)(~=|>=|==).*\n$" + ) + dependencies = set() + for file in args.requirements_files: + if not file.exists(): + raise FileNotFoundError(f"Could not find {file} !") + with open(file.resolve(), "r") as handle: + for line in handle.readlines(): + match = requirements_regex.fullmatch(line) + if match is None: + raise ValueError( + ( + "Couldn't determine package name from line:\n\n " + f"{line}" + ) + ) + dependencies.add(match.group("name")) + return dependencies + + +if __name__ == "__main__": + from sys import argv + + parsed_dependencies = main(argv[1:]) + grep_extended_regex = f"({'|'.join(parsed_dependencies)})" + print(grep_extended_regex) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ef258f..c344077 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [push, pull_request] +on: [push] jobs: diff --git a/.github/workflows/dic2owl_ci.yml b/.github/workflows/dic2owl_ci.yml index 1be8fde..33b108a 100644 --- a/.github/workflows/dic2owl_ci.yml +++ b/.github/workflows/dic2owl_ci.yml @@ -1,6 +1,9 @@ name: CI - dic2owl -on: [push, pull_request] +on: + push: + paths: + - 'dic2owl/**' jobs: @@ -28,12 +31,12 @@ jobs: run: bandit -r dic2owl/dic2owl - name: Run PyLint - run: pylint dic2owl/dic2owl + run: pylint --rcfile=dic2owl/pyproject.toml dic2owl/dic2owl - name: Run safety run: | - safety check -r dic2owl/requirements.txt --bare - safety check -r dic2owl/requirements_dev.txt --bare + DEPENDENCIES=$( python .github/static/get_dic2owl_deps.py dic2owl/requirements.txt dic2owl/requirements_dev.txt ) + pip freeze | grep -E "${DEPENDENCIES}" | safety check --stdin - name: Lint with MyPy run: mypy --ignore-missing-imports --scripts-are-modules dic2owl/dic2owl diff --git a/.gitignore b/.gitignore index 29ae2fb..bc1ddcd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ old __pycache__ *.pyc +.mypy* + *.dic *.cif diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 772957e..e895e6d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,17 +10,13 @@ repos: rev: 21.7b0 hooks: - id: black - name: Blacken + args: + - --config=dic2owl/pyproject.toml -- repo: https://gitlab.com/pycqa/flake8 - rev: '3.9.2' +- repo: https://github.com/pycqa/pylint + rev: 'v2.10.1' hooks: - - id: flake8 + - id: pylint args: - - --count - - --show-source - - --statistics - # E501: Line to long. Handled by black. - # W503: Line break before binary operator. This is preferred formatting for black. - # E203: Whitespace before ':'. - - --ignore=E501,W503,E203 + - --rcfile=dic2owl/pyproject.toml + - --disable=import-error diff --git a/dic2owl/dic2owl/__init__.py b/dic2owl/dic2owl/__init__.py index e922b51..017aa3d 100644 --- a/dic2owl/dic2owl/__init__.py +++ b/dic2owl/dic2owl/__init__.py @@ -1,3 +1,19 @@ +""" +# `dic2owl` Python package + +This is a tool to generate ontologies from a CIF `.dic`-file. + +It can be used either by importing and using the `dic2owl.dic2owl.main` +function or running it via the `dic2owl` CLI, which will be automatically +installed when `pip install`-ing this package. +For more information on how to run the CLI, run `dic2owl --help` in your +terminal. +""" + __version__ = "0.1.0" -__author__ = "Jesper Friis" -__author_email__ = "jesper.friis@sintef.no" +__author__ = ( + "Jesper Friis , " + "Casper Welzel Andersen , " + "Francesca Lønstad Bleken " +) +__author_email__ = "cif@emmo-repo.eu" diff --git a/dic2owl/dic2owl/cli.py b/dic2owl/dic2owl/cli.py index a8f1694..2277c93 100644 --- a/dic2owl/dic2owl/cli.py +++ b/dic2owl/dic2owl/cli.py @@ -1,9 +1,17 @@ +""" +# `dic2owl` CLI + +The `dic2owl` command line interface (CLI) is an easy way of running the +ontology-generation tool for CIF `.dic`-files. +""" import argparse import logging from pathlib import Path -LOGGING_LEVELS = [logging.getLevelName(level).lower() for level in range(0, 51, 10)] +LOGGING_LEVELS = [ + logging.getLevelName(level).lower() for level in range(0, 51, 10) +] def main(argv: list = None) -> None: @@ -11,8 +19,9 @@ def main(argv: list = None) -> None: Produce an OWL Turtle (`.ttl`) file from a CIF dictionary (`.dic`) file. """ + # pylint: disable=import-outside-toplevel from dic2owl import __version__ - from dic2owl.generate_cif import main as dic2owl_run + from dic2owl.dic2owl import main as dic2owl_run parser = argparse.ArgumentParser( description=main.__doc__, @@ -43,24 +52,31 @@ def main(argv: list = None) -> None: dest="ttlfile", type=Path, help=( - 'The generated output file. Example "--output cif_core.ttl". If output is not ' - "provided, the filename will be taken to be similar to the CIF_DIC file." + 'The generated output file. Example "--output cif_core.ttl". If ' + "output is not provided, the filename will be taken to be similar " + "to the CIF_DIC file." ), ) parser.add_argument( "dicfile", metavar="CIF_DIC", type=Path, - help="The CIF dictionary file from which to generate an OWL ontologized Turtle file.", + help=( + "The CIF dictionary file from which to generate an OWL ontologized" + " Turtle file." + ), ) args = parser.parse_args(argv) if args.ttlfile is None: - args.ttlfile = args.dicfile.resolve().name[: -len(args.dicfile.suffix)] + ".ttl" + args.ttlfile = ( + args.dicfile.resolve().name[: -len(args.dicfile.suffix)] + ".ttl" + ) if not args.dicfile.resolve().exists(): - # The dic-file does not exist, use it as a string instead so it can be downloaded. + # The dic-file does not exist, use it as a string instead so it can be + # downloaded. args.dicfile = str(args.dicfile) dic2owl_run(dicfile=args.dicfile, ttlfile=args.ttlfile) diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index 129a1c3..c26f3a2 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """ # Generate ontology @@ -10,14 +9,14 @@ # import textwrap import types -from typing import Union, Sequence +from typing import Any, Set, Union, Sequence import urllib.request from CifFile import CifDic # Remove the print statement concerning 'owlready2_optimized' # when importing owlready2 (which is imported also in emmo). -with open(DEVNULL, "w") as handle: +with open(DEVNULL, "w") as handle: # pylint: disable=unspecified-encoding with redirect_stderr(handle): from emmo import World from emmo.ontology import Ontology @@ -28,17 +27,19 @@ # Workaround for flaw in EMMO-Python # To be removed when EMMO-Python doesn't requires ontologies to import SKOS import emmo.ontology # noqa: E402 + emmo.ontology.DEFAULT_LABEL_ANNOTATIONS = [ "http://www.w3.org/2000/01/rdf-schema#label", ] """The absolute, normalized path to the `ontology` directory in this repository""" -ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath( - "ontology") +ONTOLOGY_DIR = ( + Path(__file__).resolve().parent.parent.parent.joinpath("ontology") +) -def en(string: str) -> locstr: +def lang_en(string: str) -> locstr: """Converted to an English-localized string. Parameters: @@ -52,10 +53,10 @@ def en(string: str) -> locstr: class MissingAnnotationError(Exception): - """Raised when using a cif-dictionary annotation not defined in ddl - """ + """Raised when using a cif-dictionary annotation not defined in ddl""" +# pylint: disable=too-few-public-methods class Generator: """Class for generating CIF ontology from a CIF dictionary. @@ -64,15 +65,16 @@ class Generator: base_iri: Base IRI of the generated ontology. comments: Sequence of comments to add to the ontology itself. """ + # TODO: # Should `comments` be replaced with a dict `annotations` for annotating # the ontology itself? If so, we should import Dublin Core. def __init__( - self, - dicfile: str, - base_iri: str, - comments: Sequence[str] = (), + self, + dicfile: str, + base_iri: str, + comments: Sequence[str] = (), ) -> None: self.dicfile = dicfile self.dic = CifDic(dicfile, do_dREL=False) @@ -89,10 +91,10 @@ def __init__( self.onto.imported_ontologies.append(self.ddl) # Load Dublin core for metadata and append it to imported ontologies - #dcterms = self.world.get_ontology('http://purl.org/dc/terms/').load() - #self.onto.imported_ontologies.append(dcterms) + # dcterms = self.world.get_ontology('http://purl.org/dc/terms/').load() + # self.onto.imported_ontologies.append(dcterms) - self.items = set() + self.items: Set[dict] = set() def generate(self) -> Ontology: """Generate ontology for the CIF dictionary. @@ -124,11 +126,11 @@ def _add_top(self, item) -> None: """ with self.onto: top = types.new_class( - item["_dictionary.title"], (self.ddl.DictionaryDefinedItem, ) + item["_dictionary.title"], (self.ddl.DictionaryDefinedItem,) ) self._add_annotations(top, item) - def _add_category(self, item) -> None: + def _add_category(self, item: dict) -> None: """Add category. Parameters: @@ -168,16 +170,16 @@ def _add_data_value(self, item: dict) -> None: parents = [] parent_name1 = item["_name.category_id"] parent = self.dic[parent_name1] - parent_name = parent['_definition.id'] + parent_name = parent["_definition.id"] self._add_item(parent) parents.append(self.onto[parent_name]) for ddl_name, value in item.items(): - if ddl_name.startswith('_type.'): - if ddl_name == '_type.dimension': + if ddl_name.startswith("_type."): + if ddl_name == "_type.dimension": # TODO - fix special case pass - elif value == 'Implied': + elif value == "Implied": # TODO - fix special case pass else: @@ -188,13 +190,13 @@ def _add_data_value(self, item: dict) -> None: self._add_annotations(cls, item) - def _add_annotations(self, cls, item) -> None: - """Add annotations for dic item `item` to generated on ontology + def _add_annotations(self, cls: Any, item: dict) -> None: + """Add annotations for dic item `item` to generated ontology class `cls`. Parameters: - cls: Generated ontology class to wich the annotations should - be added. + cls: Generated ontology class to which the annotations should + be added. item: Dic item with annotation info. """ @@ -206,19 +208,20 @@ class `cls`. # Assign annotation annot = getattr(cls, annotation_name) - annot.append(en(value)) + annot.append(lang_en(value)) - def _add_metadata(self): + def _add_metadata(self) -> None: """Adds metadata to the generated ontology.""" # TODO: # Is there a way to extract metadata from the dic object like # _dictionary_audit.version? - #onto.set_version(version="XXX") + # onto.set_version(version="XXX") for comment in self.comments: self.onto.metadata.comment.append(comment) self.onto.metadata.comment.append( - f'Generated with dic2owl from {self.dicfile}') + f"Generated with dic2owl from {self.dicfile}" + ) def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: @@ -250,7 +253,9 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: for dic in ("ddl.dic", "templ_attr.cif", "templ_enum.cif", dicfile): if not Path(dic).resolve().exists(): print("downloading", dic) - urllib.request.urlretrieve(baseurl + dic, dic) + # Since `baseurl` is used, the retrieved URL will never be a + # `file://` or similar. + urllib.request.urlretrieve(baseurl + dic, dic) # nosec gen = Generator(dicfile=dicfile, base_iri=base_iri) onto = gen.generate() @@ -260,13 +265,3 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: ) return gen # XXX - just for debugging - - -if __name__ == "__main__": - # main() - - # for debugging and testing... - self = gen = main("cif_core.dic", "cif_core.ttl") - dic = self.dic - ddl = self.ddl - onto = self.onto diff --git a/dic2owl/dic2owl/generate_cif.py b/dic2owl/dic2owl/generate_cif.py deleted file mode 100644 index 55f7ce8..0000000 --- a/dic2owl/dic2owl/generate_cif.py +++ /dev/null @@ -1,239 +0,0 @@ -#!/usr/bin/env python -""" -# Generate ontology - -Python script for generating an ontology corresponding to a CIF dictionary. -""" -from contextlib import redirect_stderr -from os import devnull as DEVNULL -from pathlib import Path -import textwrap -import types -from typing import Union -import urllib.request - -# Remove the print statement concerning 'owlready2_optimized' -# when importing owlready2 (which is imported also in emmo). -with open(DEVNULL, "w") as handle: - with redirect_stderr(handle): - from emmo import World - import owlready2 - from owlready2 import locstr - -from CifFile import CifDic - - -def en(s): - """Returns `s` converted to a localised string in english.""" - return locstr(s, lang="en") - - -def ontology_dir() -> Path: - """Return the absolute, normalized path to the `ontology` directory in this repository""" - return Path(__file__).parent.parent.parent.joinpath("ontology").resolve() - - -class Generator: - """Class for generating CIF ontology from a CIF dictionary. - - Parameters: - dicfile : string - File name of CIF dictionary to generate an ontology for. - base_iri : string - Base IRI of the generated ontology. - cif_top : string - URI or file name of the cif_top ontology that will be imported. - """ - - def __init__(self, dicfile, base_iri, cif_top="cif_top.ttl"): - self.cd = CifDic(dicfile, do_dREL=False) - self.cif_top = ontology_dir() / cif_top - self.categories = set() - - # Load cif_top ontology - self.world = World() - self.top = self.world.get_ontology(str(self.cif_top)).load() - self.top.sync_python_names() - - # Create new ontology - self.onto = self.world.get_ontology(base_iri) - self.onto.imported_ontologies.append(self.top) - - def generate(self): - """Generate ontology for the CIF dictionary.""" - # Add categories first so they are available when we add data items. - # A category seems to be characterised by having a _definition.scope - # attribute. - for item in self.cd: - if "_definition.scope" in item: - self._add_category(item) - - # Add data items - for item in self.cd: - if "_definition.scope" not in item: - self._add_data_value(item) - - return self.onto - - def _add_category(self, item): - """Add category.""" - if item in self.categories: - return - self.categories.add(item) - - name = item["_definition.id"] - descr = item.get("_description.text") - lname = "_" + name.lstrip("_").lower() - with self.onto: - if item.get("_definition.class"): - loop = types.new_class(lname + "_LOOP", (self.top.LOOP,)) - loop.prefLabel.append(en(loop.name.lstrip("_"))) - packet = types.new_class(lname + "_PACKET", (self.top.PACKET,)) - packet.prefLabel.append(en(packet.name.lstrip("_"))) - cat = types.new_class(name, (self.top.CATEGORY,)) - cat.prefLabel.append(en(cat.name.lstrip("_"))) - if descr: - cat.comment.append(en(textwrap.dedent(descr))) - loop.is_a.append(self.top.hasSpatialDirectPart.some(packet)) - loop.is_a.append(self.top.hasSpatialPart.only(cat)) - else: - print("** ignoring category:", name) - - def _add_data_value(self, item): - """Add data item.""" - realname = item["_definition.id"] - name = realname.replace(".", "_") - descr = item.get("_description.text") - units = item.get("_units.code") - aliases = item.get("_alias.definition_id") - examples = item.get("_description_example.detail", []) - examples.extend(item.get("_description_example.case", [])) - dimension = item.get("_type.dimension") - - container_name = item.get("_type.container", "Single") - datatype_name = item.get("_type.contents", "Text") - category_name = item["_name.category_id"].upper() - packet_name = "_%s_PACKET" % item["_name.category_id"] - - container = self.onto[container_name] - datatype = self.onto[datatype_name] - category = self.onto[category_name] - - with self.onto: - - if container_name == "Single": - e = types.new_class(name, (datatype,)) - elif container_name in ("Matrix", "Array"): - dims = dimension.strip("[]") - if dims: - subarr = self.subarray(dims.split(","), datatype, container_name) - e = types.new_class(name, (subarr,)) - else: - e = types.new_class(name, (datatype,)) - else: - e = types.new_class(name, (container,)) - if container_name == "List": - e.is_a.append(self.top.hasSpatialDirectPart.some(datatype)) - else: - e.is_a.append(self.top.hasSpatialPart.some(datatype)) - - if category.disjoint_unions: - category.disjoint_unions[0].append(e) - else: - category.disjoint_unions.append([e]) - e.prefLabel.append(en(realname.lstrip("_"))) - if name != realname: - e.altLabel.append(en(name.lstrip("_"))) - - # Hmm, _name is already used internally by owlready2.Ontology - # so `e._name.append(name)` won't work. - # We have to add the tripple the hard way... - o, d = owlready2.to_literal(realname) # not localised - self.onto._set_data_triple_spod( - s=e.storid, p=self.onto.world._props["_name"].storid, o=o, d=d - ) - - if aliases: - e.altLabel.extend(en(a) for a in aliases) - if descr: - e.comment.append(en(textwrap.dedent(descr))) - if examples: - e.example.extend(en(textwrap.dedent(ex)) for ex in examples) - if units: - e._unit.append(units) # not localised - if dimension: - e._dimension.append(dimension) # not localised - if datatype: - e._datatype.append(datatype) # not localised - if packet_name in self.onto: - packet = self.onto[packet_name] - packet.is_a.append(self.top.hasSpatialDirectPart.max(1, e)) - else: - print("** no packet:", realname) - - def subarray(self, dimensions, datatype, container_name): - """Returns a reference to an array or matrix corresponding to: - - dimensions: list of dimension values - - typename: type of elements - - container_name: "Array" or "Matrix" - If it does not already exists, the subarray is created. All - its spatial direct parts are also generated recursively. - """ - if not dimensions or not dimensions[0]: - return datatype - name = "Shape" + "x".join(dimensions) + datatype.name + container_name - if name not in self.onto: - e = types.new_class(name, (self.onto[container_name],)) - d = int(dimensions.pop(0)) - e.is_a.append( - self.top.hasSpatialDirectPart.exactly( - d, self.subarray(dimensions, datatype, container_name) - ) - ) - return self.onto[name] - - -def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: - base_iri = "http://emmo.info/CIF-ontology/cif_core#" - - dicfile = dicfile if isinstance(dicfile, str) else str(dicfile.resolve()) - - # Download the CIF dictionaries to current directory - baseurl = "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" - for dic in ("ddl.dic", "templ_attr.cif", "templ_enum.cif") + (dicfile,): - if not Path(dic).resolve().exists(): - print("downloading", dic) - urllib.request.urlretrieve(baseurl + dic, dic) - - gen = Generator(dicfile=dicfile, base_iri=base_iri) - onto = gen.generate() - - # Annotate ontology - onto.sync_attributes() - onto.set_version(version="0.0.1") - onto.metadata.abstract = ( - "CIF core ontology generated from the CIF core definitions at " - "https://raw.githubusercontent.com/COMCIFS/cif_core/master/" - ) - - if ttlfile is None: - ttlfile = Path(dicfile).name[: -len(Path(dicfile).suffix)] + ".ttl" - - onto.save( - ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()), - overwrite=True, - ) - - return gen # XXX - just for debugging - - -if __name__ == "__main__": - # main() - - # for debugging and testing... - self = gen = main("cif_core.dic", "cif_core.ttl") - top = self.top - onto = self.onto - cd = self.cd - sid = cd["space_group_symop.id"] - s = cd["SPACE_GROUP_SYMOP"] diff --git a/dic2owl/pyproject.toml b/dic2owl/pyproject.toml new file mode 100644 index 0000000..d5129e6 --- /dev/null +++ b/dic2owl/pyproject.toml @@ -0,0 +1,651 @@ +[tool.black] +line-length = 79 +target-version = ['py37', 'py38', 'py39'] + +[tool.pylint.MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +# extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +# extension-pkg-whitelist= + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +# fail-on= + +# Specify a score threshold to be exceeded before program exits with error. +fail-under=10.0 + +# Files or directories to be skipped. They should be base names, not paths. +ignore='CVS' + +# Add files or directories matching the regex patterns to the ignore-list. The +# regex matches against paths. +# ignore-paths= + +# Files or directories matching the regex patterns are skipped. The regex +# matches against base names, not paths. +# ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +# load-plugins= + +# Pickle collected data for later comparisons. +persistent=true + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=true + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=false + + +[tool.pylint.MESSAGES_CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +# confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=[ + 'print-statement', + 'parameter-unpacking', + 'unpacking-in-except', + 'old-raise-syntax', + 'backtick', + 'long-suffix', + 'old-ne-operator', + 'old-octal-literal', + 'import-star-module-level', + 'non-ascii-bytes-literal', + 'raw-checker-failed', + 'bad-inline-option', + 'locally-disabled', + 'file-ignored', + 'suppressed-message', + 'useless-suppression', + 'deprecated-pragma', + 'use-symbolic-message-instead', + 'apply-builtin', + 'basestring-builtin', + 'buffer-builtin', + 'cmp-builtin', + 'coerce-builtin', + 'execfile-builtin', + 'file-builtin', + 'long-builtin', + 'raw_input-builtin', + 'reduce-builtin', + 'standarderror-builtin', + 'unicode-builtin', + 'xrange-builtin', + 'coerce-method', + 'delslice-method', + 'getslice-method', + 'setslice-method', + 'no-absolute-import', + 'old-division', + 'dict-iter-method', + 'dict-view-method', + 'next-method-called', + 'metaclass-assignment', + 'indexing-exception', + 'raising-string', + 'reload-builtin', + 'oct-method', + 'hex-method', + 'nonzero-method', + 'cmp-method', + 'input-builtin', + 'round-builtin', + 'intern-builtin', + 'unichr-builtin', + 'map-builtin-not-iterating', + 'zip-builtin-not-iterating', + 'range-builtin-not-iterating', + 'filter-builtin-not-iterating', + 'using-cmp-argument', + 'eq-without-hash', + 'div-method', + 'idiv-method', + 'rdiv-method', + 'exception-message-attribute', + 'invalid-str-codec', + 'sys-max-int', + 'bad-python3-import', + 'deprecated-string-function', + 'deprecated-str-translate-call', + 'deprecated-itertools-function', + 'deprecated-types-field', + 'next-method-defined', + 'dict-items-not-iterating', + 'dict-keys-not-iterating', + 'dict-values-not-iterating', + 'deprecated-operator-function', + 'deprecated-urllib-function', + 'xreadlines-attribute', + 'deprecated-sys-function', + 'exception-escape', + 'comprehension-escape', + 'unspecified-encoding', + 'fixme' +] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable='c-extension-no-member' + + +[tool.pylint.REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'error', 'warning', 'refactor', and 'convention' +# which contain the number of messages in each category, as well as 'statement' +# which is the total number of statements analyzed. This score is used by the +# global evaluation report (RP0004). +evaluation='10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)' + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +output-format='text' + +# Tells whether to display a full report or only the messages. +reports=false + +# Activate the evaluation score. +score=true + + +[tool.pylint.REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=['sys.exit', 'argparse.parse_error'] + + +[tool.pylint.STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=false + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=false + + +[tool.pylint.MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=[ + 'FIXME', + 'XXX', + 'TODO' +] + +# Regular expression of note tags to take in consideration. +#notes-rgx= + + +[tool.pylint.SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it work, +# install the 'python-enchant' package. +# spelling-dict= + +# List of comma separated words that should be considered directives if they +# appear and the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=[ + 'fmt: on', + 'fmt: off', + 'noqa:', + 'noqa', + 'nosec', + 'isort:skip', + 'mypy:' +] + +# List of comma separated words that should not be checked. +# spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +# spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=false + + +[tool.pylint.BASIC] + +# Naming style matching correct argument names. +argument-naming-style='snake_case' + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style='snake_case' + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=[ + 'foo', + 'bar', + 'baz', + 'toto', + 'tutu', + 'tata' +] + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +# bad-names-rgxs= + +# Naming style matching correct class attribute names. +class-attribute-naming-style='any' + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. +#class-attribute-rgx= + +# Naming style matching correct class constant names. +class-const-naming-style='UPPER_CASE' + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. +#class-const-rgx= + +# Naming style matching correct class names. +class-naming-style='PascalCase' + +# Regular expression matching correct class names. Overrides class-naming- +# style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style='UPPER_CASE' + +# Regular expression matching correct constant names. Overrides const-naming- +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style='snake_case' + +# Regular expression matching correct function names. Overrides function- +# naming-style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=[ + 'i', + 'j', + 'k', + 'ex', + 'Run', + '_' +] + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +# good-names-rgxs= + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=false + +# Naming style matching correct inline iteration names. +inlinevar-naming-style='any' + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style='snake_case' + +# Regular expression matching correct method names. Overrides method-naming- +# style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style='snake_case' + +# Regular expression matching correct module names. Overrides module-naming- +# style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +# name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx='^_' + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes='abc.abstractproperty' + +# Naming style matching correct variable names. +variable-naming-style='snake_case' + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. +#variable-rgx= + + +[tool.pylint.LOGGING] + +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style='old' + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules='logging' + + +[tool.pylint.VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +# additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=true + +# List of names allowed to shadow builtins +# allowed-redefined-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=['cb_', '_cb'] + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx='_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_' + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names='_.*|^ignored_|^unused_' + +# Tells whether we should check for unused import in __init__ files. +init-import=false + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=['six.moves', 'past.builtins', 'future.builtins', 'builtins', 'io'] + + +[tool.pylint.TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators='contextlib.contextmanager' + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +# generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=true + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=true + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=true + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=['optparse.Values', 'thread._local', '_thread._local'] + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +# ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=true + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# List of decorators that change the signature of a decorated function. +# signature-mutators= + + +[tool.pylint.FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines='^\s*(# )??$' + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=80 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=false + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=false + + +[oylint.SIMILARITIES] + +# Comments are removed from the similarity computation +ignore-comments=true + +# Docstrings are removed from the similarity computation +ignore-docstrings=true + +# Imports are removed from the similarity computation +ignore-imports=false + +# Signatures are removed from the similarity computation +ignore-signatures=false + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[tool.pylint.DESIGN] + +# List of qualified class names to ignore when countint class parents (see +# R0901) +# ignored-parents= + +# Maximum number of arguments for function / method. +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[tool.pylint.IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +# allow-any-import-level= + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=false + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=false + +# Deprecated modules which should not be used, separated by a comma. +# deprecated-modules= + +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). +# ext-import-graph= + +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). +# import-graph= + +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). +# int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +# known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party='enchant' + +# Couples of modules and preferred modules, separated by a comma. +# preferred-modules= + + +[tool.pylint.CLASSES] + +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=false + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=[ + '__init__', + '__new__', + 'setUp', + '__post_init__' +] + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=[ + '_asdict', + '_fields', + '_replace', + '_source', + '_make' +] + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg='cls' + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg='cls' + + +[tool.pylint.EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "BaseException, Exception". +overgeneral-exceptions=['BaseException', 'Exception'] diff --git a/dic2owl/requirements.txt b/dic2owl/requirements.txt index e611334..7a2f307 100644 --- a/dic2owl/requirements.txt +++ b/dic2owl/requirements.txt @@ -1,2 +1,2 @@ -EMMO~=1.0 -PyCifRW~=4.4,>=4.4.3 +EMMO>=1.0.1,<2 +PyCifRW>=4.4.3,<5 diff --git a/dic2owl/requirements_dev.txt b/dic2owl/requirements_dev.txt index 9057ccd..e558478 100644 --- a/dic2owl/requirements_dev.txt +++ b/dic2owl/requirements_dev.txt @@ -1,2 +1,4 @@ -pre-commit~=2.14 -pylint~=2.9 +bandit~=1.7.0 +mypy==0.910 +pre-commit>=2.14.0,<3 +pylint>=2.10.1,<3 diff --git a/dic2owl/setup.py b/dic2owl/setup.py index 1417eb0..b84c4f5 100644 --- a/dic2owl/setup.py +++ b/dic2owl/setup.py @@ -1,3 +1,13 @@ +""" +# Install `dic2owl` + +Run `pip install -e .` when in the folder of this file. +If in the root of the repository run instead `pip install -e ./dic2owl`. + +Together with the `dic2owl` package, the CLI tool with the same name will be +installed. +To find out more, run `dic2owl --help` after a successful installation. +""" from pathlib import Path import re @@ -31,11 +41,14 @@ }.items(): if value is None: raise RuntimeError( - f"Could not determine {info} from {PACKAGE_DIR / 'dic2owl/__init__.py'} !" + ( + f"Could not determine {info} from " + f"{PACKAGE_DIR / 'dic2owl/__init__.py'} !" + ) ) - VERSION = VERSION.group("version") - AUTHOR = AUTHOR.group("author") - AUTHOR_EMAIL = AUTHOR_EMAIL.group("email") + VERSION = VERSION.group("version") # type: ignore + AUTHOR = AUTHOR.group("author") # type: ignore + AUTHOR_EMAIL = AUTHOR_EMAIL.group("email") # type: ignore with open(PACKAGE_DIR / "requirements.txt", "r") as handle: BASE = [ From 2a902e626c8663e149625a8be70457a3279f62dd Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Fri, 27 Aug 2021 13:49:23 +0200 Subject: [PATCH 7/9] Proper import of the ddl ontology --- dic2owl/dic2owl/dic2owl.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index c26f3a2..5f35003 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -85,7 +85,10 @@ def __init__( self.onto = self.world.get_ontology(base_iri) # Load cif-ddl ontology and append it to imported ontologies - cif_ddl = ONTOLOGY_DIR / "cif-ddl.ttl" + # TODO - update the url below when the dic2owl branch is merged into + # master... + #cif_ddl = 'https://raw.githubusercontent.com/emmo-repo/CIF-ontology/main/ontology/cif-ddl.ttl' + cif_ddl = 'https://raw.githubusercontent.com/emmo-repo/CIF-ontology/dic2owl/ontology/cif-ddl.ttl' self.ddl = self.world.get_ontology(str(cif_ddl)).load() self.ddl.sync_python_names() self.onto.imported_ontologies.append(self.ddl) @@ -265,3 +268,6 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: ) return gen # XXX - just for debugging + + +main('cif_core.dic', 'cif_core.ttl') From 53f434ad28f9ed9284807638c31a2084ca88d1a4 Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Fri, 27 Aug 2021 14:53:10 +0200 Subject: [PATCH 8/9] Fix install Ensure `dic2owl` is installable through CI. --- .github/workflows/dic2owl_ci.yml | 2 +- dic2owl/dic2owl/__init__.py | 7 ++----- dic2owl/dic2owl/dic2owl.py | 16 ++++++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dic2owl_ci.yml b/.github/workflows/dic2owl_ci.yml index 33b108a..0e39b03 100644 --- a/.github/workflows/dic2owl_ci.yml +++ b/.github/workflows/dic2owl_ci.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools wheel - pip install -U -r dic2owl/requirements.txt + pip install -U -e dic2owl pip install bandit pylint safety mypy pytest pytest-cov - name: Run bandit diff --git a/dic2owl/dic2owl/__init__.py b/dic2owl/dic2owl/__init__.py index 017aa3d..0494274 100644 --- a/dic2owl/dic2owl/__init__.py +++ b/dic2owl/dic2owl/__init__.py @@ -9,11 +9,8 @@ For more information on how to run the CLI, run `dic2owl --help` in your terminal. """ +# pylint: disable=line-too-long __version__ = "0.1.0" -__author__ = ( - "Jesper Friis , " - "Casper Welzel Andersen , " - "Francesca Lønstad Bleken " -) +__author__ = "Jesper Friis , Casper Welzel Andersen , Francesca Lønstad Bleken " __author_email__ = "cif@emmo-repo.eu" diff --git a/dic2owl/dic2owl/dic2owl.py b/dic2owl/dic2owl/dic2owl.py index 5f35003..d3b9ad2 100644 --- a/dic2owl/dic2owl/dic2owl.py +++ b/dic2owl/dic2owl/dic2owl.py @@ -64,6 +64,7 @@ class Generator: dicfile: File name of CIF dictionary to generate an ontology for. base_iri: Base IRI of the generated ontology. comments: Sequence of comments to add to the ontology itself. + """ # TODO: @@ -86,9 +87,15 @@ def __init__( # Load cif-ddl ontology and append it to imported ontologies # TODO - update the url below when the dic2owl branch is merged into - # master... - #cif_ddl = 'https://raw.githubusercontent.com/emmo-repo/CIF-ontology/main/ontology/cif-ddl.ttl' - cif_ddl = 'https://raw.githubusercontent.com/emmo-repo/CIF-ontology/dic2owl/ontology/cif-ddl.ttl' + # main... + # cif_ddl = ( + # "https://raw.githubusercontent.com/emmo-repo/CIF-ontology/main/" + # "ontology/cif-ddl.ttl" + # ) + cif_ddl = ( + "https://raw.githubusercontent.com/emmo-repo/CIF-ontology/dic2owl" + "/ontology/cif-ddl.ttl" + ) self.ddl = self.world.get_ontology(str(cif_ddl)).load() self.ddl.sync_python_names() self.onto.imported_ontologies.append(self.ddl) @@ -268,6 +275,3 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator: ) return gen # XXX - just for debugging - - -main('cif_core.dic', 'cif_core.ttl') From 6868e60152825833d1f964b9dbe63cb0b51f03dd Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Fri, 27 Aug 2021 15:38:21 +0200 Subject: [PATCH 9/9] Update dic2owl to be v0.2.0 --- dic2owl/dic2owl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dic2owl/dic2owl/__init__.py b/dic2owl/dic2owl/__init__.py index 0494274..cbde23a 100644 --- a/dic2owl/dic2owl/__init__.py +++ b/dic2owl/dic2owl/__init__.py @@ -11,6 +11,6 @@ """ # pylint: disable=line-too-long -__version__ = "0.1.0" +__version__ = "0.2.0" __author__ = "Jesper Friis , Casper Welzel Andersen , Francesca Lønstad Bleken " __author_email__ = "cif@emmo-repo.eu"