@@ -72,6 +72,12 @@ def str_is_blocked(self, str_or_curie_or_uri: str, *, context: str | None = None
7272 )
7373
7474
75+ class Postprocessing (BaseModel ):
76+ """A model for post-processing based on the prefix parsed."""
77+
78+ suffix : dict [str , str ] = Field (default_factory = dict )
79+
80+
7581class PreprocessingRewrites (BaseModel ):
7682 """A model for prefix and full rewrites."""
7783
@@ -123,6 +129,7 @@ class PreprocessingRules(BaseModel):
123129
124130 blocklists : PreprocessingBlocklists
125131 rewrites : PreprocessingRewrites
132+ postprocessing : Postprocessing = Field (default_factory = Postprocessing )
126133
127134 @classmethod
128135 def lint_file (cls , path : str | Path ) -> None :
@@ -261,9 +268,21 @@ def parse(
261268 else :
262269 return None
263270
264- if strict :
265- return super ().parse (str_or_uri_or_curie , strict = strict )
266- return super ().parse (str_or_uri_or_curie , strict = strict )
271+ rv = super ().parse (str_or_uri_or_curie , strict = strict )
272+ return self ._post_process (rv )
273+
274+ def _post_process (self , rt : ReferenceTuple | None ) -> ReferenceTuple | None :
275+ if rt is None :
276+ return None
277+
278+ if rt .prefix in self .rules .postprocessing .suffix :
279+ for s in self .rules .postprocessing .suffix [rt .prefix ]:
280+ if rt .identifier .endswith (s ):
281+ return ReferenceTuple (
282+ prefix = rt .prefix , identifier = rt .identifier .removesuffix (s )
283+ )
284+
285+ return rt
267286
268287 # docstr-coverage:excused `overload`
269288 @overload
@@ -325,9 +344,8 @@ def parse_curie(
325344 else :
326345 return None
327346
328- if strict :
329- return super ().parse_curie (curie , strict = strict )
330- return super ().parse_curie (curie , strict = strict )
347+ rv = super ().parse_curie (curie , strict = strict )
348+ return self ._post_process (rv )
331349
332350 # docstr-coverage:excused `overload`
333351 @overload
@@ -410,6 +428,5 @@ def parse_uri(
410428 elif return_none :
411429 return None
412430
413- if strict :
414- return super ().parse_uri (uri , strict = strict , return_none = True )
415- return super ().parse_uri (uri , strict = strict , return_none = True )
431+ rv = super ().parse_uri (uri , strict = strict , return_none = True )
432+ return self ._post_process (rv )
0 commit comments