From 8b9e6a30371d6522100c0404e80dc9838a7c120c Mon Sep 17 00:00:00 2001 From: Harshad Date: Wed, 13 Mar 2024 22:16:21 -0500 Subject: [PATCH] Made semsimian an optional dependency (#704) * Made semsimian an optional dependency * latest version of semsimian * Address semsimian being optional dependency * formatted * updated message * formatted * Use TYPE_CHECKING * roll back init * formatted * add sesmimian as dependency in tox * duplicate * add semsimian install * add semsimian install * edit semsimian install * undo semsimian install * fixed semsimian mystery * semsimian as a group not an extra * optional semsimian possible solution * formatted * formatted * formatted * updated gitignore * corrected branch diff madness * don't initialize it to be None * formatted * Should fix the gh action error thanks @justaddcoffee * update pip dependency * cleanup+formatted * semsimian as extra not group * formatted * formatted * formatted * formatted --- .github/workflows/main.yaml | 2 +- pyproject.toml | 3 ++- .../implementations/semsimian/semsimian_implementation.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0e1d8f676..4b0bd9ddf 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -88,7 +88,7 @@ jobs: # install your root project, if required #---------------------------------------------- - name: Install library - run: poetry install --no-interaction --extras "gilda" + run: poetry install --no-interaction --extras "gilda semsimian" - name: Get Gilda resources run: | diff --git a/pyproject.toml b/pyproject.toml index 89d676783..a0f1a3f07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ kgcl-schema = "^0.6.5" funowl = ">=0.2.0" gilda = {version = ">=1.0.0", optional = true} +semsimian = {version = ">=0.1.0", optional = true} kgcl-rdflib = "0.5.0" llm = {version = "*", optional = true} aiohttp = {version = "*", optional = true} @@ -37,7 +38,6 @@ pysolr = "^3.9.0" eutils = ">=0.6.0" requests-cache = "^1.0.1" click = "*" -semsimian = "^0.2.1" urllib3 = {version = "< 2", optional = true} pydantic = "*" jsonlines = "^4.0.0" @@ -75,6 +75,7 @@ docs = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-mermaid", "sphinx-copybutto gilda = ["scipy", "gilda", "urllib3"] llm = ["llm", "aiohttp"] seaborn = ["seaborn"] +semsimian = ["semsimian"] [tool.black] line-length = 100 diff --git a/src/oaklib/implementations/semsimian/semsimian_implementation.py b/src/oaklib/implementations/semsimian/semsimian_implementation.py index 9b17c8a01..df6ae970e 100644 --- a/src/oaklib/implementations/semsimian/semsimian_implementation.py +++ b/src/oaklib/implementations/semsimian/semsimian_implementation.py @@ -6,8 +6,6 @@ from dataclasses import dataclass, field from typing import ClassVar, Dict, Iterable, Iterator, List, Optional, Tuple, Union -from semsimian import Semsimian - from oaklib.datamodels.similarity import ( BestMatch, TermInfo, @@ -51,7 +49,7 @@ class SemSimianImplementation(SearchInterface, SemanticSimilarityInterface, OboG SemanticSimilarityInterface.information_content_scores, ] - semsimian_object_cache: Dict[Tuple[PRED_CURIE], Semsimian] = field(default_factory=dict) + semsimian_object_cache: Dict[Tuple[PRED_CURIE], Optional["Semsimian"]] = field(default_factory=dict) # type: ignore # noqa def __post_init__(self): slug = self.resource.slug @@ -81,13 +79,15 @@ def _get_semsimian_object( predicates: List[PRED_CURIE] = None, attributes: List[str] = None, resource_path: str = None, - ) -> Semsimian: + ) -> "Semsimian": # type: ignore # noqa """ Get Semsimian object from "semsimian_object_cache" or add a new one. :param predicates: collection of predicates, defaults to None :return: A Semsimian object. """ + from semsimian import Semsimian + predicates = tuple(sorted(predicates)) if predicates not in self.semsimian_object_cache: # spo = [