Hi Rob,
Â
Â
There are several ways. One is:
Â
Â
1) Aggregator
Â
Group By: Animal, Colour
Â
Keep Input Attributes: No
Â
List Name: _list
Â
Â
2) ListIndexer
Â
List Attribute: _list{}
Â
List Index: 0
Â
Demoted Attribute Prefix: first_
Â
Â
3) ListIndexer_2
Â
List Attribute: _list{}
Â
List Index: -1Â Â Â (-1 indicates the last element in the list)
Â
Demoted Attribute Prefix: last_
Â
Â
4) AttributeRenamer
Â
Old Attribute | New Attribute
Â
first_Start | Start
Â
last_End | End
Â
Â
Takashi
# re-post. correction for typos...
Â
Â
Another approach. Maybe this is simpler and more general.
Â
Â
1) StatisticsCalculator (Summary)
Â
Group By: Animal, Colour
Â
Attributes to Analyze: Start, End
Â
Â
2) AttributeRenamer
Â
Old Attribute | New Attribute
Â
Start._min | Start
Â
End._max | End
Hi Takashi,
Â
Â
As always thanks for the help. I have implemented the first solution using the Aggregator and the List Indexers and it has nearly worked. However, in the example above some successive records may match in terms of Cat and Purple, but there may be gaps in terms of successive End and Start values (which I want to retain). When I used the min and max (0 and -1) indexes the gap is effectively closed or ignored. Do you think there is a way to account for this?
Â
Â
Cat,Purple,101,102 (gap for next start)
Â
Cat,Purple,103,111
Â
Â
Regards,
Â
Â
Rob
Â
Â
Â
Ah, I missed that condition.
Â
How about creating a group ID by comparing Start of current row to End of previous row?
Â
Â
1) AttributeCreator
Â
Attribute Name: GroupID
Â
Value: <any>
Â
Just create the attribute name. It can be replaced with the AttributeExposer.
Â
Â
2) AttributeCreator_2
Â
Check Multiple Feature Attribute Support option.
Â
Number of Prior Features: 1
Â
If Attribute is Missing, Null or Empty: Use Other Value
Â
Attribute Replacement Value: 0
Â
-----
Â
Attribute Name: GroupID
Â
Value: 2 Possible Values (Conditional Value setting)
Â
If @Value(Start) = @Value(feature=-1].End) Then featuren-1].GroupID
Â
Else @Evaluate(@Value(featuret-1].GroupID) + 1)
Â
Â
3) StatisticsCalculator (Summary)
Â
Group By: Animal, Colour, GroupID
Â
Attributes to Analyze: Start, End
Â
Â
4) AttributeRenamer
Â
Old Attribute | New Attribute
Â
Start._min | Start
Â
End._max | End
Hi Takashi,
Â
Â
Thanks for the revised settings, IÂ managed to complete step 1 and then got stuck.
Â
Â
For info I am using FME2013.
Â
Â
I started on step 2 but could not find the check Multiple Feature Att support and the other settings i.e/ # prior features. (is this avaiable in 2013 or am is it user error (most likely!).
Â
Â
Also I tried to enter the conditional value setting but did not manage to enter teh setting in correctly.
Â
Â
Sorry for being a pain but could you  include a screen shot/s of this bit. when i have done it once I will be ok.
Â
Â
Regards,
Â
Â
Rob
Â
Â
Multiple Feature Attribute Support was added in FME 2013 SP2 (or SP1?).
Â
Well, replace two AttributeCreators with a PythonCaller.
Â
Attributes to Expose: GroupID
Â
-----
Â
import fmeobjects
Â
class GroupIdSetter(object):
Â
   def __init__(self):
Â
       self.groupId = 0
Â
       self.prevEnd = 0
Â
Â
   def input(self, feature):
Â
       start = int(feature.getAttribute('Start'))
Â
       if start != self.prevEnd:
Â
           self.groupId += 1
Â
       feature.setAttribute('GroupID', self.groupId)
Â
       self.prevEnd = int(feature.getAttribute('End'))
Â
       self.pyoutput(feature)
Â
Â
   def close(self):
Â
       pass
Â
-----
Hi,
Â
Â
I made a little workspace doing this.
Â
Â
Il put it on chatter
Uploaded on chatter,
Â
Â
its a tiny piece of tcl, and mostly transformers, in fme 2013.
..ok what it does.
Â
Â
listbuilder on col0 an dcol1 (Animal and Color)
Â
2 listconcatenators. 1 on col2 and 1 on col3 (start, end).
Â
Â
Then i use a little tcl to remove the intersection:
Â
In tcl caller
Â
Â
Â
Tcl Expression: listcompare @Value(Start) @Value(End)
Â
Source Code:
Â
proc listcompare {a b} {
Â
Â
 set a split $a ","]
