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 01-30-2014, 06:22 PM   #1
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Looking for how to create a custom column based on a tag

I would like to create a custom column that works this way:

If a book has a specific tag (in this case "First"), make the column that tag name.
Otherwise, make it the series name if one exists.
Otherwise, make it the string "Uncategorized".

I know how to do all of this except for checking for a specific tag on a book that might have more then one tag.

{:'first_non_empty(field('tag'), field('Series'),'Uncategorized')'}

I need to replace field('tag') with something that will look for the specific tag, but I have no idea what to put in instead.

Any advice or help would be appreciated.

Thanks.
kaufman is offline   Reply With Quote
Old 01-30-2014, 06:50 PM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
http://manual.calibre-ebook.com/temp...-not-found-val

Quote:
str_in_list(val, separator, string, found_val, not_found_val)
str_in_list(val, separator, string, found_val, not_found_val) – treat val as a list of items separated by separator, comparing the string against each value in the list. If the string matches a value, return found_val, otherwise return not_found_val. If the string contains separators, then it is also treated as a list and each value is checked.

use "," as separator, val will be field('tags') and you want to search for string "First", then return found_val "First". not_found_val should return empty "" which first_non_empty should skip over, I think.

Personally, I think you should use general program mode for this:

Code:
program:
	first_non_empty(
		str_in_list(
			field('tags'),
			",",
			"First",
			"First",
			""
		),
		field('series'),
		"Uncategorized"
	)
eschwartz is offline   Reply With Quote
Advert
Old 01-30-2014, 06:51 PM   #3
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Quote:
Originally Posted by eschwartz View Post
http://manual.calibre-ebook.com/temp...-not-found-val

using str_in_list(val, separator, string, found_val, not_found_val)

use "," as separator, val will be field('tags') and you want to search for string "First", then return found_val "First". not_found_val should return empty "" which first_non_empty should skip over, I think.

Personally, I think you should use general program mode for this:

Code:
program:
	first_non_empty(
		str_in_list(
			field('tags'),
			",",
			"First",
			"First",
			""
		),
		field('series'),
		"Uncategorized"
	)
Thanks, this look very helpful. How do I go about using a program mode?
kaufman is offline   Reply With Quote
Old 01-30-2014, 08:01 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,046
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by kaufman View Post
Thanks, this look very helpful. How do I go about using a program mode?
That is it (the words set that)
Just paste it into the rule
theducks is offline   Reply With Quote
Old 01-30-2014, 08:06 PM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by kaufman View Post
Thanks, this look very helpful. How do I go about using a program mode?
http://manual.calibre-ebook.com/temp...l-program-mode

the "program:" at the beginning set the interpreter to use general program mode, which is why I included it.

Much more readable this way, isn't it?

Last edited by eschwartz; 01-30-2014 at 08:10 PM.
eschwartz is offline   Reply With Quote
Advert
Old 01-30-2014, 10:48 PM   #6
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Quote:
Originally Posted by eschwartz View Post
http://manual.calibre-ebook.com/temp...l-program-mode

the "program:" at the beginning set the interpreter to use general program mode, which is why I included it.

Much more readable this way, isn't it?
Thanks for the info. This worked perfectly. I was thrown off originally because I was reading you post on my phone.
kaufman is offline   Reply With Quote
Old 02-10-2014, 02:20 PM   #7
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
One more question.

As suggested, I am using this:

str_in_list(
field('tags'),
",",
"First",
"First",
""
),

as part of my column definition. Is there a way to search for the first tag that doesn't match a specific substring. I have a bunch of tags that start with "FiS-", and I would like to get the first tag that isn't one of them. Something like


str_not_in_list(
field('tags'),
",",
"FiS-*",
##Found Tag##,
""
),

Is there some way to do that?

Thanks.
kaufman is offline   Reply With Quote
Old 02-11-2014, 12:52 AM   #8
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Using list_difference() [see here]:
Quote:
list_difference(list1, list2, separator) – return a list made by removing from list1 any item found in list2, using a case-insensitive compare. The items in list1 and list2 are separated by separator, as are the items in the returned list.
PHP Code:
list_difference(
    
field('tags'),
    
"comma,separated,list,of,excluded,tags",
    
","

will return a new list, that contains only the items in list1 (tags field) that are not excluded using list2 ("comma,separated,list,of,excluded,tags")

So try this:
PHP Code:
program:

str_in_list(
    
list_difference(
        
field('tags'),
        
"comma,separated,list,of,excluded,tags",
        
","
    
),
    
",",
    
"First",
    
"First",
    
""


It appears that the "PHP" BBCode is better than the "CODE" BBCode for this CODE.
eschwartz is offline   Reply With Quote
Old 02-11-2014, 09:33 AM   #9
kaufman
Calibre Companion Fanatic
kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.kaufman ought to be getting tired of karma fortunes by now.
 
kaufman's Avatar
 
Posts: 873
Karma: 1088610
Join Date: Nov 2006
Device: Galaxy Note 4, Kindle Voyage
Excellent, thanks. One question:

Is there any way to use a regex string in the "comma,separated,list,of,excluded,tags" so that I don't have to enumerate each one. I have about 10 of them, and I add new ones occasionally as well. They all start with "FiS-". I tried "FiS-.*" and that didn't work.

Thanks for all the help.

Last edited by kaufman; 02-11-2014 at 10:42 AM.
kaufman is offline   Reply With Quote
Old 02-11-2014, 02:28 PM   #10
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
list comparisons do not accept regexes.

Try using

list_re() [see here]:

Quote:
list_re(src_list, separator, search_re, opt_replace) – Construct a list by first separating src_list into items using the separator character. For each item in the list, check if it matches search_re. If it does, then add it to the list to be returned. If opt_replace is not the empty string, then apply the replacement before adding the item to the returned list.
Using a "^" to match at the start of string (each tag is evaluated as a string in turn) and the negative lookahead (?!matched-regex-to-ignore) we get:

PHP Code:
program:

list_re(
    
field('tags'),
    
',',
    
'^(?!send to .*)',
    
''

So the whole program will look like:

PHP Code:
program:

str_in_list(
    
list_re(
        
field('tags'),
        
",",
        
"^(?!send to .*)",
        
""
    
),
    
",",
    
"First",
    
"First",
    
""

list_re() does not accept a list of regexes, so you must use regex (either|or) for multiple regexes.

Last edited by eschwartz; 02-11-2014 at 02:36 PM.
eschwartz is offline   Reply With Quote
Old 02-12-2014, 11:15 AM   #11
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,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You could also use list_re to create a sublist of the source, then list difference to see if the source contains any other elements.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM
Automatically tag based on column info? Iocane Library Management 3 09-10-2012 12:40 PM
Y/N custom column in Tag Browser? matthewdeans Calibre 15 08-12-2011 02:01 PM
create custom format column blaubach Calibre 12 09-17-2010 03:22 PM


All times are GMT -4. The time now is 06:14 PM.


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