PreprocessingConverter

class PreprocessingConverter(*args: Any, rules: PreprocessingRules | str | Path, reference_cls: type[X] | None = None, preclean: Callable[[str], str] | None = None, **kwargs: Any)[source]

Bases: Converter

A converter with pre-processing rules.

Instantiate a converter with a ruleset for pre-processing.

Parameters:
  • args – Positional arguments passed to curies.Converter.__init__()

  • rules – A set of rules

  • reference_cls – The reference class to use. Defaults to curies.Reference.

  • preclean – An optional function used to preprocess strings, CURIEs, and URIs before parsing

  • kwargs – Keyword arguments passed to curies.Converter.__init__()

Methods Summary

from_converter(converter, rules)

Wrap a converter with a ruleset.

parse()

Parse a string, CURIE, or URI.

parse_curie()

Parse and standardize a CURIE.

parse_uri()

Parse and standardize a URI.

Methods Documentation

classmethod from_converter(converter: Converter, rules: PreprocessingRules | str | Path) Self[source]

Wrap a converter with a ruleset.

Parameters:
  • converter – A pre-instantiated converter

  • rules – A pre-processing rules object, or path to a JSON file containing a pre-processing configuration

Returns:

A converter that uses the ruls for pre-processing when parsing URIs and CURIEs.

parse(str_or_uri_or_curie: str, *, strict: Literal[True] = True, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple[source]
parse(str_or_uri_or_curie: str, *, strict: Literal[False] = False, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple | None

Parse a string, CURIE, or URI.

parse_curie(curie: str, *, strict: Literal[False] = False, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple | None[source]
parse_curie(curie: str, *, strict: Literal[True] = True, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple

Parse and standardize a CURIE.

Parameters:
  • curie – The CURIE to parse and standardize

  • strict – If the CURIE can’t be parsed, should an error be thrown? Defaults to false.

  • context – Is there a context, e.g., an ontology prefix that should be applied to the remapping and blocklist rules?

  • block_action

    What action should be taken when the blocklist is invoked?

    • raise - raise an exception

    • pass - return None

Returns:

A tuple representing a parsed and standardized CURIE

Raises:

BlocklistError – If the CURIE is blocked

parse_uri(uri: str, *, strict: Literal[False] = False, return_none: Literal[False] = False, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') Never[source]
parse_uri(uri: str, *, strict: Literal[False] = False, return_none: Literal[True] = True, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple | None
parse_uri(uri: str, *, strict: Literal[True] = True, return_none: bool = False, context: str | None = None, block_action: Literal['raise', 'pass'] = 'raise') ReferenceTuple

Parse and standardize a URI.

Parameters:
  • uri – The URI to parse and standardize

  • strict – If the URI can’t be parsed, should an error be thrown? Defaults to false.

  • return_none – A dummy value, do not use. If given as False, will raise a not implemented error

  • context – Is there a context, e.g., an ontology prefix that should be applied to the remapping and blocklist rules?

  • block_action

    What action should be taken when the blocklist is invoked?

    • raise - raise an exception

    • pass - return None

Returns:

A tuple representing a parsed and standardized URI

Raises:
  • BlocklistError – If the URI is blocked

  • NotImplementedError – If return_none is given as False