From 12c6381a3330075d4b6340955c9075628e1c1199 Mon Sep 17 00:00:00 2001 From: francescalb Date: Tue, 17 Jan 2023 14:04:40 +0100 Subject: [PATCH 1/3] Some testing --- ontopy/ontodoc.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ontopy/ontodoc.py b/ontopy/ontodoc.py index 3092d13bc..13da0e2c5 100644 --- a/ontopy/ontodoc.py +++ b/ontopy/ontodoc.py @@ -392,14 +392,28 @@ def itemdoc( # Instances (individuals) if hasattr(item, "instances"): points = [] + for individual in item.instances(): + print("item", item, "is a", item.is_a) + print( + "individual", + individual, + "is instance of", + individual.is_instance_of, + ) + + # print(item.individual.is_instance_of) + for entity in [ _ for _ in item.instances() if item in _.is_instance_of ]: + print("entity", entity) + print("a", points) points.append( point_style.format( point=asstring(entity, link_style), ontology=onto ) ) + print("b", points) if points: value = points_style.format( points="".join(points), ontology=onto @@ -409,7 +423,6 @@ def itemdoc( key="Individuals", value=value, ontology=onto ) ) - return "\n".join(doc) def itemsdoc(self, items, header_level=3): From a36e987c4de09889ffdfa2bb9dbd894e4e4fc76f Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 2 Feb 2023 17:27:10 +0100 Subject: [PATCH 2/3] Fixed new pylint requirements --- demo/horizontal/emmo2meta.py | 2 +- ontopy/graph.py | 2 +- ontopy/ontodoc.py | 68 ++++++++++++++++++------------------ ontopy/ontology.py | 9 ++--- ontopy/patch.py | 5 ++- 5 files changed, 45 insertions(+), 41 deletions(-) diff --git a/demo/horizontal/emmo2meta.py b/demo/horizontal/emmo2meta.py index 9ca36036d..1c4538938 100644 --- a/demo/horizontal/emmo2meta.py +++ b/demo/horizontal/emmo2meta.py @@ -174,7 +174,7 @@ def get_properties(self, cls): # pylint: disable=too-many-locals props = [] dimindices = {} propnames = set() - types = dict(Integer="int", Real="double", String="string") + types = {"Integer": "int", "Real": "double", "String": "string"} def get_dim(restriction, name, descr=None): """Returns dimension index corresponding to dimension name `name` diff --git a/ontopy/graph.py b/ontopy/graph.py index ec142243a..ba69d4dff 100644 --- a/ontopy/graph.py +++ b/ontopy/graph.py @@ -264,7 +264,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals self.edges = set() else: if ontology != graph.ontology: - ValueError( + raise ValueError( "the same ontology must be used when extending a graph" ) self.dot = graph.dot.copy() diff --git a/ontopy/ontodoc.py b/ontopy/ontodoc.py index 13da0e2c5..3f97ef22c 100644 --- a/ontopy/ontodoc.py +++ b/ontopy/ontodoc.py @@ -49,20 +49,20 @@ class OntoDoc: annotation values. """ - _markdown_style = dict( - sep="\n", - figwidth="{{ width={width:.0f}px }}", - figure="![{caption}]({path}){figwidth}\n", - header="\n{:#<{level}} {label}", - link="[{name}]({lowerurl})", - point=" - {point}\n", - points="\n\n{points}\n", - annotation="**{key}:** {value}\n", - substitutions=[], - ) + _markdown_style = { + "sep": "\n", + "figwidth": "{{ width={width:.0f}px }}", + "figure": "![{caption}]({path}){figwidth}\n", + "header": "\n{:#<{level}} {label}", + "link": "[{name}]({lowerurl})", + "point": " - {point}\n", + "points": "\n\n{points}\n", + "annotation": "**{key}:** {value}\n", + "substitutions": [], + } # Extra style settings for markdown+tex (e.g. pdf generation with pandoc) - _markdown_tex_extra_style = dict( - substitutions=[ + _markdown_tex_extra_style = { + "substitutions": [ # logic/math symbols ("\u2200", r"$\\forall$"), ("\u2203", r"$\\exists$"), @@ -132,17 +132,17 @@ class OntoDoc: ("\u014d", r"$\\bar{\\mathrm{o}}$"), ("\u1f45", r"$\\acute{o}$"), # no \omicron ], - ) - _html_style = dict( - sep="

\n", - figwidth='width="{width:.0f}"', - figure='{caption}', - header='{label}', - link='{name}', - point="

  • {point}
  • \n", - points=" \n", - annotation="
    {key}:\n{value}
    \n", - substitutions=[ + } + _html_style = { + "sep": "

    \n", + "figwidth": 'width="{width:.0f}"', + "figure": '{caption}', + "header": '{label}', + "link": '{name}', + "point": "

  • {point}
  • \n", + "points": " \n", + "annotation": "
    {key}:\n{value}
    \n", + "substitutions": [ (r"&", r"‒"), (r"

    ", r"

    \n\n"), (r"\u2018([^\u2019]*)\u2019", r"\1"), @@ -154,7 +154,7 @@ class OntoDoc: (r"\u226B", r"&x226B;"), (r'"Y$', r""), # strange noice added by owlready2 ], - ) + } def __init__(self, onto, style="markdown"): if isinstance(style, str): @@ -243,15 +243,15 @@ def itemdoc( substitutions = self.style.get("substitutions", []) # Logical "sorting" of annotations - order = dict( - definition="00", - axiom="01", - theorem="02", - elucidation="03", - domain="04", - range="05", - example="06", - ) + order = { + "definition": "00", + "axiom": "01", + "theorem": "02", + "elucidation": "03", + "domain": "04", + "range": "05", + "example": "06", + } doc = [] diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 90eed6c08..d3fd267b1 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -220,8 +220,7 @@ def __contains__(self, other): self.get_by_label(other) except NoSuchLabelError: return False - else: - return True + return True def __objclass__(self): # Play nice with inspect... @@ -782,7 +781,7 @@ def save( fmt = revmap.get(format, format) filename = f"{self.name}.{fmt}" else: - TypeError("`filename` and `format` cannot both be None.") + raise TypeError("`filename` and `format` cannot both be None.") filename = os.path.join(dir, filename) dir = Path(filename).resolve().parent @@ -1465,7 +1464,9 @@ def closest_common_ancestor(*classes): return cur if len(mro) == 0: mros.remove(mro) - raise Exception("A closest common ancestor should always exist !") + raise EMMOntoPyException( + "A closest common ancestor should always exist !" + ) def get_ancestors(self, classes, include="all", strict=True): """Return ancestors of all classes in `classes`. diff --git a/ontopy/patch.py b/ontopy/patch.py index d67525dcb..6a957e2cc 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -5,6 +5,7 @@ import owlready2 from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace from owlready2 import Metadata +from ontopy.utils import EMMOntoPyException def render_func(entity): @@ -60,7 +61,9 @@ def get_parents(self, strict=False): for cls in self.is_a if isinstance(cls, owlready2.ObjectPropertyClass) } - raise Exception("self has no parents - this should not be possible!") + raise EMMOntoPyException( + "self has no parents - this should not be possible!" + ) def _dir(self): From 3a0464c0c42d80f8ba6c7c01546da85436ac208c Mon Sep 17 00:00:00 2001 From: francescalb Date: Fri, 3 Feb 2023 08:15:32 +0100 Subject: [PATCH 3/3] Removed hannging debugging prints --- ontopy/ontodoc.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ontopy/ontodoc.py b/ontopy/ontodoc.py index 3f97ef22c..e14637e1c 100644 --- a/ontopy/ontodoc.py +++ b/ontopy/ontodoc.py @@ -392,28 +392,14 @@ def itemdoc( # Instances (individuals) if hasattr(item, "instances"): points = [] - for individual in item.instances(): - print("item", item, "is a", item.is_a) - print( - "individual", - individual, - "is instance of", - individual.is_instance_of, - ) - - # print(item.individual.is_instance_of) - for entity in [ _ for _ in item.instances() if item in _.is_instance_of ]: - print("entity", entity) - print("a", points) points.append( point_style.format( point=asstring(entity, link_style), ontology=onto ) ) - print("b", points) if points: value = points_style.format( points="".join(points), ontology=onto