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 07-11-2012, 04:50 PM   #1
Rob557
Enthusiast
Rob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-books
 
Posts: 45
Karma: 810
Join Date: Jul 2012
Device: Kobo
Calibre authors LN, FN to FN LN "swap_around_comma"

In a sub-library I have a large number of books where the "authors" field is the same as "author_sort" (i.e. LN, FN) and I was trying to figure out how to do a bulk metadata edit in order to reformat all the "authors" names to FN LN for overall library consistency.

The link "http://manual.calibre-ebook.com/template_lang.html" refers to the function "swap_around_comma(val)" but I couldn't figure out how to use it in the context of a bulk edit of the metadata.

I tried two approaches:
a) first tried setting up a custom user-defined column to get a re-formatted author name by using the above function in the template definition for the column when it is created (as suggested by the general approach of "using templates in custom columns" at the link "http://manual.calibre-ebook.com/template_lang.html"), and
b) also tried using "swap_around_comma" as a type of general expression within the context of a "search and replace" bulk metadata edit copying the authors column to a general user-defined text column.

In both cases above I was unable to figure out the correct syntax, and tried things like {authors:swap_around_comma()} and tried {swap_around_comma(authors)} and {swap_around_comma(LN,FN)}. Has anyone seen any further documentation on this function, or can provide the syntax for using this function in the context of either of the above approaches, or some alternative bulk edit approach?

Thanks ...Rob
Rob557 is offline   Reply With Quote
Old 07-12-2012, 02:28 AM   #2
unboggling
by the bootstraps
unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.
 
Posts: 1,052
Karma: 858115
Join Date: Jan 2011
Location: Southeast US
Device: PRS-T2, Nexus 7, KindleT, iPad1, Kindle3KB
Welcome to Mobile Read. Try the third-party plugin Quality Check, available through Preferences/Plugins. Click the Get New Plugins button on the bottom in Prefs/Plugins and look at uninstalled plugins. Install Quality Check.

Search for all books with the comma in authors. In Quick Search box at top type:
Code:
author:,
Select all those books. Two methods to proceed:

1. Use Quality Check, Fix menu, Swap Author command. Or (more complicated):

2. Use Edit Metadata in Bulk, Search and Replace Tab, regular expression mode to switch elements around the comma.

Search field: authors

Search for:
Code:
(.+), (.*)
Replace with:
Code:
\2 \1
Look at the test results. Click the save button, name it something like LN, FN --> FN LN.

Note: that will mess up any authors with ", Jr" after last name, but then you can fix those after searching for "author:Jr".

Last edited by unboggling; 07-12-2012 at 05:21 AM. Reason: detail re installing plugin
unboggling is offline   Reply With Quote
 
Enthusiast
Old 07-12-2012, 05:28 AM   #3
chaley
"chaley", not "charley"
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: 5,264
Karma: 821512
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by Rob557 View Post
I tried two approaches:
a) first tried setting up a custom user-defined column to get a re-formatted author name by using the above function in the template definition for the column when it is created (as suggested by the general approach of "using templates in custom columns" at the link "http://manual.calibre-ebook.com/template_lang.html"), and
b) also tried using "swap_around_comma" as a type of general expression within the context of a "search and replace" bulk metadata edit copying the authors column to a general user-defined text column.

In both cases above I was unable to figure out the correct syntax, and tried things like {authors:swap_around_comma()} and tried {swap_around_comma(authors)} and {swap_around_comma(LN,FN)}. Has anyone seen any further documentation on this function, or can provide the syntax for using this function in the context of either of the above approaches, or some alternative bulk edit approach?
It would be helpful if you tell us what didn't work. I tried both a) and b) and they worked except for books that have multiple authors.

To reinforce unboggling's comment: templates operate on all the authors at once. Using swap_around_comma() on a book with multiple authors such as "Blogs, Joe & Sneeze, Sam" will produce "Joe & Sneeze, Sam Blogs. The bulk metadata method overcomes the multiple author problem because it processes the authors one at a time.
chaley is offline   Reply With Quote
Old 07-12-2012, 05:36 AM   #4
Rob557
Enthusiast
Rob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-books
 
Posts: 45
Karma: 810
Join Date: Jul 2012
Device: Kobo
Quote:
Originally Posted by unboggling View Post
... Search for all books with the comma in authors ... Use Edit Metadata in Bulk, Search and Replace Tab, regular expression mode to switch elements around the comma:
Search field: authors
Search for: (.+), (.*)
Replace with: \2 \1
Look at the test results. ...
Hi unblogging, thank you for your greeting message.

