Skip to content

Commit

Permalink
- Update: Type definition for entities() method type definitions. Was…
Browse files Browse the repository at this point in the history
… previously just Iterable[CURIE], but it is also possible for it to return URIs.
  • Loading branch information
joeflack4 committed Dec 12, 2023
1 parent 09bf298 commit 7e667d8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/oaklib/implementations/funowl/funowl_implementation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from dataclasses import dataclass
from typing import Any, Iterable, List, Mapping, Optional
from typing import Any, Iterable, List, Mapping, Optional, Union

import rdflib
from funowl import (
Expand All @@ -27,7 +27,7 @@
from oaklib.interfaces.basic_ontology_interface import LANGUAGE_TAG
from oaklib.interfaces.owl_interface import OwlInterface, ReasonerConfiguration
from oaklib.interfaces.patcher_interface import PatcherInterface
from oaklib.types import CURIE, PRED_CURIE
from oaklib.types import CURIE, PRED_CURIE, URI


@dataclass
Expand Down Expand Up @@ -97,7 +97,7 @@ def label(self, curie: CURIE, lang: Optional[LANGUAGE_TAG] = None) -> str:
else:
raise ValueError(f"Label must be literal, not {label}")

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
for ax in self._ontology.axioms:
if isinstance(ax, Declaration):
uri = ax.v.full_uri(self.functional_writer.g)
Expand Down
6 changes: 3 additions & 3 deletions src/oaklib/implementations/kgx/kgx_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import defaultdict
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Type
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union

import rdflib
import sqlalchemy.orm
Expand Down Expand Up @@ -63,7 +63,7 @@
from oaklib.interfaces.semsim_interface import SemanticSimilarityInterface
from oaklib.interfaces.summary_statistics_interface import SummaryStatisticsInterface
from oaklib.interfaces.validator_interface import ValidatorInterface
from oaklib.types import CATEGORY_CURIE, CURIE, SUBSET_CURIE
from oaklib.types import CATEGORY_CURIE, CURIE, SUBSET_CURIE, URI
from oaklib.utilities.identifier_utils import synonym_type_code_from_curie
from oaklib.utilities.iterator_utils import chunk

Expand Down Expand Up @@ -347,7 +347,7 @@ def is_postgres(self):
# TODO
return False

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
q = self.session.query(Node.id)
logging.debug(f"Entities Query: {q}")
for row in q:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _all_relationships(self) -> Iterator[RELATIONSHIP]:
# directionality is lost in OboGraph representation
yield self._tuple_to_curies((n1, EQUIVALENT_CLASS, n2))

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
od = self.obograph_document
for g in od.graphs:
for n in g.nodes:
Expand Down
4 changes: 2 additions & 2 deletions src/oaklib/implementations/pronto/pronto_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
from oaklib.interfaces.taxon_constraint_interface import TaxonConstraintInterface
from oaklib.interfaces.validator_interface import ValidatorInterface
from oaklib.resource import OntologyResource
from oaklib.types import CURIE, SUBSET_CURIE
from oaklib.types import CURIE, SUBSET_CURIE, URI
from oaklib.utilities.axioms.logical_definition_utilities import (
logical_definition_matches,
)
Expand Down Expand Up @@ -293,7 +293,7 @@ def _create_pred(self, curie: CURIE, exist_ok=True):
else:
return self.wrapped_ontology.create_relationship(curie)

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
for t in self.wrapped_ontology.terms():
if filter_obsoletes and t.obsolete:
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
from oaklib.interfaces.taxon_constraint_interface import TaxonConstraintInterface
from oaklib.interfaces.validator_interface import ValidatorInterface
from oaklib.resource import OntologyResource
from oaklib.types import CURIE, PRED_CURIE, SUBSET_CURIE
from oaklib.types import CURIE, PRED_CURIE, SUBSET_CURIE, URI
from oaklib.utilities.axioms.logical_definition_utilities import (
logical_definition_matches,
)
Expand Down Expand Up @@ -255,7 +255,7 @@ def _all_entailed_relationships(self):
reasoner = RelationGraphReasoner(self)
yield from reasoner.entailed_edges()

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
od = self.obo_document
for s_id, s in od.stanzas.items():
if filter_obsoletes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def uri_to_curie(self, uri: URI, strict=True) -> Optional[CURIE]:
return uri.replace("_", ":")
return uri

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
query = SparqlQuery(select=["?s"], distinct=True, where=["?s a ?cls", "FILTER (isIRI(?s))"])
if owl_type:
query.where.append(f"?s a {self.curie_to_sparql(owl_type)}")
Expand Down
4 changes: 2 additions & 2 deletions src/oaklib/implementations/sqldb/sql_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
from oaklib.interfaces.summary_statistics_interface import SummaryStatisticsInterface
from oaklib.interfaces.taxon_constraint_interface import TaxonConstraintInterface
from oaklib.interfaces.validator_interface import ValidatorInterface
from oaklib.types import CATEGORY_CURIE, CURIE, SUBSET_CURIE
from oaklib.types import CATEGORY_CURIE, CURIE, SUBSET_CURIE, URI
from oaklib.utilities.axioms.logical_definition_utilities import (
logical_definition_matches,
)
Expand Down Expand Up @@ -407,7 +407,7 @@ def languages(self) -> Iterable[LANGUAGE_TAG]:
if row.language:
yield row.language

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
# TODO: figure out how to pass through ESCAPE at SQL Alchemy level
# s = text('SELECT id FROM class_node WHERE id NOT LIKE "\_:%" ESCAPE "\\"') # noqa W605
q = self.session.query(Node)
Expand Down
2 changes: 1 addition & 1 deletion src/oaklib/interfaces/basic_ontology_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def ontology_metadata_map(self, ontology: CURIE) -> METADATA_MAP:
f"ontology_metadata_map() method not implemented for {self.__class__.__name__}"
)

def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[CURIE]:
def entities(self, filter_obsoletes=True, owl_type=None) -> Iterable[Union[URI, CURIE]]:
"""
Yields all known entity CURIEs.
Expand Down

0 comments on commit 7e667d8

Please sign in to comment.