INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help: Changing artist [lastname, firstname] to [firstname lastname]  (Read 6060 times)

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

As the title says, I need an expression to change (in bulk): [artist] from the format (lastname, firstname) to (firstname lastname)

A couple of threads provide expressions to do the opposite transition, but my regex-fu is pititful and I didn't bother trying to reverse engineer them.

I started by creating custom fields for first name and last name, and was going to look for an expression that I could use to auto-fill this data from the artisit name. e.g. anything before the comma fills firstname, and everything after the comma and space will fill the lastname. Then I would simply do =[firstname] [lastname].
However, after seeing what regex could do to bypass these multiple steps, I realised I should just ask for a one-shot deal if possible.

Any help appreciated.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854

Mr C is/was the reg-expert...

But how about something like:

if(regex([artist], /#^([^,]*), (.*)#/, 0),[R2] [R1],[artist])

Will do the swap if a comma is present, otherwise just returns the [artist] field.

Could break if more than one comma present...

And am assuming that the [ ] are not part of your text?
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

Mr C is/was the reg-expert...

But how about something like:

if(regex([artist], /#^([^,]*), (.*)#/, 0),[R2] [R1],[artist])

Will do the swap if a comma is present, otherwise just returns the [artist] field.

Could break if more than one comma present...

And am assuming that the [ ] are not part of your text?

Thanks very much! The [] are not part of the text, indeed.
I just checked it out, and used with caution, it's perfect for the intended use. Thanks so much again.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854

That's great.  I'm pretty comfortable with regex in other languages but rarely use them in MC, so I'm glad it worked for you :D
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772



A couple of threads provide expressions to do the opposite transition, but my regex-fu is pititful and I didn't bother trying to reverse engineer them.

hi

searched for these threads can't find them (going the opposite way)  -- got a link or a search phrase, if its not too much of a pain? not coming up with anything

thanks
Logged

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3020

Here is one of the threads, from October

http://yabb.jriver.com/interact/index.php?topic=92346
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

There is a better thread. I will find it when on my PC.
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

Here is the thread I was looking at:
http://yabb.jriver.com/interact/index.php?topic=92092.0

And it links to an earlier thread too:
http://yabb.jriver.com/interact/index.php?topic=78210.0

Most of the heavy lifting done by glynor.  :)

I also miss MrC.  :(

PS, I found the original thread by googling:
Quote
changing artist last name, first name to first name last name in jriver
Logged

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3020

Here is the thread I was looking at:
http://yabb.jriver.com/interact/index.php?topic=92092.0

And it links to an earlier thread too:
http://yabb.jriver.com/interact/index.php?topic=78210.0

Most of the heavy lifting done by glynor.  :)

I also miss MrC.  :(

PS, I found the original thread by googling:

Thanks for the links to the earlier thread. FYI, your first link is referenced in the October thread. And that thread references your second link. The October thread adds additional information to the original threads.
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772

yes good to consolidate this - thanks guys
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

Thanks for the links to the earlier thread. FYI, your first link is referenced in the October thread. And that thread references your second link. The October thread adds additional information to the original threads.

Thanks for the correction! I skimmed through the October thread and noticed a lack of expressions compared to the earlier threads. I didn't realize that they were linked to. Cheers.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42002
  • Shoes gone again!

Next build:
NEW: Added an Unswap(...) expression function that takes Last name, First name and flips them to First name Last name.

You can in-place edit the artist and type =Unswap([Artist]) and it'll fill the value in unswapped.
Logged
Matt Ashland, JRiver Media Center

ssands

  • Galactic Citizen
  • ****
  • Posts: 457

Next build:
NEW: Added an Unswap(...) expression function that takes Last name, First name and flips them to First name Last name.

You can in-place edit the artist and type =Unswap([Artist]) and it'll fill the value in unswapped.
Awesome!

Is there a Swap([Artist]) function? Just curious.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42002
  • Shoes gone again!

Is there a Swap([Artist]) function? Just curious.

Not currently.  What would it do?  Take First Name Last Name and swap to Last Name, First Name?
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42002
  • Shoes gone again!

Next build:
NEW: Added a Swap(...) expression that takes First name Last name and swaps to Last name, First name.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608

Do both of these new expression functions take suffixes (like Jr, Sr, III, etc) into account like MrC's nice RegEx does?

The Unswap() in particular would be quite handy for me.  I'm currently mulling switching my [Artist] system over to something a little fancier and more automatic, but to do so, I'll need to manually Unswap() all of my existing "single-person" artist names.
Logged
"Some cultures are defined by their relationship to cheese."

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

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42002
  • Shoes gone again!

Do both of these new expression functions take suffixes (like Jr, Sr, III, etc) into account like MrC's nice RegEx does?

No.  They search for a ", " or a " " and do the deed.

What should they be checking for?
Logged
Matt Ashland, JRiver Media Center

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3020

Matt - your swap will work 90%+ of the time, but there are several potential problems that are hard to sort out. Sometimes names should not be swapped, like  the jazz group LA 4 should probably not become 4, LA. How about The Beatles. You need to deal with people with three or more names, like Jamie Lee Curtis or Billy Bob Thornten, or groups like Bill Evans Trio, Peter, Paul & Mary or  Allison Krauss & Union Station. Even Bach and Mozart become a problem. The discussion in the earlier threads is not only about how to swap names but also about how you handle these exceptions. The solution up to now has been to have a way to manual override the expressions when the unusually cases arise.  I would think Mr. C's expression should be the minimum. And even then, there are going to be many times that the function does not give the correct result. As much as swap and unswap would be nice, you need to realize that there are many times they will not give the desired result.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608

No.  They search for a ", " or a " " and do the deed.

What should they be checking for?

MrC's expression is:

Code: [Select]
if(!regex([Artist], /#^([^,]+)\s+([^,]*?)$#/),
   [Artist],
   regex(listclean([Artist], 2, / ),
         /#^(?:(I+|[JS]r\.?)\s+)?(\S+)(.*)$#/, -1)[R2]/,/ listclean([R3], 2, / )[R1]
)

That'll "ignore" Jr, Sr, I, II, III, and any digit (perhaps among others, RegEx makes my eyes bleed).

So that "Harry Connick Jr." becomes "Connick, Harry Jr." instead of "Jr., Harry Connick" (which is useless).
Logged
"Some cultures are defined by their relationship to cheese."

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

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608

Matt - your swap will work 90%+ of the time, but there are several potential problems that are hard to sort out. Sometimes names should not be swapped, like  the jazz group LA 4 should probably not become 4, LA.

Yes.  Only a human can identify these.

My plan is to make a checkbox field where you can enable [Artist Name Swapped] and then the displayed/sorted value for that Artist will spit out a Swap() version, and if the checkbox is unchecked (the default) they'll be normal.  Right now, I do it by hand, but that's annoying.  This will be easier.  Just check a box and it'll swap them for you.

I think.  I haven't built it yet.  I'm a little concerned about how it will impact tagging.
Logged
"Some cultures are defined by their relationship to cheese."

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

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877

Thanks, Matt! I will have to use the regex expression provided above this time around, as I am scheduled to help someone make these changes tomorrow. I'm not sure that the guy is on MC19 or 20, so this new work might help me later on if not tomorrow.

This is my planned workflow:

The very first step is to filter for Artist names that have a comma in them.

I was planning on creating a new field as a triage to take the expression. Then I can compare, say, [Artist swapped] to [Artist]. Unselecting any that are not done right, I will then do a Move/Copy Fields with [Artist swapped] as source and [Artist] as destination.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42002
  • Shoes gone again!

Next build:
Changed: The Swap(...) expression has special handling for strings that end with Jr., Sr., I, II, III, IV, V.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608

Thanks, Matt!
Logged
"Some cultures are defined by their relationship to cheese."

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

ssands

  • Galactic Citizen
  • ****
  • Posts: 457

My plan is to make a checkbox field where you can enable [Artist Name Swapped] and then the displayed/sorted value for that Artist will spit out a Swap() version, and if the checkbox is unchecked (the default) they'll be normal.  Right now, I do it by hand, but that's annoying.  This will be easier.  Just check a box and it'll swap them for you.

I think.  I haven't built it yet.  I'm a little concerned about how it will impact tagging.
Based on your earlier comments about this, Glynor, I went ahead and implemented it and it has worked really well for me. You had also mentioned an "override" field, for those cases where the swap or unswap wasn't what was wanted. It has worked out very well for me and allowed me to deal well with compilations (where I wanted to sort it under the Album name instead of multiple artists or whatever, but still keep the individual artists listed by track) and also with names like Jethro Tull or Pink Floyd which I put under J and P respectively.

Glynor: Thanks for the suggestion; it worked really well for me.
Matt: thanks! Cool work!
Logged
Pages: [1]   Go Up