Hi all,
So I do have a solution which I'm including in this post, but I just don't think it's elegant enough. It seems to me that it can/should be done with less transformers. Python can probably help solve this, but I just don't have the chops, at least as of now :) And I still would like to do it all with transformers if possible.
The problem I'm trying to solve is as follows: I have string data (multi-line text) that sometimes starts with a dash character used as a bullet. I need to have these dashes replaced by sequential numbers, mostly because an import into a database system fails with dashes. Here's a before:
and after:
The StringReplacer trasformer comes very close (see the top part of ""). The nice thing about this transformer is that it allows the user to pick multiple attributes, which is a requirement for me as there are multiple attributes I need to fix for each feature. However the Replacement Text setting is limiting in my case (cannot do sequential numbers within the same attribute with it as far as I can tell; this would imply assigning lists, which isn't possible).
So my next try was to use a series of transformers to split each multi-line text into separate lines, do a RegEx search for each one to find instances of lines starting with a dash, then count those instances and use the count attribute to do the dash replacement. I also wrapped this in a custom transformer, but the problems I'm facing are:
- It doesn't seem possible to make changes to input parameters directly within a custom transformer, hence the need for additional attribute cleanup after the custom transformer. As you can see from the "Multiple" example, you have to add a custom transformer, followed by an AttributeManager, for each attribute you want to clean up. This is the "unelegant" part I would love to find a solution to.
- The custom transformer contains various other transformers that do not allow multiple attributes to be selected: AttributeSplitter & StringSearcher.
- I tried to use an AttributeExploder to "flatten" the attribute list, filter unwanted features (unwanted attributes become features so you filter those out), then use a single instance of the custom transformer. The problem though is: how do you re-assemble them dynamically into the original features with the original attributes after the text cleanup?
#3 can be solved (somewhat) as you can see in "", but I'm trying to create a dynamic workflow that does not require one to know all attributes that need to be fixed. Basically I want to look for this condition within all/select attributes and make the adjustment, rather than manually specifing each one and having to "hard-code" for each attribute. Any help would be greatly appreciated!