Skip to content

Commit 957ca5f

Browse files
committed
Rename and start docs
1 parent e58cc63 commit 957ca5f

6 files changed

Lines changed: 27 additions & 10 deletions

File tree

docs/source/api.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ API Reference
22
=============
33

44
.. automodapi:: curies
5-
:no-inheritance-diagram:
65
:no-heading:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Converter with Preprocessing
2+
============================
3+
4+
When simple expansion and contraction aren't enough, and you want to
5+
inject global or context-specific rewrite rules, you can wrap a :class:`curies.Converter`
6+
and preprocessing rules encoded in an instance of :class:`curies.PreprocessingRules` inside
7+
a :class:`curies.PreprocessingConverter`.
8+

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ The most recent code and data can be installed directly from GitHub with:
6868
services/index
6969
typing
7070
w3c
71+
converter_with_preprocessing

src/curies/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
)
3636
from .triples import Triple
3737
from .version import get_version
38+
from .wrapped import PreprocessingConverter, PreprocessingRules
3839

3940
__all__ = [
4041
"Converter",
@@ -45,6 +46,8 @@
4546
"NamedReference",
4647
"Prefix",
4748
"PrefixMap",
49+
"PreprocessingConverter",
50+
"PreprocessingRules",
4851
"Record",
4952
"Records",
5053
"Reference",

src/curies/wrapped.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"Blacklist",
1616
"BlacklistError",
1717
"PreprocessingConverter",
18+
"PreprocessingRules",
1819
"Rewrites",
19-
"Rules",
2020
]
2121

2222
X = TypeVar("X", bound=Reference)
@@ -121,7 +121,7 @@ def remap_prefix(self, str_or_curie_or_uri: str, ontology_prefix: str | None = N
121121
return str_or_curie_or_uri
122122

123123

124-
class Rules(BaseModel):
124+
class PreprocessingRules(BaseModel):
125125
"""A model for blacklists and rewrites."""
126126

127127
blacklists: Blacklist
@@ -166,10 +166,10 @@ def remap_prefix(self, str_or_curie_or_uri: str, ontology_prefix: str | None = N
166166
return self.rewrites.remap_prefix(str_or_curie_or_uri, ontology_prefix=ontology_prefix)
167167

168168

169-
def _load_rules(rules: str | Path | Rules) -> Rules:
169+
def _load_rules(rules: str | Path | PreprocessingRules) -> PreprocessingRules:
170170
if isinstance(rules, (str, Path)):
171171
rules = Path(rules).expanduser().resolve()
172-
rules = Rules.model_validate_json(rules.read_text())
172+
rules = PreprocessingRules.model_validate_json(rules.read_text())
173173
return rules
174174

175175

@@ -183,7 +183,7 @@ class PreprocessingConverter(Converter):
183183
def __init__(
184184
self,
185185
*args: Any,
186-
rules: Rules | str | Path,
186+
rules: PreprocessingRules | str | Path,
187187
reference_cls: type[X] | None = None,
188188
**kwargs: Any,
189189
) -> None:
@@ -199,7 +199,7 @@ def __init__(
199199
self._reference_cls = Reference if reference_cls is None else reference_cls
200200

201201
@classmethod
202-
def from_converter(cls, converter: Converter, rules: Rules | str | Path) -> Self:
202+
def from_converter(cls, converter: Converter, rules: PreprocessingRules | str | Path) -> Self:
203203
"""Wrap a converter with a ruleset."""
204204
return cls(records=converter.records, rules=rules)
205205

tests/test_wrapped.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
from typing import ClassVar
99

1010
from curies import Converter, ReferenceTuple
11-
from curies.wrapped import Blacklist, BlacklistError, PreprocessingConverter, Rewrites, Rules
11+
from curies.wrapped import (
12+
Blacklist,
13+
BlacklistError,
14+
PreprocessingConverter,
15+
PreprocessingRules,
16+
Rewrites,
17+
)
1218

1319
EX1_RT = ReferenceTuple("GO", "1234567")
1420
EX1_URI = "http://purl.obolibrary.org/obo/GO_1234567"
@@ -21,7 +27,7 @@
2127
class TestWrapped(unittest.TestCase):
2228
"""Tests for preprocessing converter."""
2329

24-
rules: ClassVar[Rules]
30+
rules: ClassVar[PreprocessingRules]
2531
inner_converter: ClassVar[Converter]
2632
converter: ClassVar[PreprocessingConverter]
2733
temporary_directory: ClassVar[tempfile.TemporaryDirectory[str]]
@@ -31,7 +37,7 @@ class TestWrapped(unittest.TestCase):
3137
@classmethod
3238
def setUpClass(cls) -> None:
3339
"""Set up the test case."""
34-
cls.rules = Rules(
40+
cls.rules = PreprocessingRules(
3541
rewrites=Rewrites(
3642
full={"is_a": "rdf:type"},
3743
prefix={

0 commit comments

Comments
 (0)