Skip to content

Commit

Permalink
Reorganize documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jul 31, 2023
1 parent e72efd9 commit 87cbeb3
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 81 deletions.
44 changes: 44 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
API
---
.. automodapi:: curies
:no-inheritance-diagram:
:no-heading:

Integrating with :mod:`rdflib`
------------------------------
RDFlib is a pure Python package for manipulating RDF data. The following example shows how to bind the
prefix map from a :class:`curies.Converter` to a graph (:class:`rdflib.Graph`).

.. code-block::
import curies, rdflib, rdflib.namespace
converter = curies.get_obo_converter()
graph = rdflib.Graph()
for prefix, uri_prefix in converter.prefix_map.items():
graph.bind(prefix, rdflib.Namespace(uri_prefix))
A more flexible approach is to instantiate a namespace manager (:class:`rdflib.namespace.NamespaceManager`)
and bind directly to that.

.. code-block::
import curies, rdflib
converter = curies.get_obo_converter()
namespace_manager = rdflib.namespace.NamespaceManager(rdflib.Graph())
for prefix, uri_prefix in converter.prefix_map.items():
namespace_manager.bind(prefix, rdflib.Namespace(uri_prefix))
URI references for use in RDFLib's graph class can be constructed from
CURIEs using a combination of :meth:`curies.Converter.expand` and :class:`rdflib.URIRef`.

.. code-block::
import curies, rdflib
converter = curies.get_obo_converter()
uri_ref = rdflib.URIRef(converter.expand("CHEBI:138488"))
3 changes: 3 additions & 0 deletions docs/source/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLI Usage
---------
.. automodule:: curies.cli
82 changes: 9 additions & 73 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,76 +15,12 @@ The most recent code and data can be installed directly from GitHub with:
$ pip install git+https://github.com/cthoyt/curies.git
.. automodapi:: curies
:no-inheritance-diagram:

CLI Usage
---------
.. automodule:: curies.cli

Integrating with :mod:`rdflib`
------------------------------
RDFlib is a pure Python package for manipulating RDF data. The following example shows how to bind the
prefix map from a :class:`curies.Converter` to a graph (:class:`rdflib.Graph`).

.. code-block::
import curies, rdflib, rdflib.namespace
converter = curies.get_obo_converter()
graph = rdflib.Graph()
for prefix, uri_prefix in converter.prefix_map.items():
graph.bind(prefix, rdflib.Namespace(uri_prefix))
A more flexible approach is to instantiate a namespace manager (:class:`rdflib.namespace.NamespaceManager`)
and bind directly to that.

.. code-block::
import curies, rdflib
converter = curies.get_obo_converter()
namespace_manager = rdflib.namespace.NamespaceManager(rdflib.Graph())
for prefix, uri_prefix in converter.prefix_map.items():
namespace_manager.bind(prefix, rdflib.Namespace(uri_prefix))
URI references for use in RDFLib's graph class can be constructed from
CURIEs using a combination of :meth:`curies.Converter.expand` and :class:`rdflib.URIRef`.

.. code-block::
import curies, rdflib
converter = curies.get_obo_converter()
uri_ref = rdflib.URIRef(converter.expand("CHEBI:138488"))
Incremental Converters
----------------------
As suggested in `#13 <https://github.com/cthoyt/curies/issues/33>`_, new prefixes
can be added to an existing converter like in the following:

.. code-block::
import curies
converter = curies.get_obo_converter()
converter.add_prefix("hgnc", "https://bioregistry.io/hgnc:")
Similarly, an empty converter can be instantiated using an empty list
for the `records` argument and prefixes can be added one at a time
(note this currently does not allow for adding synonyms separately):

.. code-block::
import curies
converter = curies.Converter(records=[])
converter.add_prefix("hgnc", "https://bioregistry.io/hgnc:")
Identifier Mapping Service
--------------------------
.. automodapi:: curies.mapping_service
:no-inheritance-diagram:
.. toctree::
:maxdepth: 2
:caption: Contents:

struct
api
resolver_service
mapping_service
cli
5 changes: 5 additions & 0 deletions docs/source/mapping_service.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Identifier Mapping Service
--------------------------
.. automodapi:: curies.mapping_service
:no-inheritance-diagram:
:no-heading:
5 changes: 5 additions & 0 deletions docs/source/resolver_service.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Resolver Service
----------------
.. automodapi:: curies.resolver_service
:no-inheritance-diagram:
:no-heading:
2 changes: 2 additions & 0 deletions docs/source/struct.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Data Structures
===============
6 changes: 0 additions & 6 deletions src/curies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
get_prefixcommons_converter,
)
from .version import get_version
from .web import get_fastapi_app, get_fastapi_router, get_flask_app, get_flask_blueprint

__all__ = [
"Converter",
Expand All @@ -38,9 +37,4 @@
"get_monarch_converter",
"get_go_converter",
"get_bioregistry_converter",
# Web extras
"get_flask_blueprint",
"get_flask_app",
"get_fastapi_router",
"get_fastapi_app",
]
23 changes: 23 additions & 0 deletions src/curies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ class Converter:
# Example with missing prefix:
>>> converter.expand("missing:0000000")
Incremental Converters
----------------------
As suggested in `#13 <https://github.com/cthoyt/curies/issues/33>`_, new prefixes
can be added to an existing converter like in the following:
.. code-block::
import curies
converter = curies.get_obo_converter()
converter.add_prefix("hgnc", "https://bioregistry.io/hgnc:")
Similarly, an empty converter can be instantiated using an empty list
for the `records` argument and prefixes can be added one at a time
(note this currently does not allow for adding synonyms separately):
.. code-block::
import curies
converter = curies.Converter(records=[])
converter.add_prefix("hgnc", "https://bioregistry.io/hgnc:")
"""

#: The expansion dictionary with prefixes as keys and priority URI prefixes as values
Expand Down
6 changes: 4 additions & 2 deletions src/curies/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ def _get_converter(location, format) -> Converter:


def _get_resolver_app(converter: Converter, framework: str):
from curies import resolver_service

if framework == "flask":
return curies.get_flask_app(converter)
return resolver_service.get_flask_app(converter)
elif framework == "fastapi":
return curies.get_fastapi_app(converter)
return resolver_service.get_fastapi_app(converter)
else:
raise ValueError(f"Unhandled framework: {framework}")

Expand Down
File renamed without changes.

0 comments on commit 87cbeb3

Please sign in to comment.