INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Help With An Expression (Artist Letters)  (Read 3835 times)

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Help With An Expression (Artist Letters)
« on: May 20, 2012, 10:29:19 pm »

Way back in 2010, marko helped me create an [Artist Letters] Calculated field, which I use when organizing my music files on disk, so that they go into folders like this:

M:\Audio\Music\0 - 9\2pac\The Don Killuminati - The 7 Day Theory (Makaveli)
M:\Audio\Music\A\Aphex Twin\I Care Because You Do [90-94]
M:\Audio\Music\A\The Avett Brothers\Four Thieves Gone - The Robbinsville Sessions
M:\Audio\Music\B\Benetar, Pat\Best Shots
M:\Audio\Music\B\The Beatles\Sgt. Pepper's Lonely Hearts Club Band
M:\Audio\Music\C\Chatham County Line\Speed of the Whippoorwill
M:\Audio\Music\D\Difranco, Ani\Dilate
M:\Audio\Music\E\Ellington, Duke\The Best of Duke Ellington
M:\Audio\Music\F\A Flock of Seagulls
M:\Audio\Music\F\The Felice Brothers\The Felice Brothers
<etc>


You get the idea.  It returns the first letter "folder name" that I want created for each given artist: 0-9, A, B, C, D, E, F, etc.  But it  does so in a smart way that it "ignores articles" such as: a, an, and the, making the results match the results of using MC with "ignore articles" enabled.

Here's my expression:

Code: [Select]
if(isequal(mid([artist],0,4),the/ ,1),mid([artist],4,1),if(isequal(mid([artist],0,3),an/ ,1),mid([artist],3,1),if(isequal(mid([artist],0,2),a/ ,1),mid([artist],2,1),if(isequal(Mid([artist],0,1),1,6),0 - 9,Mid([artist],0,1))))
It has been working since we made it back in 2010, but it is broken now.  It returns: "Expression Error (Unknown)".  I think I know why (the changes recently in the Expression Engine made it less forgiving of logic errors and/or the nesting changes), but I don't feel like diagnosing it because...

I'm sure there is a much better way to do this now, with RegEx instead of all the crazy If(isequal(mid)) statements.

Help?
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #1 on: May 20, 2012, 11:50:47 pm »

The expression is just missing a single closing paren.

But here's your newfangled, improved version:

   Regex([Artist], /#^(?:(?:the|an|a) +)?(.)#/,-1)if(Compare(1[R1], >=, 10), 0 - 9, [R1])

It also fixes two problems in the original expression:

  1) The 5th Dimension would have been placed under 5, and not 0 - 9.
  2) Artists with 0 would have been placed in a separate 0 category, not 0 - 9.

Would you like punctuation all to be placed into an Other category?
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Help With An Expression (Artist Letters)
« Reply #2 on: May 21, 2012, 12:27:21 am »

The expression is just missing a single closing paren.

I figured, actually.  I was going to count them, and then I was lazy (since I didn't like it anyway).  And, I was going to just add it, but the same.

Would you like punctuation all to be placed into an Other category?

I don't think I have any, but if you feel like modifying it, grouped in with 0-9 works for me (Other would sort in Windows Explorer with O).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Help With An Expression (Artist Letters)
« Reply #3 on: May 21, 2012, 05:15:28 am »

Quote
I don't think I have any, but if you feel like modifying it, grouped in with 0-9 works for me (Other would sort in Windows Explorer with O).

That's what I do in a pane for narrowing down [Artist]\[Album] shown in a separate pane. That is, all names that do not begin with a letter of the alphabet are grouped as '0-9'. I've now updated that (thanks, MrC) to...

Regex([Artist], /#
(?:(?:the|an|a) +)?([^a-zA-Z]?)(?:[^a-zA-Z]*)(?:(?:the|an|a|and|st|nd|rd|th) +)* ?([a-zA-Z])(.)
#/,-1)
If(IsEmpty([R1]), FixCase([R2]), 0-9)\[R2][R3]&DataType=[list]


That creates a nested list where the first level is the first letter (or '0-9') and the second is the first two letters (that are alpha and not the words the, an or a). (It allows much faster selection than is possible searching and scrolling in an [Artist] pane.) I'm not sure I've done it correctly, but it seems to work for my artists. It handles things like 107.8 Radio (as '0-9\Ra'), and my favourite test case: ? and the Mysterians ('0-9\My').

Now all I have to do is figure out how to include single artists by surname (as well as by full name)...
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Help With An Expression (Artist Letters)
« Reply #4 on: May 21, 2012, 05:49:18 pm »

Quote
Now all I have to do is figure out how to include single artists by surname (as well as by full name)...

I've now done so as follows...

Regex([Artist], /#
(?:(?:the|an|a) +)?([^a-zA-Z]?)(?:[^a-zA-Z]*)(?:(?:the|an|a|and|st|nd|rd|th) +)* ?([a-zA-Z])(.)
#/,-1)
If(IsEmpty([R1]), FixCase([R2]), 0-9)\[R2][R3];

If(IsEmpty([r.Surname]), , Left([r.Surname], 1)\– FixCase(Left([r.Surname], 1)))
&DataType=[List]

[r.Surname] is an Artist-related field in which I save only the surname of 'single artists'. I started with an expression that did much the same thing (by determining 'single artists' using other data), but there were exceptions, and I realized I would want to override it anyway. Now that it's done, setting the value (if applicable) for new artists will be an infrequent, easy task. Also, using an Artist-related field eliminates the possibility of assigning more than one value per artist.

As shown in the screenshot, it adds the surnames to the list for each letter, and includes them all under '– {letter}' in the second level—so they can be easily viewed alone or excluded.
Logged

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #5 on: October 12, 2013, 01:28:13 pm »

This is brilliant.  Beats the heck out of FormatRange([Artist], 1, 0) that I was using.  Thank you.
Logged
Pages: [1]   Go Up