INTERACT FORUM

Please login or register.

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

Author Topic: Expression column with subtraction  (Read 2068 times)

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Expression column with subtraction
« on: August 22, 2011, 04:55:55 pm »

(I figured a slightly-confusing subject might get me more eyeballs. Sorry!)

I am wondering if it's possible to build an expression column that ignores parts of the fields it draws from.

I've got my [Artist] field and I've got a [Track Credits] field where I put soloists and guests and what they've played. I'd like to construct a {Performer} expression column that puts the two together but only shows names and not what they've played. If the [Track Credits] field has a consistent structure (currently, it's "instrument - performer"), is it possible to have the expression constructer ignore everything prior to a certain character (i.e. the hyphen) and only display the name following?

I get the feeling this is WAY more complex than the expression language can handle, but maybe not. Failing that, has anyone else tried to construct a similar field and how did you think about doing it? Obviously it is easy to do it if I make separate fields for each type of performer, but, well, then that means breaking apart one tag and turning it into a bunch of others. (I like the [Track Credits] tag I've been using because it's flexible.)

Thanks for any and all advice...
Micah
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression column with subtraction
« Reply #1 on: August 23, 2011, 12:52:37 am »

listitem([track credits],1,/ - )

This will give you everything after the first " - "

More info:

ListItem - See here

Why the forward slash before the first space? - See the last of the three examples here ---> (link), which also contains a link to the overview which has yet more info.

EDIT:
This [track credits] field of yours... is it a list type field with lots of different "instrument - performer" entries per track? If it is, the above won't work, but we may be able to build on it...

-marko

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Expression column with subtraction
« Reply #2 on: August 23, 2011, 10:36:58 am »

listitem([track credits],1,/ - )

This will give you everything after the first " - "

More info:

ListItem - See here

Why the forward slash before the first space? - See the last of the three examples here ---> (link), which also contains a link to the overview which has yet more info.

EDIT:
This [track credits] field of yours... is it a list type field with lots of different "instrument - performer" entries per track? If it is, the above won't work, but we may be able to build on it...

-marko

Hi Marko --

First off, thanks very much for this. I really did not think it would be very possible. So yes, it is a bunch of different "instrument - performer" entries per track, but, say I just want the vocalist, I should be able to use something like "listitem([track credits],1,Vocals/ - )"?

Thanks again!
Micah
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression column with subtraction
« Reply #3 on: August 23, 2011, 01:09:49 pm »

If only it were that simple!! (although, with "Vocals" it might be)

First of all, you don't need to escape the space after "Vocals". Space is only ignored when it follows a comma.

listitem([track credits],1,Vocals - )
This will only work if "Vocals" is always the last item listed in your [track credits] field. Imagine your list of stuff in [track credits] is stored like so: Vocals - Rod;Guitar - Jane;Triangle - Freddy
The result of the above expression would be: "Rod;Guitar - Jane;Triangle - Freddy", when all you want is "Rod"

If you are also tracking the writer in your track credits field, then you may have a problem as it will always come after vocals in the list field. Try it first and see how you fare, you might be lucky.

You may have noticed that build 156 has added Regular Expressions. MrC is our resident RegEx Expert. This is in its infancy at the moment, but should firm up and settle down in a week or two. After that, I'm sure that this new feature will allow you to simply and quickly extract just the info you need from any given list type field.

MrC, correct me if I'm wrong :)

-marko.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression column with subtraction
« Reply #4 on: August 23, 2011, 02:55:24 pm »

Right.

With build 156 you can do this easily enough.  We could take the output of marko's expression:

   listitem([track credits],1, / vocals - )

