polymatheia.transform

The transform module implements a number of transform classes.

All transform classes use the following transform expression language and are designed to work with NavigableDict. Each transform is structured as follows: ('operator', 'parameter'[, 'parameter', ...]). The number of parameters depends on the operator:

  • Static: ('static', target, value): The static value is stored at the location specified by the dotted path target.

  • Copy: ('copy', target, source): The value specified by the dotted path source is stored at the location specified by the dotted path target.

  • Fill: ('fill', target, value): If the value specified by the dotted path target is None, then this is replaced by the value, otherwise it is left untouched.

  • Split: ('split', target, splitter, source): The value specified by the dotted path ``source is split and stored at the location specified by the dotted path target. If the value is a list, then the list is split into its elements. If the value is a str, then it is split using splitter`. Because this will produce more than one value in the transformation result, the ``target can contain the string {}, which is replaced with the index of each split value (starting at 1).

  • Combine: ('combine', target, source1, ...): The values specified by the dotted paths source1 (and optionally source2, source3,…) are combined into a list and stored at the location specified by the dotted path target.

  • Join: ('join', target, joiner, source1, ...): The values specified by the dotted paths source1 (and optionally source2, source3,…) are joined by the joiner and the result stored at the location specified by the dotted path target. If only one source is specified, this is treated as a list and the values of the list joined using joiner. If multiple sources are specified, then the values returned by each dotted source path are returned.

  • sequence: ('sequence', expression1, expression2, ...): Applies the transform expressions in sequence. When using the sequence transformation, this should be the only top-level transformation being applied, otherwise the results cannot be guaranteed.

  • parallel: ('multiple', expression1, expression2, ...): Applies the transform expressions in parallel. Only needed if you want to convert multiple expressions in parallel inside a sequence transform. Parallel transforms must not be mixed with other transforms at the same level.

  • custom: ('custom', target, callable): Applies the custom transformation defined by the callable and stores the result in target.

class polymatheia.transform.RecordsTransform(records, mappings)

The RecordsTransform provides a record transformation iterator container.

The actual transformation is performed using a Transform that is applied to each record in the source iterator.

__init__(records, mappings)

Create a new RecordsTransform.

Parameters:
  • records – The source records to iterate over and transform

  • mappings (list) – The mappings that are applied to each record

__iter__()

Return this class:~polymatheia.transform.RecordsTransform as the iterator.

__weakref__

list of weak references to the object (if defined)

class polymatheia.transform.RecordsTransformIterator(records, mappings)

The RecordsTransformIterator provides a record transformation iterator.

The actual transformation is performed using a Transform that is applied to each record in the source iterator.

__init__(records, mappings)

Create a new RecordsTransformIterator.

Parameters:
  • records – The source records to iterate over and transform

  • mappings (list) – The mappings that are applied to each record

__iter__()

Return this class:~polymatheia.transform.RecordsTransformIterator as the iterator.

__next__()

Transform and return the next NavigableDict record.

Returns:

The transformed record

Return type:

NavigableDict

Raises:

StopIteration – If no more records are available

__weakref__

list of weak references to the object (if defined)

class polymatheia.transform.Transform(mapping)

The Transform is a callable transformation for NavigableDict.

__call__(record)

Transform the record according to the mappings of this Transform.

Parameters:

record (NavigableDict) – The record to transform

Returns:

The transformed record

Return type:

NavigableDict

__init__(mapping)

Create a new Transform.

Parameters:

mapping (tuple or list) – The mappings that are applied when the Transform is called. If a list is passed as the parameter, then this constructs an implicit 'parallel' transform.

__weakref__

list of weak references to the object (if defined)