INTERACT FORUM

Please login or register.

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

Author Topic: Help with expression - Convert List to nested List  (Read 584 times)

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Help with expression - Convert List to nested List
« on: July 13, 2019, 04:37:43 am »

Hello Forum,

i need some help with an expression, maybe there are better ways to do it.
Essentially I want to convert a list to a nested list

Custom Field SubGenre (List): Includes the Sub Genres like Alternative Rock, Stoner Rock etc.

In another field (e.g. SubGenre Tree) i want to create a tree based on the SubGenre (e.g. Rock\Hard Rock\Stoner Rock). This means "Stoner Rock" has to be replaced by Rock\Hard Rock\Stoner Rock. I tried the isequal function but it obviously won't work because after the first match it won't check any further.

ifelse(
isequal([SubGenre], Stoner Rock, 7), Rock\Hard Rock\Stoner Rock,
isequal([SubGenre], Hard Rock, 7), Rock\Hard Rock,
isequal([SubGenre], Stoner Metal, 7), Rock\Metal\Stoner Metal,
isequal([SubGenre], Metal, 7), Rock\Metal
)

Thanks for your help!
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8943
Re: Help with expression - Convert List to nested List
« Reply #1 on: July 14, 2019, 06:02:05 am »

I'm not 100% certain, but my gut tells me you are not going to be able to find a fool-proof, one-stop-shop way to achieve this.

Here's what I did just now as a quick test for you, that might get you started...

I created the new field that will be a list type field, but, to start with, will be a standard, string type field, as this makes editing easier.

I tested with one file. We will call the new field [New Field] below, replace that with whatever you named yours :)

In the search bar up the top left, I entered [sub genre]="rock"
I selected one of those files. It contained "mellow rock; alternative rock; rock ballad; soft rock"
In the tag window, click the New Field to edit, type =[sub genre] and press enter. This puts the semi-colon delimited string in your new field.

Click the New Field to edit again, and paste the following expression:
Code: [Select]
=replace([New Field],/;/ ,/;/ Rock\)
Change "New Field" to your chosen field name, and press enter.
Your New Field will now contain:
"mellow rock; Rock\alternative rock; Rock\rock ballad; Rock\soft rock"

Go back to the field manager and change your new field to data type "List" and edit type "List"

Back at your workspace, you will see a problem...

We are replacing the semi-colon with the heirarchy parent item, and, as the 1st item does not have a preceding semi-colon, it gets left hanging.
I don't have a solution for that.

I haven't tested going three levels deep (reminds me of Inception ;)) but I could imagine that getting exponentially more complex depending on the consistency of the data that is in your New Field.

Have a mess around with that anyway and see if you make any headway.

-marko.

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Help with expression - Convert List to nested List
« Reply #2 on: July 14, 2019, 08:07:29 am »

Does [SubGenre] tag have one item per file or many values like Hard Rock;Stoner Rock ? Could you give example meta data for one file?
Logged

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Re: Help with expression - Convert List to nested List
« Reply #3 on: July 16, 2019, 12:15:40 pm »

Thanks to both of you for your reply and sorry for my late reply.

@lepa: Exactly this is my problem with the ifelse expression i posted above. One file could have many values.

@marko: I have to check your suggestion - currently i don't think this is the solution - maybe my post was a little bit misleading.

My current setup is as following:
User defined field "Sub-Genre" - List field where i maintain the genre information.
For example:
Rock\Alternative Rock; Rock\Grunge; Rock\Metal\Thrash Metal - this way i see a nice tree of the subgenres in MC.
The downside of this method, maintainance is rather cumbersome.

What i want to achieve:
1. User defined field where I just have to add e.g. Alternative Rock
2. Another user defined field which automatically (based on an predefined expression) shows the complete Genre Tree, in this case Rock\Alternative Rock.

Example
Artist: Mastodon
Album: Emperor of Sand

In User defined Field i add the values: Progressive Metal; Sludge Metal; Stoner Metal (in best case from a predefined List with check boxes)
The other user defined Field shows automatically:
Rock\Metal\Progressive Metal
Rock\Metal\Sludge Metal
Rock\Metal\Stoner Metal


Thanks again for support.


Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Help with expression - Convert List to nested List
« Reply #4 on: July 17, 2019, 07:55:45 am »

Don't have time right now to dig deeper but if you do it like in your example you need to take out the ifelse and do every is equals inside own if decisions

IfElse(IsEqual([SubGenre],Metal,7),If(IsEqual([SubGenre],Stoner Metal,7),Rock\Metal\Stoner;,)If(IsEqual([SubGenre],Trash Metal,7),Rock\Metal\Trash,Rock\Metal;,)Rock\Metal;,IsEqual([SubGenre],Hard Rock,7),If(IsEqual([SubGenre],Stoner Rock,7),Rock\Hard Rock\Stoner Rock;,)If(IsEqual([SubGenre],Alternative Rock,),Rock\Hard Rock\Alternative Rock;,)Rock\Hard Rock;)

Something like this and you need to expand it for more subgenres. Not sure how will MC behave with list items with same names so would you get Rock\Hard Rock two times there or will MC ignore if the same thing is inserted twice

So it will get quite complicated to read. I'm sure there is more elegant way to do this also maybe with regex. But sorry I need to rush now as I'm already late.. also no guarantee with above code I just put something up in a hurry..
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1570
Re: Help with expression - Convert List to nested List
« Reply #5 on: July 17, 2019, 05:58:26 pm »

Are you missing the simple?

I'd do this with a set of several fields & a display field.

1. Base genre field (Rock)
2. Subgenre (Alternative Rock)
3. Final subtype (Grunge)

The display field is then set to fill from each if not empty.

Main drawback to this approach is that editing is a little cumbersome if you want to use the dropdown list.

A marginal refinement to the system is to use separate final subtype fields for each subgenre.
With this, I just match the non-empty final subtype field.
Logged
Pages: [1]   Go Up