@@ -92,16 +92,20 @@ class Rewrites(BaseModel):
9292 )
9393
9494 def remap_full (
95- self , str_or_curie_or_uri : str , cls : type [X ], * , ontology_prefix : str | None = None
95+ self ,
96+ str_or_curie_or_uri : str ,
97+ reference_cls : type [X ],
98+ * ,
99+ ontology_prefix : str | None = None ,
96100 ) -> X | None :
97101 """Remap the string if possible otherwise return it."""
98102 if ontology_prefix :
99103 resource_rewrites : dict [str , str ] = self .resource_full .get (ontology_prefix , {})
100104 if resource_rewrites and str_or_curie_or_uri in resource_rewrites :
101- return cls .from_curie (resource_rewrites [str_or_curie_or_uri ])
105+ return reference_cls .from_curie (resource_rewrites [str_or_curie_or_uri ])
102106
103107 if str_or_curie_or_uri in self .full :
104- return cls .from_curie (self .full [str_or_curie_or_uri ])
108+ return reference_cls .from_curie (self .full [str_or_curie_or_uri ])
105109
106110 return None
107111
@@ -146,11 +150,15 @@ def str_is_blacklisted(
146150 )
147151
148152 def remap_full (
149- self , str_or_curie_or_uri : str , cls : type [X ], * , ontology_prefix : str | None = None
153+ self ,
154+ str_or_curie_or_uri : str ,
155+ reference_cls : type [X ],
156+ * ,
157+ ontology_prefix : str | None = None ,
150158 ) -> X | None :
151159 """Remap the string if possible otherwise return it."""
152160 return self .rewrites .remap_full (
153- str_or_curie_or_uri , cls = cls , ontology_prefix = ontology_prefix
161+ str_or_curie_or_uri , reference_cls = reference_cls , ontology_prefix = ontology_prefix
154162 )
155163
156164 def remap_prefix (self , str_or_curie_or_uri : str , ontology_prefix : str | None = None ) -> str :
@@ -172,16 +180,23 @@ class BlacklistError(ValueError):
172180class PreprocessingConverter (Converter ):
173181 """A converter with pre-processing rules."""
174182
175- def __init__ (self , * args : Any , rules : Rules | str | Path , ** kwargs : Any ) -> None :
183+ def __init__ (
184+ self ,
185+ * args : Any ,
186+ rules : Rules | str | Path ,
187+ reference_cls : type [X ] | None = None ,
188+ ** kwargs : Any ,
189+ ) -> None :
176190 """Instantiate a converter with a ruleset for pre-processing.
177191
178192 :param args: Positional arguments passed to :func:`Converter.__init__`
179193 :param rules: A set of rules
194+ :param reference_cls: The reference class to use. Defaults to :class:`curies.Reference`.
180195 :param kwargs: Keyword arguments passed to :func:`Converter.__init__`
181196 """
182197 super ().__init__ (* args , ** kwargs )
183198 self .rules = _load_rules (rules )
184- self ._cls = Reference
199+ self ._reference_cls = Reference if reference_cls is None else reference_cls
185200
186201 @classmethod
187202 def from_converter (cls , converter : Converter , rules : Rules | str | Path ) -> Self :
@@ -211,7 +226,7 @@ def parse(
211226 ) -> ReferenceTuple | None :
212227 """Parse a string, CURIE, or URI."""
213228 if r1 := self .rules .remap_full (
214- str_or_uri_or_curie , cls = self ._cls , ontology_prefix = ontology_prefix
229+ str_or_uri_or_curie , reference_cls = self ._reference_cls , ontology_prefix = ontology_prefix
215230 ):
216231 return r1 .pair
217232
@@ -240,7 +255,9 @@ def parse_curie(
240255 def parse_curie ( # noqa:D102
241256 self , curie : str , * , strict : bool = False , ontology_prefix : str | None = None
242257 ) -> ReferenceTuple | None :
243- if r1 := self .rules .remap_full (curie , cls = self ._cls , ontology_prefix = ontology_prefix ):
258+ if r1 := self .rules .remap_full (
259+ curie , reference_cls = self ._reference_cls , ontology_prefix = ontology_prefix
260+ ):
244261 return r1 .pair
245262
246263 # Remap node's prefix (if necessary)
0 commit comments