Skip to content

Commit 431fc08

Browse files
committed
Add URI example
1 parent 1d41e6b commit 431fc08

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

docs/source/preprocessing.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ OBO Foundry's PURL rules
5353
>>> converter.parse_curie("APOLLO:SV_1234567")
5454
ReferenceTuple('APOLLO_SV', '1234567')
5555
56+
The CURIE and URI rewrites are unified. Therefore, you can also use a URI as a rewrite,
57+
such as handling Creative Commons license URLs, which unfortunately aren't themselves
58+
part of a semantic space for licenses. Luckily, SPDX is, and we can remap to that.
59+
60+
.. code-block:: python
61+
62+
import curies
63+
from curies import PreprocessingRules, PreprocessingConverter, PreprocessingRewrites
64+
65+
rules = PreprocessingRules(
66+
rewrites=PreprocessingRewrites(
67+
full={"http://creativecommons.org/licenses/by/3.0/": "spdx:CC-BY-3.0",},
68+
)
69+
)
70+
71+
converter = curies.get_obo_converter()
72+
converter.add_prefix("spdx", "https://spdx.org/licenses/")
73+
converter = PreprocessingConverter.from_converter(
74+
converter, rules=rules,
75+
)
76+
77+
>>> converter.parse_uri("http://creativecommons.org/licenses/by/3.0/")
78+
ReferenceTuple('spdx', 'CC-BY-3.0')
79+
5680
Some rewrite rules only apply to a specific resource, because of its own quirks in
5781
curation or encoding. For example, CHMO encodes OrangeBook entries with ``orange`` as a
5882
prefix, which is not typically specific enough to warrant curating ``orange`` as a

src/curies/preprocessing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ def parse_uri(
367367
:param uri: The URI to parse and standardize
368368
:param strict: If the URI can't be parsed, should an error be thrown? Defaults
369369
to false.
370-
:param return_none: A dummy value, do not use. If given as False,
371-
will raise a not implemented error
370+
:param return_none: A dummy value, do not use. If given as False, will raise a
371+
not implemented error
372372
:param context: Is there a context, e.g., an ontology prefix that should be
373373
applied to the remapping and blocklist rules?
374374
:param block_action: What action should be taken when the blocklist is invoked?

tests/test_preprocessing.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def setUpClass(cls) -> None:
3939
"""Set up the test case."""
4040
cls.rules = PreprocessingRules(
4141
rewrites=PreprocessingRewrites(
42-
full={"is_a": "rdf:type"},
42+
full={
43+
"is_a": "rdf:type",
44+
"http://creativecommons.org/licenses/by/3.0/": "spdx:CC-BY-3.0",
45+
},
4346
prefix={
4447
"OMIM:PS": "omim.ps:",
4548
"omim:PS": "omim.ps:",
@@ -76,6 +79,7 @@ def setUpClass(cls) -> None:
7679
"omim": "https://omim.org/MIM:",
7780
"omim.ps": "https://omim.org/phenotypicSeries/PS",
7881
"pubmed": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
82+
"spdx": "https://spdx.org/licenses/",
7983
}
8084
)
8185

@@ -120,6 +124,10 @@ def test_global_full_rewrite(self) -> None:
120124
"""Test global full string rewrite."""
121125
self.assertEqual(ReferenceTuple("rdf", "type"), self.converter.parse("is_a"))
122126
self.assertEqual(ReferenceTuple("rdf", "type"), self.converter.parse_curie("is_a"))
127+
self.assertEqual(
128+
ReferenceTuple("spdx", "CC-BY-3.0"),
129+
self.converter.parse_uri("http://creativecommons.org/licenses/by/3.0/"),
130+
)
123131

124132
def test_global_prefix_rewrite(self) -> None:
125133
"""Test global prefix rewrite."""

0 commit comments

Comments
 (0)