Â
 set b >split $b ","]
Â
 set a_no_intersect {}
Â
 set b_no_intersect {}
Â
 foreach i $a {
Â
   if {ilsearch -exact $b $i]==-1} {
Â
     lappend a_no_intersect $i}
Â
      }
Â
   foreach i $b {
Â
   if {Âlsearch -exact $a $i]==-1} {
Â
     lappend b_no_intersect $i}
Â
      }  Â
Â
Â
Â
 FME_SetAttribute Start_ $a_no_intersect
Â
 FME_SetAttribute End_ $b_no_intersect
Â
Â
}
Â
Â
Â
Â
Attributesto expose: .Start_ End_
Â
Â
Â
then 2 attributesplitters on Start_Â and End_,
Â
listelementcounter on Start_ (or End_),
Â
attributecreator: index 0
Â
custom transformer to read out the 2 attributes:
- Â 2 listindexers on Start_ and End_ with Listindex : Index
- test on index.
- Tester:
Â
the trick here is to attach the passed and failed from the tester to output.Â
failed and raising index you must attach to loop to input. - so the tester fail ports gopes to output and loop to input. If u dont it will only output the last element in the list.
matcher : on col0 trough 3. (because the loop proces dups)
Â
Â
Â
i put it on chatter anyways..
Â
Â
haves funs!
Â
Â
Â
Gio
Â
I also created a workspace example with FME 2012 SP4.
Â
https://safecommunity.force.com/068a000000456DqÂ
Hi Takashi,
Â
Â
Thanks very much for the worked examples I will look at these over the weekend.
Â
Â
I checked and I do have 2013 SP1.
Â
Â
Also i tried to set up the pythoncaller with teh script last night and kept getting an error SYMBOL_NAME requires arguement; there was clearly something that I had missed. However the worked exmaple you have sent will be great to work through and i am sure that i will be able to follow the steps.
Â
Â
Thanks again for taking the time to construct this for me.
Â
Â
On a related note I reworked a workbench a few weeks ago and used SQL to preform a join between query which you helped with, this had previously been based on feature merge and then tests. i implemented the SQL version it took 6 minutes instead of the FM version whcih took 2Hrs and 5mins. A significant improvement.
Â
Â
Best wishes,
Â
Â
Rob
Â
Â
Â
Â
Â
Â
Hi Gio,
Â
Â
Thanks very much for sending the TCL and list concat solution via chatter, I will look at this over the weekend.
Â
Â
I love that fact that you can obtain the same result within FME but use completely differing ways of implementing a solution.
Â
Â
Â
Best wishes,
Â
Â
Rob
Hi Rob,
Â
Â
I updated the example, added full Python edition. You can download ver.2 from the same URL.
Â
Â
I expected that the SQL would be faster, but couldn't imagine such a significant improvement. The information will be very helpful for me.
Â
Thank you for the notification.
Â
Â
Have a nice weekend.
Â
Â
Takashi
Hi Takashi,
Â
Â
Many thanks for sending through v7 with all the additional methods for resolving this issue I will send some further reviewing the alternate methods, and select the most appropriate based on my service pack type.
Â
Â
I spent some time working through the 2 methods that you sent on Friday; due to my SP issues I implemented the variable based version, it worked a treat. Once I understood the process flow, I tested if I could add in another variable/condition which much be met.
Â
Â
(See below) I Included an extra variable (vPrevHat) and test condition (vPrevEnd = Start AND vPrevHat = Hat) which much be met in order to collapse the record, it worked well.
Â
Â
Â
Input Data Format
Â
Animal,Colour,Start,End,Hat
Â
Dog,Blue,0,1,Tophat
Â
Dog,Blue,1,5,Tophat
Â
Dog,Blue,5,10,Fedora
Â
Dog,Red,31,35,Baseball Cap
Â
Dog,Red,35,56,Baseball Cap
Â
Cat,Purple,101,102,Fez
Â
Cat,Purple,103,106,Fez
Â
Cat,Purple,106,111,Fez
Â
Â
Â
Output Data Format
Â
Animal,Colour,Start,End
Â
Dog,Blue,0,5,Tophat
Â
Dog,Blue,5,10,Fedora
Â
Dog,Red,31,56,Baseball Cap
Â
Cat,Purple,101,102,Fez
Â
Cat,Purple,103,111,Fez
Â
Â
Â
Depending on the compatibility of the new methods with my SP I may change, it is good to see the number of approaches which can be taken to solve a problem.
Â
Â
As always thanks again.
Â
Â
Best wishes
Â
Â
Rob
Good to hear you got your own solution.
Â
This is an interesting subject, was also a good material for my own self training. To Think of multiple approaches for the same goal is always a good training.
Â
Cheers!