I tried the bulk metadata edit approach using the search and replace parameters you suggested, and it worked great!

Per your caution on potential exceptions, the only additional steps that I took were:
a) first located and adjusted all authors names that contained more than one comma (I didn't know how to search for two commas in the Calibre search and so used a separate program outside of Calibre to list out all the author folder names shown in Windows Explorer and then used a character string test within Excel),
b) copied the metadata edit results to a test user-defined column prior to copying the results into the "author" field.

Thank you unboggling !
Rob557 is offline   Reply With Quote
Old 07-12-2012, 06:13 AM   #5
Rob557
Enthusiast
Rob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-books
 
Posts: 45
Karma: 810
Join Date: Jul 2012
Device: Kobo
syntax for using swap_around_comma(val) ?

Quote:
Originally Posted by chaley View Post
... I tried both a) and b) and they worked except for books that have multiple authors. ...
Hi chaley,
Thank you for confirming that you were able to get the template "swap_around_comma(val)" to work in the context of both approaches a) and b) as described above. (The issue with multiple authors can be resolved okay in different ways I guess.)

I was curious how you got swap_around_comma(val) to work, in terms of the specific use and syntax for each of the two approaches.

I had mentioned several examples for the syntax that I tried using but those did not seem to work.

The questions I was struggling with include:
i) does swap_around_comma(val) need to be enclosed in {};
ii) is "val" a general parameter to be replaced by something else;
iii) in bulk edit search and replace does it go in the "search for:" section;
iv) is the syntax different for the bulk edit approach compared to the template syntax when setting up a user-defined custom column with column type "Column build from other columns".
v) maybe seeing specific examples is the easiest way to see how it works?

I have been using Calibre for a relatively short period of time but it is really impressive open source software that particularly Kovid Goyal, and all of you, have helped to create.
Rob557 is offline   Reply With Quote
Old 07-12-2012, 06:35 AM   #6
chaley
"chaley", not "charley"
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: 5,264
Karma: 821512
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by Rob557 View Post
The questions I was struggling with include:
i) does swap_around_comma(val) need to be enclosed in {};
Depends on whether you are using single function mode, template program mode, or general program mode. The first two require the braces. The third does not use braces.
Quote:
ii) is "val" a general parameter to be replaced by something else;
Yes, but the replacement is automatic in single function mode. "Val" is replaced with the value of the field named before the colon. In the other two modes you must explicitly provide a value. This difference is discussed in the template program mode documentation.
Quote:
iii) in bulk edit search and replace does it go in the "search for:" section;
To use template functions in bulk search/replace, you must select "template" as the source field. A box will appear for you to enter the desired template. Any of the program modes can be used, although entering general program mode templates into that box is a pain.

The search expression searches the result of evaluating the template.
Quote:
iv) is the syntax different for the bulk edit approach compared to the template syntax when setting up a user-defined custom column with column type "Column build from other columns".
No, it isn't.
Quote:
v) maybe seeing specific examples is the easiest way to see how it works?
You can see examples of using swap_around_comma in single function mode and template program mode in the thread containing this post.
chaley is offline   Reply With Quote
Old 07-12-2012, 07:12 AM   #7
Rob557
Enthusiast
Rob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-books
 
Posts: 45
Karma: 810
Join Date: Jul 2012
Device: Kobo
Quote:
Originally Posted by chaley View Post
... To use template functions in bulk search/replace, you must select "template" as the source field. ... You can see examples of using swap_around_comma in single function mode and template program mode in the thread containing this post.
Quote:
Originally Posted by chaley View Post
For completeness, here is a template in template program mode that works with both FN LN and LN, FN for most names. This template will fail for author names like Joe Blogs, PhD, which is one reason it isn't the default.
Code:
{authors:'contains($, ',', swap_around_comma($), $)'}
Thank you chaley. In the bulk metadata edit's search and replace screen, with {template} selected as the search field, {authors:'contains($, ',', swap_around_comma($), $)'} in the template field and a temporary user-defined text column as my destination field, the conversion from "last-name, first-name" to "first-name last-name" worked great.

Thanks again for your help on this, and the other alternative provided by unboggling !

