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

merge V0.1.3 onto main #5

Merged
merged 2 commits into from
Sep 3, 2024
Merged
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.1.3 (2024-09-03)
---------------------------
* Separate rapidfuzz dependency into optional [search] extra


Version 0.1.2 (2024-09-02)
---------------------------
* Added JSON-LD serialization support
Expand Down
11 changes: 7 additions & 4 deletions docker/ubuntu2204-install/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM ubuntu:22.04

# define package version
ARG SOLI_VERSION=0.1.3

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -20,11 +23,11 @@ RUN python3 -m venv /app/.venv
# install pytest into it
RUN /app/.venv/bin/pip install pytest pytest-benchmark

# copy the target/wheels/*.whl files
COPY dist/*.whl /app
# copy the SOLI_VERSION wheel:
COPY dist/soli_python-${SOLI_VERSION}-py3-none-any.whl /app/

# install the wheels
RUN /app/.venv/bin/pip install /app/*.whl
# install the wheels with extra 'search'
RUN /app/.venv/bin/pip install /app/soli_python-${SOLI_VERSION}-py3-none-any.whl[search]

# copy the tests directory
COPY tests /app/tests
Expand Down
11 changes: 7 additions & 4 deletions docker/ubuntu2404-install/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM ubuntu:24.04

# define package version
ARG SOLI_VERSION=0.1.3

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -20,11 +23,11 @@ RUN python3 -m venv /app/.venv
# install pytest into it
RUN /app/.venv/bin/pip install pytest pytest-benchmark

# copy the target/wheels/*.whl files
COPY dist/*.whl /app
# copy the SOLI_VERSION wheel:
COPY dist/soli_python-${SOLI_VERSION}-py3-none-any.whl /app/

# install the wheels
RUN /app/.venv/bin/pip install /app/*.whl
# install the wheels with extra 'search'
RUN /app/.venv/bin/pip install /app/soli_python-${SOLI_VERSION}-py3-none-any.whl[search]

# copy the tests directory
COPY tests /app/tests
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
project = "soli-python"
copyright = "2024, ALEA Institute"
author = "ALEA Institute (https://aleainstitute.ai)"
release = "0.1.2"
version = "0.1.2"
release = "0.1.3"
version = "0.1.3"
master_doc = "index"
language = "en"

Expand Down Expand Up @@ -67,7 +67,7 @@
"use_sidenotes": True,
"collapse_navbar": True,
"show_navbar_depth": 2,
"repository_url": "https://github.com/alea-institute/soli-api",
"repository_url": "https://github.com/alea-institute/soli-python",
"repository_branch": "main",
"path_to_docs": "sphinx",
"use_issues_button": True,
Expand Down
3 changes: 3 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ print(f"First class: {first_class.label}")

### Search by Label

**Make sure that you have installed with the `[search]` extra to use the search functionality. See the [installation instructions](index.md#search-extras).**


```python
# Search for classes with "SDNY" in the label
results = soli.search_by_label("SDNY", limit=3)
Expand Down
12 changes: 11 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ pip install --upgrade https://github.com/alea-institute/soli-python/archive/refs
pip install soli-python
```

#### Search Extras

**If you want to use the basic search functionality to run fuzzy searches on labels or definitions,
you should install the library with the `[search]` extra:**

```bash
pip install soli-python[search]
```




## Getting Started
Expand Down Expand Up @@ -179,7 +189,7 @@ For detailed information about the SOLI Python library API, please refer to the

## Contributing

Contributions to the SOLI Python library are welcome! Please see our [contribution guidelines](contributing.md) for more information. You can also contribute to the SOLI standard itself through the [SOLI GitHub repository](https://github.com/alea-institute/soli-api).
Contributions to the SOLI Python library are welcome! Please see our [contribution guidelines](contributing.md) for more information. You can also contribute to the SOLI standard itself through the [SOLI GitHub repository](https://github.com/alea-institute/soli-python).

## License

Expand Down
223 changes: 113 additions & 110 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "soli-python"
version = "0.1.2"
version = "0.1.3"
description = "Python library for SOLI, the Standard for Open Legal Information"
authors = ["ALEA Institute <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -39,7 +39,7 @@ python = ">=3.10,<4.0.0"
pydantic = "^2.8.2"
lxml = "^5.2.2"
httpx = "^0.27.2"
rapidfuzz = "^3.9.6"
rapidfuzz = {version = "^3.9.7", optional = true}

[tool.poetry.group.dev.dependencies]
types-lxml = "^2024.8.7"
Expand All @@ -57,6 +57,14 @@ sphinx-copybutton = "^0.5.2"
sphinxext-opengraph = "^0.9.1"
sphinx-plausible = "^0.1.2"

[tool.poetry.group.search.dependencies]
rapidfuzz = "^3.9.7"

# extras
[tool.poetry.extras]
search = ["rapidfuzz"]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
2 changes: 1 addition & 1 deletion soli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: MIT
# (c) 2024 ALEA Institute.

__version__ = "0.1.2"
__version__ = "0.1.3"
__author__ = "ALEA Institute"
__license__ = "MIT"
__description__ = "Python library for SOLI, the Standard for Open Legal Information"
Expand Down
26 changes: 25 additions & 1 deletion soli/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# imports
import base64
import hashlib
import importlib.util
import time
import uuid
from enum import Enum
Expand All @@ -24,7 +25,6 @@
# packages
import httpx
import lxml.etree
import rapidfuzz

# project imports
from soli.config import (
Expand Down Expand Up @@ -114,6 +114,18 @@ class SOLITypes(Enum):
LOGGER = get_logger(__name__)


# try to import rapidfuzz with importlib; log if not able to.
try:
if importlib.util.find_spec("rapidfuzz") is not None:
import rapidfuzz
else:
LOGGER.warning("Disabling search functionality: rapidfuzz not found.")
rapidfuzz = None
except ImportError as e:
LOGGER.warning("Failed to check for search functionality: %s", e)
rapidfuzz = None


# pylint: disable=too-many-instance-attributes
class SOLI:
"""
Expand Down Expand Up @@ -1028,6 +1040,12 @@ def search_by_label(
List[Tuple[OWLClass, int | float]]: The list of search results with
the OWL class and the search score.
"""
# check if we can search
if rapidfuzz is None:
raise RuntimeError(
"search extra must be installed to use search functions: pip install soli-python[search]"
)

# get search labels
if not include_alt_labels:
search_labels = tuple(self.label_to_index.keys())
Expand Down Expand Up @@ -1069,6 +1087,12 @@ def search_by_definition(
List[Tuple[OWLClass, int | float]]: The list of search results with
the OWL class and the search score.
"""
# check if we can search
if rapidfuzz is None:
raise RuntimeError(
"search extra must be installed to use search functions: pip install soli-python[search]"
)

# get definitions to search with zip pattern
class_index, class_definitions = zip(
*[
Expand Down