INTERACT FORUM

Please login or register.

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

Author Topic: Flatten nested Keywords for display - expression help  (Read 2246 times)

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3123
Flatten nested Keywords for display - expression help
« on: December 14, 2010, 08:58:08 am »

I like to use nested Keywords in my photos for organization but for display I would like to just list the "childmost" part.  For example, instead of displaying "People\Our Family\Craig;People\Fred" I would like to display just "Craig;Fred".  I see the ListItem() function but don't see any way to "loop" through all the list items? 
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: Flatten nested Keywords for display - expression help
« Reply #1 on: December 14, 2010, 11:00:13 am »

I've struggled with this one too, without success.

I think that what we need is an expression that will parse the field for each instance of "\...;" and return the characters inbetween.

-marko

lise

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 946
Re: Flatten nested Keywords for display - expression help
« Reply #2 on: December 14, 2010, 01:23:11 pm »

I've been at that for the last year, and couldn't come up with anything. I wanted to view panes with the various parents so Finishing\antiquing\glazing could be viewed as three panes: Finishing    Antiquing   Glazing
I tried looping, listing things before a bracket, nothing worked.
The only way to get what I want is by using 3 fields, which is great but more of a hassle when tagging. So much easier to just tag everything as keywords. When the day comes where we could explode the nested elements I'll be one happy camper.
Logged
A wise man once said don't count your years, but make your years count. Or was it beers?

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Flatten nested Keywords for display - expression help
« Reply #3 on: December 14, 2010, 06:02:29 pm »

It must be time for another Smartlist Smackdown...

Here's my submission. It only handles up to four terms of up to four branches each, but it works. I offer it only as a challenge for the masters to come up with something more elegant. ;D

Code: [Select]
ListBuild(1,;,
If(IsEmpty(ListItem(ListItem([Keywords],0,;),1,\)),ListItem(ListItem([Keywords],0,;),0,\),
If(IsEmpty(ListItem(ListItem([Keywords],0,;),2,\)),ListItem(ListItem([Keywords],0,;),1,\),
If(IsEmpty(ListItem(ListItem([Keywords],0,;),3,\)),ListItem(ListItem([Keywords],0,;),2,\),
ListItem(ListItem([Keywords],0,;),3,\)))),
If(IsEmpty(ListItem(ListItem([Keywords],1,;),1,\)),ListItem(ListItem([Keywords],1,;),0,\),
If(IsEmpty(ListItem(ListItem([Keywords],1,;),2,\)),ListItem(ListItem([Keywords],1,;),1,\),
If(IsEmpty(ListItem(ListItem([Keywords],1,;),3,\)),ListItem(ListItem([Keywords],1,;),2,\),
ListItem(ListItem([Keywords],1,;),3,\)))),
If(IsEmpty(ListItem(ListItem([Keywords],2,;),1,\)),ListItem(ListItem([Keywords],2,;),0,\),
If(IsEmpty(ListItem(ListItem([Keywords],2,;),2,\)),ListItem(ListItem([Keywords],2,;),1,\),
If(IsEmpty(ListItem(ListItem([Keywords],2,;),3,\)),ListItem(ListItem([Keywords],2,;),2,\),
ListItem(ListItem([Keywords],2,;),3,\)))),
If(IsEmpty(ListItem(ListItem([Keywords],3,;),1,\)),ListItem(ListItem([Keywords],3,;),0,\),
If(IsEmpty(ListItem(ListItem([Keywords],3,;),2,\)),ListItem(ListItem([Keywords],3,;),1,\),
If(IsEmpty(ListItem(ListItem([Keywords],3,;),3,\)),ListItem(ListItem([Keywords],3,;),2,\),
ListItem(ListItem([Keywords],3,;),3,\)))))&datatype=[list]

The code includes line breaks for readability. They don't seem to impair function. And because I wouldn't believe me if I were you—a screen shot... ;)

[Edit:] Oops. Forgot the &datatype=[li st] at the end
Logged

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3123
Re: Flatten nested Keywords for display - expression help
« Reply #4 on: December 15, 2010, 08:09:14 am »

It must be time for another Smartlist Smackdown...

Thanks for that and it probably would work for me as I think I only go 3 levels deep but that is one ugly expression!  :)
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Flatten nested Keywords for display - expression help
« Reply #5 on: December 15, 2010, 02:13:05 pm »

Quote
Thanks for that and it probably would work for me as I think I only go 3 levels deep but that is one ugly expression!

It's easily modified to handle any number of terms and levels. What it lacks in beauty it makes up for in symmetry. ;)
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: Flatten nested Keywords for display - expression help
« Reply #6 on: December 16, 2010, 02:20:38 am »

That's pretty good rick, nice work there.

Gappie would really appreciate that too, does anyone know where he's got to? I've not seen him around for a while now...

-marko.

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Re: Flatten nested Keywords for display - expression help
« Reply #7 on: December 16, 2010, 03:13:44 am »

thank you marko for the mail... i like expressions. and i think that ricks solution is as elegant as you can get with the tools available now. nice.

there is also one simple solution with a different outcome (and something i use for places) , but some people might like that. to take cncb's example, it will add people and our family to the list, but also animals, dogs, beside ficky and brutus.
the solution is getting very simple then.
Code: [Select]
Replace([keywords],\,;)&datatype=[list] :)
gab
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Flatten nested Keywords for display - expression help
« Reply #8 on: December 16, 2010, 04:58:03 am »

It's nice I found a solution this time, but what can I do about this evil voice in my head that keeps saying, "there must be a way to do this..." ;D
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Re: Flatten nested Keywords for display - expression help
« Reply #9 on: December 16, 2010, 06:27:58 am »

It's nice I found a solution this time, but what can I do about this evil voice in my head that keeps saying, "there must be a way to do this..." ;D
ok i bite.
would this not do the same?
Code: [Select]
ListBuild(1,;,Listitem(listitem([Keywords],0,;),math(listcount(Listitem([keywords],0,;),\)-1),\),
Listitem(listitem([Keywords],1,;),math(listcount(Listitem([keywords],1,;),\)-1),\),
Listitem(listitem([Keywords],2,;),math(listcount(Listitem([keywords],2,;),\)-1),\),
Listitem(listitem([Keywords],3,;),math(listcount(Listitem([keywords],3,;),\)-1),\))&datatype=[list]
:)
gab
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Flatten nested Keywords for display - expression help
« Reply #10 on: December 16, 2010, 09:59:14 am »

Indeed it does. Well done!

This would be a great example for the "list" section of the expressions wiki. Or maybe the "elegant" section. ;)
Logged
Pages: [1]   Go Up