Skip to main content
Solved

Remove the two last elements of a list


Forum|alt.badge.img

Hello,

I'm very confused, I don't find how to remove the two last elements of a address list and concatenate the other words.

imageI think it's quite easy but even with the ListElementCounter, I dont find the answer!

Thank for your help.

Best answer by dustin

Based on the screenshot, it looks like you've used an AttributeExploder. I'm assuming that you now have a common attribute that could be used to group each of the related elements now? If so, let's assume that attribute is 'ID'. (If you don't have a common attribute, you can create one prior to your AttributeExploder using the Counter transformer).

 

I would feed all the features into a StatisticsCalculator with the Group By set to ID. In the Statistics to Calculate section, set the attribute to _element_index, and check the box for max. From the Complete port of the StatisticsCalculator, feed that into a Tester. The test you want to perform is @Value(_element_index) <= @Evaluate(@Value(_element_index.max)-2). From the passed port will be the list components except the last two. Send those to an Aggregator with Group By set to ID, and use the Attributes to Concatenate parameters to build your concatenation.

View original
Did this help you find an answer to your question?

2 replies

dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • Best Answer
  • October 6, 2022

Based on the screenshot, it looks like you've used an AttributeExploder. I'm assuming that you now have a common attribute that could be used to group each of the related elements now? If so, let's assume that attribute is 'ID'. (If you don't have a common attribute, you can create one prior to your AttributeExploder using the Counter transformer).

 

I would feed all the features into a StatisticsCalculator with the Group By set to ID. In the Statistics to Calculate section, set the attribute to _element_index, and check the box for max. From the Complete port of the StatisticsCalculator, feed that into a Tester. The test you want to perform is @Value(_element_index) <= @Evaluate(@Value(_element_index.max)-2). From the passed port will be the list components except the last two. Send those to an Aggregator with Group By set to ID, and use the Attributes to Concatenate parameters to build your concatenation.


Forum|alt.badge.img
  • Author
  • October 6, 2022
dustin wrote:

Based on the screenshot, it looks like you've used an AttributeExploder. I'm assuming that you now have a common attribute that could be used to group each of the related elements now? If so, let's assume that attribute is 'ID'. (If you don't have a common attribute, you can create one prior to your AttributeExploder using the Counter transformer).

 

I would feed all the features into a StatisticsCalculator with the Group By set to ID. In the Statistics to Calculate section, set the attribute to _element_index, and check the box for max. From the Complete port of the StatisticsCalculator, feed that into a Tester. The test you want to perform is @Value(_element_index) <= @Evaluate(@Value(_element_index.max)-2). From the passed port will be the list components except the last two. Send those to an Aggregator with Group By set to ID, and use the Attributes to Concatenate parameters to build your concatenation.

yes Great it works!!

Thank you @dustin​ for your quick answer!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings