1010from curies import NamableReference
1111
1212__all__ = [
13- "from_records" ,
1413 "from_tsv" ,
14+ "iter_records" ,
1515]
1616
1717Model = TypeVar ("Model" , bound = BaseModel )
@@ -28,7 +28,6 @@ def from_tsv(
2828 A mapping from column names corresponding to reference fields to column names representing the labels
2929 :yields: Validated models
3030
31-
3231 Let's use a similar table, now with the prefix and identifier combine into CURIEs.
3332
3433 =========== ======== ======
@@ -39,22 +38,14 @@ def from_tsv(
3938 CHEBI:44884 pentanol CCCCCO
4039 =========== ======== ======
4140
42- Note that there's a typo in the prefix on the fourth row in the prefix because it uses
43- ``CHOBI`` instead of ``CHEBI``. In the following code, we simulate reading that file and
44- show where the error shows up:
41+ In the following code, we simulate reading that file and show where the error shows up:
4542
4643 .. code-block:: python
4744
48- import csv
49- from pydantic import BaseModel, ValidationError
50- from curies import Converter, NamedReference
51- from curies.metamodel import from_records
45+ from pydantic import BaseModel
5246
53- converter = Converter.from_prefix_map(
54- {
55- "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
56- }
57- )
47+ from curies import NamedReference
48+ from curies.metamodel import iter_records
5849
5950
6051 class Row(BaseModel):
@@ -68,16 +59,17 @@ class Row(BaseModel):
6859 {"curie": "CHEBI:44884", "name": "pentanol", "smiles": "CCCCCO"},
6960 ]
7061
71- models = list(from_records (records, Row, names={"curie": "name"}))
62+ models = list(iter_records (records, Row, names={"curie": "name"}))
7263 print(models)
7364
7465 """
75- with open (path ) as file :
66+ path = Path (path ).expanduser ().resolve ()
67+ with path .open () as file :
7668 reader = csv .DictReader (file , delimiter = "\t " )
77- yield from from_records (reader , cls , names = names )
69+ yield from iter_records (reader , cls , names = names )
7870
7971
80- def from_records (
72+ def iter_records (
8173 records : Iterable [dict [str , Any ]], cls : type [Model ], names : dict [str , str ] | None = None
8274) -> Iterable [Model ]:
8375 """Get records."""
0 commit comments