How can my program best represent a translation between imperfectly-matched data structures?
I am tasked with a one-way translation of data from one system to another. Both systems are established, I don't have the option of changing their data structures.
If the structures corresponded item-for-item, it would be simple to translate:
- Iterate over all input items:
- Transform the item
- Populate the output item
(We are implementing the translation in Python, so if it were that simple I would just define the item-level transforms, then iterate the data structures in a single statement.)
That won't work though, because the systems have inconsistently-matched data structures.
The data structures have largely-overlapping correlations that we've discovered, but there are many inconsistencies; a sequence here will be a single item there; a pair of unrelated items here will be a homogeneous sequence there; and so on.
What patterns can I follow to represent the mostly-correlated but imperfectly-aligned data structures, such that the translation describes all the mapping complexity and all we need do then is connect the systems at each end?