Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.entities() typedef update #688

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update

This is a minor update. I just happened to notice that while I was using this for SqlImplementation, I was getting back URIs sometimes. I assume this should always be a possible thing for the other implementations as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joeflack4 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatives?

LinkML has URIorCURIE but I don't know if it's something that should be used here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No The URI and CURIE definition are oaklib specific. So the sis correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of types?

This is a super minor thing, but I am going to guess that if there is a Python convention, maybe it should be Union[CURIE, URI] for alphabetical reasons, but I hose Union[URI, CURIE] because that's usually the order we speak them in the semantic web world.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not matter.

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