If you want to flatten the histogram as if it were a key/value pair,
Â
in your histogram example you would end up with
Â
1: 2
Â
2: 2
Â
3: 1
Â
5: 1
then creating a custom transformer loop and using an attributeCreator with the new attribute as @Value(_histo{@Value(i)}.value) and the Attribute Value as @Value(_histo{@Value(i).count) should work. Where i is the loop iteration from 0 to length of list -1
Â
Â
If you want the attribute to be named first_class, fourth_item, etc, then python is the way to go.
Upon further investigation, I'm not even sure this is possible with Python! I can't find any way to access a full list - this question from 2012 suggests the "new" API doesn't have one -
https://knowledge.safe.com/questions/5463/python-and-lists.htmlÂ
Is it possible?
Â
Upon further investigation, I'm not even sure this is possible with Python! I can't find any way to access a full list - this question from 2012 suggests the "new" API doesn't have one -
https://knowledge.safe.com/questions/5463/python-and-lists.htmlÂ
Is it possible?
Â
feature.getAttribute('_histogram{}.value') will return a list as will feature.getAttribute('_histogram{}.count').
Â
Â
If necessary you can zip them together, though I have rarely needed to do that.
Â
I cannot understand the naming rule for the destination attribute ('first_class', 'other_thing' ... 'final'?), but if the goal was just to map the counts to new attributes with any names corresponding to the values (1, 2, ... 5), this Python script example might help you.
# PythonCaller Script Example
def processFeature(feature):
    valueToAttr = {
        '1': 'first',
        '2': 'second',
        '3': 'third',
        '4': 'fourth',
        '5': 'fifth',
    }
   Â
    valueToCount = {}
    values = feature.getAttribute('_histo{}.value')
    counts = feature.getAttribute('_histo{}.count')
    if values and counts:
        for v, c in zip(values, counts):
            valueToCount(v] = c
           Â
        for v in valueToAttr.keys():
            if v in valueToCount:
                feature.setAttribute(valueToAttrÂv], valueToCount v])
I cannot understand the naming rule for the destination attribute ('first_class', 'other_thing' ... 'final'?), but if the goal was just to map the counts to new attributes with any names corresponding to the values (1, 2, ... 5), this Python script example might help you.
# PythonCaller Script Example
def processFeature(feature):
    valueToAttr = {
        '1': 'first',
        '2': 'second',
        '3': 'third',
        '4': 'fourth',
        '5': 'fifth',
    }
   Â
    valueToCount = {}
    values = feature.getAttribute('_histo{}.value')
    counts = feature.getAttribute('_histo{}.count')
    if values and counts:
        for v, c in zip(values, counts):
            valueToCount(v] = c
           Â
        for v in valueToAttr.keys():
            if v in valueToCount:
                feature.setAttribute(valueToAttrÂv], valueToCount v])
Thanks, that did the trick nicely, I couldn't find anything how to access lists with Python, hence my problem. Relating to the naming convention, I was trying to express that the attribute names would be arbitrary, but that's easily resolved in your version by changing the dict values.
Â