Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-20-2021, 02:35 AM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: Strcat matching

Currently, I have a column icon template like this:

Code:
program: 
   f = field('#taglike');
  strcat
   (    contains(f, "^foobar|foo bar$", 'foobar.png:', ''), 
    contains(f, "foo", 'foo.png:', ''), 
    contains(f, "bar", 'bar.png:', ''), 
    contains(f, "test", 'test.png:', ''), 
   )
It shows icons for whatever values are in the column, e.g. "foo, test"returns "foo.png:test.png"

However, how would I display an icon if the values do not match any existing ones? e.g.:

Value: Unknown
Results: Unknown.png

Value: Unknown, Undefined
Results: Unknown.png

Value: Unknown, foobar
Results: foobar.png

ownedbycats is offline   Reply With Quote
Old 03-20-2021, 05:34 AM   #2
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,194
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
does the below template do what you want?

Code:
program:
    f = field('#taglike');
    icons = '';
    sep = ':';
    for keyword in 'foo,bar,test':
        val = contains(f, keyword, strcat(keyword, '.png'), '');
        if val then
            icons = list_union(icons, val, sep)
        fi
    rof;
    ifempty(icons, 'unknown.png')

Last edited by capink; 03-20-2021 at 06:10 AM.
capink is offline   Reply With Quote
Advert
Old 03-20-2021, 05:27 PM   #3
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Not quite though I will save that if it comes in useful for something else. The problem is that a lot of my icons don't exactly match the keywords, e.g.

Code:
contains(f, "^Some Movie|Some Other Movie$", 'Film.png:', ''), 
contains(f, "One Entry of a Game Series", 'iconforseries.png:', ''),
ownedbycats is offline   Reply With Quote
Old 03-20-2021, 06:14 PM   #4
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,194
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Code:
program:
    f = field('#taglike');
    icons = '';
    sep = ':';
    icon_expression = 'film.png=^Some Movie|Some Other Movie$,iconforseries.png=One Entry of a Game Series';
    for item in icon_expression:
        icon = re(item, '(.+)=(.+)', '\1');
        expression = re(item, '(.+)=(.+)', '\2');
        val = contains(f, expression, icon, '');
        if val then
            icons = list_union(icons, val, sep)
        fi
    rof;
    ifempty(icons, 'unknown.png')
capink is offline   Reply With Quote
Old 03-20-2021, 06:25 PM   #5
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I will try that.

Another thing I thought of: perhaps I could change my existing rule to a non-composed rule (which will stop other rules after it) and make a second rule saying "if field is populated, put unknown.png."
ownedbycats is offline   Reply With Quote
Advert
Old 03-20-2021, 07:11 PM   #6
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,410
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I will try that.

Another thing I thought of: perhaps I could change my existing rule to a non-composed rule (which will stop other rules after it) and make a second rule saying "if field is populated, put unknown.png."
No, there is no rule condition that can query if any previous rule has succeeded.

Regarding your original question, a small change to @capink's suggestion might be easier for you to use. Something like
Code:
    if 'Some Movie|Some Other Movie' in f then icons = list_union(icons, 'film.png', sep) fi;
    if 'One Entry of a Game Series' in f then icons = list_union(icons, 'iconforseries.png', sep) fi;
# and on and on
    ifempty(icons, 'unknown.png')
chaley is offline   Reply With Quote
Old 03-20-2021, 08:46 PM   #7
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,410
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Code:
program:
    f = field('#taglike');
    icons = '';
    sep = ':';
    icon_expression = 'film.png=^Some Movie|Some Other Movie$,iconforseries.png=One Entry of a Game Series';
    for item in icon_expression:
        icon = re(item, '(.+)=(.+)', '\1');
        expression = re(item, '(.+)=(.+)', '\2');
        val = contains(f, expression, icon, '');
        if val then
            icons = list_union(icons, val, sep)
        fi
    rof;
    ifempty(icons, 'unknown.png')
FWIW this is a good place to use list_split(). Without testing it, the for loop could be rewritten as
Code:
    for item in icon_expression:
        list_split(item, '=', 'part');
        if part_1 in f then
            icons = list_union(icons, part_0, sep)
        fi
    rof;
chaley is offline   Reply With Quote
Old 03-20-2021, 10:15 PM   #8
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thank you
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Normal" template inside GPM template ownedbycats Library Management 20 12-02-2020 09:40 PM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
Ungreedy matching in S&R BobC Editor 4 01-18-2014 01:31 PM
Better matching/scanning lbutlr Calibre 3 08-04-2010 03:44 PM
Matching Light for Kobo dixieknits Kobo Reader 2 07-19-2010 02:50 AM


All times are GMT -4. The time now is 02:44 PM.


MobileRead.com is a privately owned, operated and funded community.