The only lingering question related to this process is whether there is a search technique within Calibre to identify author names that contain two commas, so that complication can be more simply resolved prior to running the bulk edit?
Rob557 is offline   Reply With Quote
Old 07-12-2012, 07:16 AM   #8
unboggling
by the bootstraps
unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.
 
Posts: 1,052
Karma: 858115
Join Date: Jan 2011
Location: Southeast US
Device: PRS-T2, Nexus 7, KindleT, iPad1, Kindle3KB
Quote:
Originally Posted by Rob557 View Post
The only lingering question related to this process is whether there is a search technique within Calibre to identify author names that contain two commas, so that complication can be more simply resolved prior to running the bulk edit?
Ah, I like that question, was wondering about that myself earlier.
unboggling is offline   Reply With Quote
Old 07-12-2012, 07:23 AM   #9
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,224
Karma: 1334002
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
This would work:
Code:
authors:"~.*,.*,"
kiwidude is offline   Reply With Quote
Old 07-12-2012, 07:33 AM   #10
Rob557
Enthusiast
Rob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-booksRob557 has learned how to read e-books
 
Posts: 45
Karma: 810
Join Date: Jul 2012
Device: Kobo
Quote:
Originally Posted by kiwidude View Post
This would work:
Code:
authors:"~.*,.*,"
Works great ! Thanks kiwidude !
Rob557 is offline   Reply With Quote
Old 07-12-2012, 07:50 AM   #11
unboggling
by the bootstraps
unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.
 
Posts: 1,052
Karma: 858115
Join Date: Jan 2011
Location: Southeast US
Device: PRS-T2, Nexus 7, KindleT, iPad1, Kindle3KB
Quote:
Originally Posted by kiwidude View Post
This would work:
Code:
authors:"~.*,.*,"
Yes, thanks. It works for titles too.
I wonder why none of my regex lists show the tilde. What specifically does it mean?
unboggling is offline   Reply With Quote
Old 07-12-2012, 08:04 AM   #12
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,224
Karma: 1334002
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
In this particular case it tells calibre that what follows is to be treated as a regular expression.
kiwidude is offline   Reply With Quote
Old 07-12-2012, 08:07 AM   #13
chaley
"chaley", not "charley"
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: 5,264
Karma: 821512
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by kiwidude View Post
This would work:
Code:
authors:"~.*,.*,"
Do note that this regexp will find books with any author having a name containing more than one comma. It will not find books with multiple authors, each containing a comma. For example, it will find "Blogs, PhD, Joe" but it will not find "Blogs, Joe & Sneeze, Sam". Depending on what you are doing, this distinction will matter.
Quote:
Originally Posted by unboggling View Post
I wonder why none of my regex lists show the tilde. What specifically does it mean?
It tells search that what follows is a regular expression. It is similar to the "=" that tells search that what follows must be a complete match, and the period that tells search that what follows is a hierarchical match.
chaley is offline   Reply With Quote
Old 07-12-2012, 08:53 AM   #14
unboggling
by the bootstraps
unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.unboggling ought to be getting tired of karma fortunes by now.
 
Posts: 1,052
Karma: 858115
Join Date: Jan 2011
Location: Southeast US
Device: PRS-T2, Nexus 7, KindleT, iPad1, Kindle3KB
Quote:
Originally Posted by chaley View Post
Do note that this regexp will find books with any author having a name containing more than one comma. It will not find books with multiple authors, each containing a comma. For example, it will find "Blogs, PhD, Joe" but it will not find "Blogs, Joe & Sneeze, Sam". Depending on what you are doing, this distinction will matter.
I see the distinction.

Quote:
Originally Posted by chaley View Post
It tells search that what follows is a regular expression. It is similar to the "=" that tells search that what follows must be a complete match, and the period that tells search that what follows is a hierarchical match.
Quote:
Originally Posted by kiwidude View Post
In this particular case it tells calibre that what follows is to be treated as a regular expression.
Thank you both. I knew I'd read about tilde somewhere. Turns out I'd seen it in the manual just last week, under search interface for using regex in quick search. How fast I forget...

Last edited by unboggling; 07-12-2012 at 08:59 AM.
unboggling is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PRS-T1 Sony "Collections" vs Calibre "Series" ted13b Sony Reader 3 02-20-2012 09:46 AM
Getting calibre to detect "Prologue" and "Epilogue" for TOC sherman Calibre 2 09-20-2010 02:21 AM
UK Daily Telegraph "Ebooks will make authors soulless, just like their product" Sparrow News 46 09-18-2009 06:55 PM


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


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