From 0edf0be182ab4afada457ea4bbce68d9c857eeb2 Mon Sep 17 00:00:00 2001 From: francescalb Date: Fri, 10 Dec 2021 10:52:45 +0100 Subject: [PATCH 1/4] Added sconverting Posix to str in get_ontology --- ontopy/ontology.py | 11 +++++++++-- tests/test_load.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index c2cc6bc00..3ab6d7230 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -16,6 +16,7 @@ import uuid import tempfile import types +import pathlib from typing import Union from collections import defaultdict from collections.abc import Iterable @@ -82,6 +83,12 @@ def get_ontology(self, base_iri="emmo-inferred"): - "emmo-development": load latest inferred development version of EMMO """ + base_iri = ( + str(base_iri) + if isinstance(base_iri, pathlib.PosixPath) + else base_iri + ) + if base_iri == "emmo": base_iri = ( "https://raw.githubusercontent.com/emmo-repo/" @@ -1281,10 +1288,10 @@ def new_entity( ) parents = tuple(parent) if isinstance(parent, Iterable) else (parent,) for thing in parents: - if not isinstance(thing, owlready2.ThingClass): + if not isinstance(thing, owlready2.entity.ThingClass): raise ThingClassDefinitionError( f"Error in parent definition: " - f"'{thing}' is not an owlready2.ThingClass." + f"'{thing}' is not an owlready2.entity.ThingClass." ) with self: diff --git a/tests/test_load.py b/tests/test_load.py index 4095e4bd1..7570becb1 100755 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -24,7 +24,8 @@ def test_load(repo_dir: "Path") -> None: # Load a local ontology with catalog testonto = repo_dir / "tests" / "testonto" / "testonto.ttl" - onto = get_ontology(str(testonto)).load() + print(type(testonto)) + onto = get_ontology(testonto).load() assert onto.TestClass.prefLabel.first() == "TestClass" # Use catalog file when downloading from web From f7d7733171676a0cab5fd939ddeca4094673a62f Mon Sep 17 00:00:00 2001 From: francescalb Date: Fri, 10 Dec 2021 10:56:58 +0100 Subject: [PATCH 2/4] Removed erroneously added change --- ontopy/ontology.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 3ab6d7230..f416d0732 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -1288,10 +1288,10 @@ def new_entity( ) parents = tuple(parent) if isinstance(parent, Iterable) else (parent,) for thing in parents: - if not isinstance(thing, owlready2.entity.ThingClass): + if not isinstance(thing, owlready2.ThingClass): raise ThingClassDefinitionError( f"Error in parent definition: " - f"'{thing}' is not an owlready2.entity.ThingClass." + f"'{thing}' is not an owlready2.ThingClass." ) with self: From e6aa039794614144585a213f9695dcfb8e8ab7be Mon Sep 17 00:00:00 2001 From: francescalb Date: Fri, 10 Dec 2021 10:58:11 +0100 Subject: [PATCH 3/4] Removed print in test --- tests/test_load.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_load.py b/tests/test_load.py index 7570becb1..d18ff60df 100755 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -24,7 +24,6 @@ def test_load(repo_dir: "Path") -> None: # Load a local ontology with catalog testonto = repo_dir / "tests" / "testonto" / "testonto.ttl" - print(type(testonto)) onto = get_ontology(testonto).load() assert onto.TestClass.prefLabel.first() == "TestClass" From 4fbe43cb5f88c05c9566721573eb06507a94a86e Mon Sep 17 00:00:00 2001 From: francescalb Date: Fri, 10 Dec 2021 11:36:48 +0100 Subject: [PATCH 4/4] Changed base_iri to be pathlib.Path and cast to as_uri --- ontopy/ontology.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index f416d0732..6c55f7482 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -84,8 +84,8 @@ def get_ontology(self, base_iri="emmo-inferred"): of EMMO """ base_iri = ( - str(base_iri) - if isinstance(base_iri, pathlib.PosixPath) + base_iri.as_uri() + if isinstance(base_iri, pathlib.Path) else base_iri )