Sorting irregular lists

Having trouble using an XCmd or XFcn? Post your questions here.

Sorting irregular lists

Postby JoeKoomen2011 » Sat May 16, 2009 1:34 pm

Any suggestions for sorting irregular lists of data?

Specifically, I want to sort a list of Authors. In some cases the person's name is two words long, in others it can be two authors listed together (Like "Laura J. Mixon & Melinda M. Snodgrass") in all cases I would like to sort by the last name of the last person on the list. In the case of using sortFieldByItem, I could be sorting by item 2 or 7 depending on the data. Also note that the list of authors is compiled on the fly.

I've thought about padding out the list for the sort and then un-padding it when I'm done the sort, but what I'm already doing is taking too long, so I want this sort to happen with as little code as possible.

Thanks for any suggestions.
Joe Koomen
>> Random! ...Damn near killed 'em! <<
User avatar
JoeKoomen2011
 
Posts: 474
Joined: Thu Mar 12, 2009 1:38 pm

Re: Sorting irregular lists

Postby JimTheParr » Sun May 17, 2009 10:23 am

I can't think of any way a script could detect whether the surname is one or more words long. It could probably take care of "von Trapp" and "de Mornay", but there might be cases any such method would miss.

If you have access to the names as they come up, or if you can figure out how to detect multiword surnames by script, you could insert a non-printing character just before each surname, or maybe use a non-breaking space (option-space,numtoChar(202)) there, then make that the itemDel and sort on the second item.

Or you could connect multiword surnames with, say, option-space instead of space; then a script could go through the list
put tSurNameDesignator before last word of line ... , set the itemDel to tSurNameDesignator, then do your sort on item 2.

Or some variation of those. Good luck..................--Jim
JimTheParr
 
Posts: 40
Joined: Sun Jul 06, 2008 2:18 pm
Location: Bloomington IL

Re: Sorting irregular lists

Postby 1nperson0z » Sun May 17, 2009 4:28 pm

Padding the list should work. Also SortFieldByItem also works for variables, which should speed things up a lot, so what about something like (untested and unoptimised)

Code: Select all
put cd fld "authorList" into tList
put the number of lines of tList into tCount
--pad the list with surname of last author
repeat with times = 1 to tCount
put last word of line times of tList into item 2 of tList
end repeat

--sort
put sortFieldByItem(tLIst, 2, A) into tList

--remove padding
repeat with times = 1 to tCount
delete last item of line times of tList
end repeat

--put it back into the field
put tList into cd fld "authorList"


Ian B
MacBook Pro 2.4Ghz i7 8Gb 10.11.3
1nperson0z
 
Posts: 79
Joined: Wed Jul 09, 2008 3:31 pm
Location: Blue Mountains Australia

Re: Sorting irregular lists

Postby JoeKoomen2011 » Mon May 18, 2009 1:21 pm

Thanks guys.

I avoided the whole issue by pre-sorting all the cards and making a list of that and then resorting the cards back into their original positions. Luckily SuperCard is very fast with this, although I haven't tested how much faster padding might have been.
Joe Koomen
>> Random! ...Damn near killed 'em! <<
User avatar
JoeKoomen2011
 
Posts: 474
Joined: Thu Mar 12, 2009 1:38 pm


Return to Using Externals

Who is online

Users browsing this forum: No registered users and 1 guest