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 2784 times)

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Help With An Expression (Artist Letters)
« on: January 15, 2014, 08:22:24 am »

I've been using this expression to group by Artist Letters (thanks Mrc):

Code: [Select]
Regex([Artist], /#^(?:(?:the|an|a) +)?(.)#/,-1)if(Compare(1[R1], >=, 10), 0 - 9, [R1])
It's been working great, but I've started to use the list ability of the Artist field more and discovered a problem.  If there are multiple artists, it only uses the first letter of the first artist. 

For example: The All Star Band; The Levon Helm Band; My Morning Jacket
The All Star Band, The Levon Helm Band, and My Morning Jacket will all appear under the letter A. 

I would like each one to be placed under their own letter (ie A, L, and M).  Is that possible?



Logged

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: January 15, 2014, 12:58:49 pm »

Only to a limited extent.

The problem: MC doesn't have a list-iterator, so you can't grab the first letters of each item in the list generally.

With a more complex regex, that essentially replicates the current pattern and adds more optional cases following a semicolon, you could grab up to the first 9 (MC also limits the number of captures to 9, which I think was a limitation of the previous Microsoft TR1 regular expression library).  Of course, more conditional If's will be required too.

If your artists don't change that much, you could use an external script (hint: pscriptor) to populate another field with the results you want, and use that fields instead of Artists.
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #2 on: January 15, 2014, 03:09:44 pm »

I doubt I would ever have more than 9 Artists in the Field.  I'd prefer to use an expression rather than an external script since it is automatic.  I would need to remember to run the scriplet every time I imported an Album in order to populate the new Field. 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #3 on: January 15, 2014, 06:00:40 pm »

Why don't you do it this way, which is as extensible as you want to copy/paste:

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

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

&datatype=[list]

Copy and paste a colored section and change the bold indexes accordingly.  1 is the second list item, 2 is the third, etc.
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #4 on: January 16, 2014, 08:28:26 am »

Almost there, but not quite.  That places all of them in each letter (ie A has The All Star Band, The Levon Helm Band, and My Morning Jacket, L has The All Star Band, The Levon Helm Band, and My Morning Jacket , and M has The All Star Band, The Levon Helm Band, and My Morning Jacket).
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #5 on: January 16, 2014, 11:10:11 am »

if you have a track that has three artists, The All Star Band, The Levon Helm Band, and My Morning Jacket, which single grouping should it go under?  It contains three artists.

This is better suited to Panes or Categories where you can create a hierarchy, and you select based on the letter, and are presented with only the item that matched that letter.
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #6 on: January 16, 2014, 12:19:16 pm »

It should go under all three, but only the Artist for that grouping should be shown.

Example:
A -> The All Star Band -> Track 27
L -> The Levon Helm Band -> Track 27
M -> My Morning Jacket -> Track 27

Right now it shows:
A -> The All Star Band -> Track 27
       The Levon Helm Band -> Track 27
       My Morning Jacket -> Track 27
L -> The All Star Band -> Track 27
       The Levon Helm Band -> Track 27
       My Morning Jacket -> Track 27
M -> The All Star Band -> Track 27
       The Levon Helm Band -> Track 27
       My Morning Jacket -> Track 27

This is better suited to Panes or Categories where you can create a hierarchy, and you select based on the letter, and are presented with only the item that matched that letter.

That is what I'm trying to do.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #7 on: January 16, 2014, 12:21:43 pm »

I'm confused.  Are we talking about Group By?  If not, where?
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 #8 on: January 16, 2014, 12:24:53 pm »

I don't think he knows about the Category Grouping feature...

I'm on my phone right now, so I can't easily explain.
Logged
"Some cultures are defined by their relationship to cheese."

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

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #9 on: January 16, 2014, 12:38:34 pm »

I'm aware of the Category Grouping feature, and it does not do it properly either.  It automatically groups by Album and doesn't break out the Artists. 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #10 on: January 16, 2014, 12:38:57 pm »

Try this instead:

ifelse(compare(listcount([Artist]), >, 0),
    Regex(listitem([Artist], 0), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
ifelse(compare(listcount([Artist]), >, 1),
   ;Regex(listitem([Artist], 1), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
ifelse(compare(listcount([Artist]), >, 2),
   ;Regex(listitem([Artist], 2), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
&datatype=[list]
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #11 on: January 16, 2014, 12:41:50 pm »

BAM!  That's it.  Thank you for you patience with me MrC. 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #12 on: January 16, 2014, 12:47:41 pm »

No sweat.  I got confused by the term "group by" in your original post.

I captured the entire Artist name in the RE (as [R1]) to show in the nested level.  If you want the artist sans articles, use:

   /#^(?:(?:the|an|a) +)?((.).*)#/

as the RE.
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #13 on: January 16, 2014, 12:48:31 pm »

Ahh....I just figured out why Category Grouping does that and possibly what Glynor was going to explain.

I need to double the Categories.  So:

Artist (Grouping Size 1)
Artist
Album  

Thanks for bearing with me.  
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Help With An Expression (Artist Letters)
« Reply #14 on: January 16, 2014, 01:02:45 pm »

Yep, that's it.

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

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

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #15 on: January 17, 2014, 10:06:58 am »

Try this instead:

ifelse(compare(listcount([Artist]), >, 0),
    Regex(listitem([Artist], 0), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
ifelse(compare(listcount([Artist]), >, 1),
   ;Regex(listitem([Artist], 1), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
ifelse(compare(listcount([Artist]), >, 2),
   ;Regex(listitem([Artist], 2), /#^((?:(?:the|an|a) +)?(.).*)#/,-1)if(Compare(1[R2], >=, 10), 0 - 9, [R2])\[R1])/
&datatype=[list]

So this is working perfectly, and it doesn't appear to be limited to the first 9.  I copy and pasted it out and tested it with up to 15-Artists, and it worked.  I prefer it to the Category Grouping feature since it places all numbers in 0-9 instead of individual groups for 1, 2, 3, etc.

However, it places special characters (!, $, &, etc) in their own individual grouping.  Category Grouping puts them all in a group called "Others."  I would like to do the same thing except have them under * so they are first in the alphabetical listing rather than after O.

Could I trouble you for assistance one more time?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help With An Expression (Artist Letters)
« Reply #16 on: January 17, 2014, 10:36:10 am »

Replace [R2] with FormatRange([R2],1,1).  This won't place them under *, but will use FormatRange's "(Others)" and its special sorting.  You can of course post-replace that by replacing "(Others)" with whatever you want.
Logged
The opinions I express represent my own folly.

connersw

  • Citizen of the Universe
  • *****
  • Posts: 661
Re: Help With An Expression (Artist Letters)
« Reply #17 on: January 17, 2014, 11:09:42 am »

Perfect--many thanks.  (Others) actually works nicely since it will come first alphabetically as opposed to Others in Category Grouping. 
Logged

MGD_King

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 548
  • It's not easy being me, but it sure is fun!
Re: Help With An Expression (Artist Letters)
« Reply #18 on: January 26, 2014, 08:06:49 am »

This works like a charm while using Gizmo! It makes locating an artist so much easier now!! Thanks MrC!
Logged
Pages: [1]   Go Up