diff --git a/.gitignore b/.gitignore index 8dcbd14..7dc6caf 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ target/ #Ipython Notebook .ipynb_checkpoints + +.DS_Store diff --git a/README.md b/README.md index 29e4e32..897aa73 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,6 @@ If you just want `reach`: pip install reach ``` -If you also want [`AutoReach`](#autoreach): - -``` -pip install reach[auto] -``` - ## Example ```python diff --git a/docs/Makefile b/docs/Makefile index f41cc07..d4bb2cb 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,10 +1,10 @@ # Minimal makefile for Sphinx documentation # -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SPHINXPROJ = reach +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build SOURCEDIR = . BUILDDIR = _build diff --git a/docs/conf.py b/docs/conf.py index 3bfc627..1e6097e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,114 +1,37 @@ -# -*- coding: utf-8 -*- -# -# Configuration file for the Sphinx documentation builder. -# -# This file does only contain a selection of the most common options. For a -# full list see the documentation: -# http://www.sphinx-doc.org/en/master/config - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# import os import sys -sys.path.insert(0, os.path.abspath("../")) +sys.path.insert(0, os.path.abspath(".")) +sys.path.insert(0, os.path.abspath("..")) +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = "reach" -copyright = "2023, Stéphan Tulkens" +copyright = "2024, Stéphan Tulkens" author = "Stéphan Tulkens" - -# The short X.Y version -version = "4.1.0" -# The full version, including alpha/beta/rc tags -release = "4.1.0" - +release = "5.0.0" # -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. extensions = [ - "sphinx.ext.autodoc", "sphinx.ext.napoleon", ] -# Add any paths that contain templates here, relative to this directory. +napoleon_google_docstring = False +napoleon_use_param = False +napoleon_use_ivar = True templates_path = ["_templates"] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# -# source_suffix = ['.rst', '.md'] -source_suffix = ".rst" - -# The master toctree document. -master_doc = "index" - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = "en" - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path . exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - # -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = "sphinx_rtd_theme" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -# html_theme_options = {} - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -# html_static_path = ['_static'] - -# Custom sidebar templates, must be a dictionary that maps document names -# to template names. -# -# The default sidebars (for documents that don't match any pattern) are -# defined by theme itself. Builtin themes are using these templates by -# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', -# 'searchbox.html']``. -# -# html_sidebars = {} - - -# -- Options for HTMLHelp output --------------------------------------------- - -# Output file base name for HTML help builder. -htmlhelp_basename = "reachdoc" - -# -- Extension configuration ------------------------------------------------- - -# Napoleon settings -# napoleon_include_init_with_doc = True - -# autodoc -autodoc_member_order = "bysource" +html_theme = "alabaster" +html_static_path = ["_static"] diff --git a/docs/index.rst b/docs/index.rst index ed0aed1..96eb377 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,3 +1,8 @@ +.. reach documentation master file, created by + sphinx-quickstart on Sun Jul 14 20:50:46 2024. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + `reach `_ documentation =================================================================== @@ -26,15 +31,6 @@ If you just want reach: $ pip install reach - -If you also want AutoReach: - - -:: - - $ pip install reach[auto] - - Contents -------- diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index a86dc24..0000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -urllib3==1.26.19 -numpy -pyahocorasick -tqdm diff --git a/docs/source/api.rst b/docs/source/api.rst index 8c34897..0f45541 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -10,11 +10,3 @@ Reach .. autoclass:: reach.Reach :members: :undoc-members: - - -AutoReach -------------------------- - -.. autoclass:: reach.AutoReach - :members: - :undoc-members: diff --git a/reach/__init__.py b/reach/__init__.py index 9385034..f0147a4 100644 --- a/reach/__init__.py +++ b/reach/__init__.py @@ -2,11 +2,5 @@ from reach.reach import Reach, normalize -try: - from reach.autoreach import AutoReach # noqa - - __all__ = ["Reach", "normalize", "AutoReach"] -except ImportError: - __all__ = ["Reach", "normalize"] - +__all__ = ["Reach", "normalize"] __version__ = "4.1.1" diff --git a/reach/reach.py b/reach/reach.py index 679e61a..5f89ebf 100644 --- a/reach/reach.py +++ b/reach/reach.py @@ -54,6 +54,7 @@ def __init__( vectors: Matrix, items: list[str], name: str = "", + metadata: dict[str, Any] | None = None, ) -> None: """Initialize a Reach instance with an array and list of items.""" if len(items) != len(vectors): @@ -75,6 +76,7 @@ def __init__( self.name = name self._unk_token: str | None = None self._unk_index: int | None = None + self.metadata = metadata or {} @property def unk_token(self) -> str | None: @@ -972,7 +974,6 @@ def save_fast_format( self, path: PathLike, overwrite: bool = False, - additional_metadata: dict[str, str] | None = None, ) -> None: """ Save a reach instance in a fast format. @@ -1007,8 +1008,7 @@ def save_fast_format( "unk_token": self.unk_token, "name": self.name, } - if additional_metadata is not None: - metadata.update(additional_metadata) + metadata.update(self.metadata) items = self.sorted_items items_dict = { @@ -1045,9 +1045,9 @@ def load_fast_format( data: dict[str, Any] = json.load(file_handle) items: list[str] = data["items"] - metadata: dict[str, Any] = data.get("metadata", {}) - unk_token = metadata.get("unk_token") - name = metadata.get("name", "") + metadata: dict[str, Any] = data["metadata"] + unk_token = metadata.pop("unk_token") + name = metadata.pop("name") numpy_path = filename_path.parent / Path(data["vectors_path"]) if not numpy_path.exists(): @@ -1056,7 +1056,7 @@ def load_fast_format( with open(numpy_path, "rb") as file_handle: vectors: npt.NDArray = np.load(file_handle) vectors = vectors.astype(desired_dtype) - instance = cls(vectors, items, name=name) + instance = cls(vectors, items, name=name, metadata=metadata) instance.unk_token = unk_token return instance