and pass that to a regular expression to remove the remainder (I'm going to use the newer build's syntax, and will translate to 156 at the end):

   regex(listitem([track credits],1, / vocals - ), /#^([^;]+)#/,1)

But can we use regular expressions to do to it all?  When a list is treated as a string, MC presents a semicolon separated string, such as:

  base - sarah; drum - sally; guitar - sam; vocals - sue; vocoder - slim

So we simply search for "vocals - " followed by everything that is not a semicolon.
  
   regex([track credits], /#vocals - ([^;]+)#/,1)

Now I believe this would be:

   RegexSearch([track credits], /#vocals - ([^;]+)#/, 0)

in the .156 build.  I'll double check and correct if I'm wrong about the syntax.

In anycase, you can just take that output, and append whatever else you want, such as your [Artist].

   [Artist], RegexSearch([track credits], /#vocals - ([^;]+)#/, 0)

[edit: I corrected the last argument from 1 to 0, as in RegexSearch the capture number was zero-based, not one-based.]
Logged
The opinions I express represent my own folly.

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Expression column with subtraction
« Reply #5 on: August 23, 2011, 05:18:42 pm »

So what's the solution to the original problem?

I've got my [Artist] field and I've got a [Track Credits] field where I put soloists and guests and what they've played. I'd like to construct a {Performer} expression column that puts the two together but only shows names and not what they've played.

In other words, how can [Track Credits] be converted to another semicolon-delimited list of names without instruments? {Performer} could then be ListBuild(1, ;, [Artist], [regex expression])&datatype=[ list].

{Performer}, BTW, would also be very useful as a pane. I do that now, combining [Artist], [Members] and [Featuring], but all of those fields consist of names only.

Before getting too carried away with a regex solution, laerm may want to consider an alternative approach. The existing contents of [Track Credits] could easily be converted from "instrument - performer" to "performer\instrument." This would make it a nested list field. [Artist] could be added to such a list as "[Artist]\artist." The result is the list being sought, with the instrument preserved as the second level. This works well in a pane—expand a person to see what instruments they played. Where the same data needs to be presented in a flat list (e.g., in a Theatre View info panel), it can be reformatted by replacing '\' with ' - ' or ' • '.

I do this now for people associated with movies. I record [Producer], [Director], [Actors], etc., but also combine them all in [People] nested with their roles. The second level of the nest is "career" (i.e., producer, director, actor, etc.), and where career = actor, a third level shows "[Name]: [Role]." I find my [People] pane very useful in seeing and navigating movies related in any way by people.
Logged

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Expression column with subtraction
« Reply #6 on: August 23, 2011, 05:30:54 pm »

Hi guys --

First off, thanks heartily for three great, in-depth responses.

Now, more importantly, WHOA we can regex now?! Oh my. Now this, gentlemen, is truly something. ;D

OK, so MrC, I will go home tonight and play around with your regex start. That is excellent.
Rick, I will also consider moving that field to a nested list as your idea is excellent for future uses.
And Marko, thanks for getting the ball rolling. :)

FYI, I am getting my metadata for this field mostly from the foobar Discogs tagger plugin. http://www.foobar2000.org/components/view/foo_discogs
If I were more of a programming whiz, I'd try and write a similar plugin for MC. It's really an amazing little thing (when Discogs isn't changing their API every week, that is).

Thanks again. I will report back in a day or so with my findings. Beers for all!
Micah
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression column with subtraction
« Reply #7 on: August 23, 2011, 05:36:22 pm »

... and to add on rick.ca's point.  Think about your data first, and then build expressions to present as you wish.

Also, if you need to convert some fields, probably MC's expressions can help do it for you.
Logged
The opinions I express represent my own folly.

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Expression column with subtraction
« Reply #8 on: August 23, 2011, 05:42:15 pm »

... and to add on rick.ca's point.  Think about your data first, and then build expressions to present as you wish.

Also, if you need to convert some fields, probably MC's expressions can help do it for you.

Indeed. Now that I know I have the flexibility of regex, I can look at my data in a whole new light and what I'd like to do with it.

Field converting will be interesting...I think I will make another field and take all of the current track credits stuff and figure out how to alter it with an expression and regex. This is a good project for this week while my girlfriend is out of town. ;)

Thanks again...
Micah
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Expression column with subtraction
« Reply #9 on: August 23, 2011, 07:56:42 pm »

Quote
I think I will make another field and take all of the current track credits stuff and figure out how to alter it with an expression and regex.

Generally, this is the best practice anyway. If a field is filled by importing data from an external source (by any means), that data should be left as is. Even if data is typically imported once and never updated, you can never be sure this will always be the case. Keeping modifications separate will ensure they're never overwritten by updates. In most cases, the data can be changed or reformatted to the desired form using an expression. It's up to you whether that's done as needed (i.e., by using an expression in a column, pane, caption or info panel) or by creating a separate expression field. In some cases, that won't do the job completely—because you want to add data where none is provided, or correct data that's wrong or unsuitable (and must be fixed manually). In that case, add an "override" field for your manual additions and changes. An expression field can then take the override value, and if there isn't one, do the necessary conversion of the imported value. Not only is this safer and easier to maintain, it provides a complete record of where the data came from.

Also, if you need to convert some fields, probably MC's expressions can help do it for you.

I'm still hoping you'll enlighten us on the regex solution to this one...  ;)

In other words, how can [Track Credits] be converted to another semicolon-delimited list of names without instruments?
Logged
Pages: [1]   Go Up