Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-16-2017, 11:20 PM   #1
PERSISTENCE
Member
PERSISTENCE began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2010
Device: NONE
Need help! Template to shorten series name

Hi - I need help to shorten the series name using a template/plugboard!

I want to create a custom column using the following book title - but I am having trouble shortening the series name:
(essentially, I want to use (approx) the first 2 words of the series name)
[SHORTENED SERIES NAME] - series index# - book title

I want to shorten the series name in a particular way - basically it would require 2 steps:
a) I want to strip off the first word (if it is an article - a/an/the)
I can do this with a custom column/using template syntax:
#stripped_series. Template: {series:re(^(A|The|An)\s+,)||}

b) then I want to use the first 2 words (approx) of the series name
BUT THIS IS WHERE I GET STUCK...

I want to use the first 2 words of the series name BUT if the following words appear, they should be included but not counted as one of the '2' words:
any article (a/an/the), conjunction (and/or/&), preposition (of, from..etc), AND any word ending in '.' (full stop) ie any short form like Mr., St. etc.

EXAMPLES:
1) Lord of the Rings and other Tolkien Stories WOULD APPEAR AS
Lord of the Rings
2) Kincaid & James WOULD APPEAR AS Kincaid & James
3) Mr.Fox & Mrs.Chicken mysteries WOULD APPEAR AS Mr. Fox & Mrs. Chicken
4) D.I. Helen Grace series WOULD APPEAR AS D.I.Helen Grace

Can anyone help me with a template that will perform STEP B? (I tried using python syntax strip.string_variable to no avail...I'm just stumped)....

Thanks so much....
PERSISTENCE
PERSISTENCE is offline   Reply With Quote
Old 01-17-2017, 04:34 AM   #2
MerlinMama
Addict
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 355
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Clara HD
Please don't start multiple threads on the same subject. Bump it up if you want it more visible.
MerlinMama is offline   Reply With Quote
Old 01-17-2017, 12:40 PM   #3
chaley
CC Android & calibre dev
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: 8,724
Karma: 2655880
Join Date: Jan 2010
Location: France
Device: Many android devices
The only practical way to do what you want is to use a loop, which the template language does not support. You can do it by writing a custom template function in python, the content of I leave as an exercise for the reader.
chaley is offline   Reply With Quote
Old 01-21-2017, 01:27 AM   #4
PERSISTENCE
Member
PERSISTENCE began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2010
Device: NONE
Hi chaley -
Sorry, I guess I'm too much of a noob to fully understand your advice. I'd be glad to do this, but need some help..could you help me get started (with syntax)? If I have some assistance to get started I can go from there...I just need a helping hand.
Thanks, in advance...I'll await word.
-Persistence
PERSISTENCE is offline   Reply With Quote
Old 01-21-2017, 07:08 AM   #5
chaley
CC Android & calibre dev
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: 8,724
Karma: 2655880
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by PERSISTENCE View Post
Hi chaley -
Sorry, I guess I'm too much of a noob to fully understand your advice. I'd be glad to do this, but need some help..could you help me get started (with syntax)? If I have some assistance to get started I can go from there...I just need a helping hand.
Thanks, in advance...I'll await word.
-Persistence
I am traveling and cannot do much for a few weeks, and in any event I don't want to write the function for you.

Custom functions are written in pure python, using the editor available from Preferences / Template Functions. The dialog provides some help for setting things up.

Here is a sample template function that returns the first word of a series if there is one, the empty string otherwise.
Code:
def evaluate(self, formatter, kwargs, mi, locals):
	series = mi.get('series')
	if series:
		return series.split()[0]
	return ''
chaley is offline   Reply With Quote
Old 01-28-2017, 08:36 AM   #6
PERSISTENCE
Member
PERSISTENCE began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2010
Device: NONE
Hi Charles -
I wouldn't want you to write the procedure for me - but I am asking for your help (when you have time). I am a physician. I studied programming years ago. I don't know python syntax, but I am familiar with the process of writing a short program.
I know that I'll need to include a loop that evaluates each word in the series starting with the first word, and 'decides' whether to discard /keep the word. The loop would terminate after collecting /keeping 3 words (or when there are no more words to evaluate), whichever comes first.
I saw your example but it lost me from the first line, sadly...likely because of my lack of familiarity with python syntax. Python documentation was of little help. I just need some help to explain what each line does in your example (or if possible, in an example that relates fairly closely to what I need to do) - so I can hopefully mix/match and create a function that does what I need.

I would be grateful for any help you can offer.
Thanks for taking the time to reply to me.
Persistence
PERSISTENCE is offline   Reply With Quote
Old 01-28-2017, 10:00 AM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 52,300
Karma: 47192023
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Aura H2O, Sony PRS-650, Sony PRS-T1, nook STR, iPad 4, iPhone 5
Using your Lord of the Rings example, what you are asking for would come out Lord of the.

The solution is to put in the series name you want and create a custom column to put in the full series name.
JSWolf is offline   Reply With Quote
Reply

Tags
calibre, custom column, plugboard, series, template

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Truncate series name using template -- Help!! (use first 3 words) PERSISTENCE Library Management 0 01-14-2017 05:17 AM
Calibre Template and Series sehlat Calibre 4 09-16-2013 11:21 AM
Save Template, {series} etc Always Empty dbareis Library Management 13 07-01-2013 07:27 PM
How to shorten device filename with series info? Larla Library Management 16 01-08-2012 01:22 PM
save file template for series bucsie Calibre 2 11-08-2010 02:07 AM


All times are GMT -4. The time now is 03:01 PM.


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