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 07-26-2011, 03:21 PM   #1
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
[Old Thread] Regex "FN LN" to "LN, FN" & reverse?

I need to learn how to switch "FN LN" to "LN, FN" and back. Does anyone have those regex's handy? Could this be added as a function to the search/replace dialogue in regex mode?

Also, is there a list anywhere of useful regexs? (It would be great as a sticky.) It's time I learn and incorporate them.

I love calibre and thank you developers for all the work
unboggling is offline   Reply With Quote
Old 07-26-2011, 03:25 PM   #2
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: 29,816
Karma: 54830978
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 unboggling View Post
I need to learn how to switch "FN LN" to "LN, FN" and back. Does anyone have those regex's handy? Could this be added as a function to the search/replace dialogue in regex mode?

Also, is there a list anywhere of useful regexs? (It would be great as a sticky.) It's time I learn and incorporate them.

I love calibre and thank you developers for all the work
There is a setting: Preference: Adding Books Swap Author First and Last name.
theducks is offline   Reply With Quote
Advert
Old 07-26-2011, 03:31 PM   #3
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
theducks, thanks, I've used that and it's great. But what if thousands of books are already added with some LN FN, some FN LN? It'd be useful to regex them selectively after adding.
unboggling is offline   Reply With Quote
Old 07-26-2011, 04:49 PM   #4
Mixx
Zealot
Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.
 
Posts: 143
Karma: 387
Join Date: Sep 2010
Device: Kindle 3
You need to go to "Edit Metadata in Bulk" (context menu), go to the second tab "Search and Replace", there you select "Search Field" to be "authors" and (in some versions of Calibre) put the result back into "authors". "Search mode": Regular expression. Then for

FN LN --> LN, FN

Search for:
Code:
(.*) (.*)
Replace with:
Code:
\2, \1
LN, FN --> FN LN

Search for:
Code:
(.*), (.*)
Replace with:
Code:
\2 \1
You see at the bottom what's gonna happen to your selected items and can even test your own cases.

If you like what you are doing, you can save these cases, too. I actually call them "FN LN --> LN, FN" and "LN, FN --> FN LN". Then you just pull them down, as needed.

Regards, Mixx
Mixx is offline   Reply With Quote
Old 07-26-2011, 04:51 PM   #5
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by unboggling View Post
I need to learn how to switch "FN LN" to "LN, FN" and back. Does anyone have those regex's handy? Could this be added as a function to the search/replace dialogue in regex mode?
To go from FN LN, try the search expression "(.*) (.+)" and the replacement expression "\2, \1". To go the other way, try "(.+), (.*)" with the replacement "\2 \1".
chaley is offline   Reply With Quote
Advert
Old 07-26-2011, 09:03 PM   #6
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
Mixx & chaley, thank you! Both methods (.*) and (.+) work great in most cases. That saves me a lot of work. So far, cases where neither method works include names such as "Melissa de la Cruz" which yields "Cruz, Melissa de la". "Melissa de la Cruz" needs to be split after the FN (at the first space from left in string) to yield "de la Cruz, Melissa" rather than the current result with each method: "Cruz, Melissa de la". Going the other way from LN, FN to FN LN in that case is fine.

Giving it some thought, it seems complex to distinguish correctly between cases of middle initials "D L" vs last name prefixes like "Da" or "de La". Counting spaces in the FN LN string to get the leftest space would only work in these special cases where they have no middle initials, not cases involving middle initials. And I haven't been using periods after initials either, which further complicates matters for me. If I added periods back in to initials, then that might be a way to distinguish between "de la" and "D. L." using a regex. Another way to distinguish would be to count the number of chars between spaces using 2 if periods present, or 1 if periods not present, to determine if it's an initial.

Anyway, thanks again. BTW, I'm curious what's the specific difference between the * and the + ?

Last edited by unboggling; 07-26-2011 at 09:21 PM.
unboggling is offline   Reply With Quote
Old 07-26-2011, 09:44 PM   #7
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
Never mind the question re difference between * and +, got it from manual, * is 0 or more vs + is 1 or more of preceding.
unboggling is offline   Reply With Quote
Old 07-26-2011, 10:33 PM   #8
penguinaka
Quack! Quack!
penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.
 
penguinaka's Avatar
 
Posts: 92
Karma: 9176
Join Date: Apr 2011
Location: Florida
Device: kindle 3 & sony daily prs950sc
LN FN SWAPS: Pre - Import

LN, FN ==> FN LN
Code:
^(\w+), *([\w \.]+)[ ]+-[ ]*(.*)
$2 $1 - $3
LN, FN & LN, FN ==> FN LN & FN LN
Code:
([^,]*), ([^&]*)& ([^,]*),([^-]*)-(.*)"
$2$1 &$4$3 -$5
LN, FN and LN, FN ==> FN LN and FN LN
Code:
([^,]*), ([^&]*)and ([^,]*),([^-]*)-(.*)
$2$1 and$4$3 -$5
Author - Title - Series Swaps:

T,S,A not ( )
Swap T,S,A to A,S,T in book filename (if there is a " - " between the three parts) anything in brackets at the end remains in place.
Code:
([^-]*) - ([^-]* - )?([^(]*)( \(.*\))?(\.[^(.]*)
\3 - \2\1\4\5
T,A,S not ( )
Swap T,A,S to A,S,T in book filename (if there is a " - " between the three parts) anything in brackets at the end remains in place.
Code:
(.*) - (.*) - ([^(]*)( \(.*\))?(\.[^(.]*)
\2 - \3 - \1\4\5
S,A,T not ( )
Swap S,A,T to A,S,T in book filename (if there is a " - " between the three parts) anything in brackets at the end remains in place.
Code:
([^-]*) - ([^-]* - )?([^(]*)( \(.*\))?(\.[^(.]*)
\2\1 - \3\4\5
Swap S,T,A not ( )
Swap S,T,A to A,S,T in book filename (if there is a " - " between the three parts) anything in brackets at the end remains in place.
Code:
(.*) - (.*) - ([^(]*)( \(.*\))?(\.[^(.]*)
\3 - \1 - \2\4\5
Swap A,T,S not ( )
Swap A,T,S to A,S,T in book filename (if there is a " - " between the three parts) anything in brackets remains in place.
Code:
(.*) - (.*) - ([^(]*)( \(.*\))?(\.[^(.]*)
\1 - \3 - \2\4\5

*NOTE - the Dollar Sign "$" or the Forward Slash "/" is used interchangeably in the replace depending on which renaming tool you are using.

Last edited by penguinaka; 07-26-2011 at 11:43 PM.
penguinaka is offline   Reply With Quote
Old 07-27-2011, 12:37 AM   #9
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
penguinaka, thanks. I've saved that list for trying out the next time I add books. Which will be weeks in future because I'm in the midst of cleaning up a big batch already imported. I'm not sure what takes the least amount of time: (1) preprocessing in the OS into directories to match each import regex, or (2) importing raw downloads then postprocessing in calibre. I suspect (1) is faster. I've done it both ways and both ways are time consuming. As I become more familiar with regex and search-terms/operators in both OS and calibre the time decreases either way. (I'm specifically referring to a group of downloaded books in which there are varying levels of directories and varying filename standards.)

Last edited by unboggling; 07-27-2011 at 12:41 AM.
unboggling is offline   Reply With Quote
Old 07-27-2011, 02:47 AM   #10
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by unboggling View Post
So far, cases where neither method works include names such as "Melissa de la Cruz" which yields "Cruz, Melissa de la". "Melissa de la Cruz" needs to be split after the FN (at the first space from left in string) to yield "de la Cruz, Melissa" rather than the current result with each method: "Cruz, Melissa de la".
There is no general way to solve this problem, because in many cases the choice has been made by the person. Consider A van B. I know people with names of that form, some of whom insist that their last name is van B, and the remainder who insist that their last name is B. The same is true for some friends with 'de' in their name (A de B) -- some want their last name to be de B and others just B. I know others with names A B C, where for some C is the last name and for the others it is B C.

In the end, you must look at the name and compare it to how the real-live human uses (used) it.
chaley is offline   Reply With Quote
Old 07-27-2011, 03:39 AM   #11
penguinaka
Quack! Quack!
penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.
 
penguinaka's Avatar
 
Posts: 92
Karma: 9176
Join Date: Apr 2011
Location: Florida
Device: kindle 3 & sony daily prs950sc
Pre-Processing prior to import is faster... this is what i use.... it is a renaming script that I created especially for ebook collectors. Its for use pre-calibre import. I hope you enjoy it! It's shaved hundreds of hours off my time working with my collection pre-import to calibre. If you like it... i normally post updates to it at http://resource.dopus.com Cheers!

BookCase (v6.0) - The Ultimate eBook File Renamer on Crack
BookCase is a heavily modified TitleCase Plus VBscript that works as a button in Directory Opus (Directory Opus is a Windows Explorer Replacement... a trial version can be downloaded at http://www.gpsoft.com.au/ and the scripts to run in it that i created can be found at the end of the post). It is designed to do all your eBook file renaming in one button click. Everything that it can do is listed below and in the script all the options can be turned on or off so that you get the format that you desire. To give you an idea it can be run against 100,000 eBook files at once and will take aproximatly five minutes to complete. 1000 files and less its near instant.

VERSION UPDATE (v6.0) Change List:
1. (request #1) added a remove bracketed version # feature (fBracketMagic2=True). The way this operates is it changes all brackets to round brackets then if fbraket=true then series brackets are removed if fbracket=false then series brackets are changed to square and then all rounded brackets are removed. If you use this feature then fBracketMagic1 should = false (i already have it set up for you)

2. (request #2) Swap title names that have ",the" ",a" and ",an" and the end of the title. I'm still working on this. I actually like this request i have the same thing in my library through out my books that i have been fixing by hand

3. (request #3) Swap lastname, firstname. this function was already built in and turned on as an option

4. (request #4) added AUTORENAME to script (if the file name already exists it renames the file to the same name with a "(1) at the end.)

5. (request #5) Turned off (commented out) the italian, spanish, french & german lower case exceptions which was giving you the W e B lower case in initals with initials that had "a" or "e" and a few others.




I know the image has a v5.8 label but the rar contains v6.0


BookCase Does the Following:


All these are set as options that can be turned on or off by changing the value to "True" or "False" in the options area of the code its clearly marked if you edit the button.

Included in the zip is BookCase as a .orp file and additionally as a button. Also Including in the Zip is some other eBook Renaming Buttons. They are 3 Buttons... 2 of the buttons have a drop down with multiple buttons inside them.

Multiple Buttons File Contains:
1st Button: Trim - Trims Multiple Spaces, Leading and Trailing
2nd Button: Replace has 5 buttons in it
-1 Replaces File Name with the Folder Name
-2 Append the Extension Info to the End of the File in Round Brackets
-3 Appends Folder Name to the Beginning of the File name separated by a Dash
-4 Replace Underscore with a Comma... for those ebooks that are Last name_ First Name
-5 Replace by with a Dash and then do a author title swap
-6 Version Fix; Add "Series" to Series Numbers that do not have A Series Title. So that Calibre doesn't drop The Series Info.
3rd Button: Swaps
-1 Swaps Lastname, Firstnames of any type also multiples of them separated by & or and.
-2 Swaps Title Series Author (TSA) to (AST) and leaves bracketed info in place
-3 Swaps (TAS) to (AST) and leaves bracketed info in place
-4 Swaps (SAT) to (AST) and leaves bracketed info in place
-5 Swaps (STA) to (AST) and leaves bracketed info in place
-6 Swaps (ATS) to (AST) and leaves bracketed info in place


The Buttons are in Text files just copy from <?xml version="1.0"?> to </button> in the files and paste it onto your bar while your in customization mode. There is a read first in the rar file which will explain more in depth how to install them onto the bar on opus... If you need further help feel free to pm me.

Let me know what you think when you test drive them!


Code:
http://www.filesonic.com/file/1515403784
No Need to get an account with filesonic just use free/regular user download

Note on Typical Settings:

1. Keep all bracketed information regardless of what it is:
fBracketMagic1 & fBracketMagic 2 should be false

2. Remove all bracketed info accept version info and series if bracketed:
fBracketMagic1 = True and fBracketmMagic2 = False

3. Remove all Bracketed info but keep series info if bracketed:
fBracketMagic1 = False abd fBracketMagic2 = True

Last edited by penguinaka; 07-27-2011 at 04:03 AM.
penguinaka is offline   Reply With Quote
Old 07-27-2011, 07:26 AM   #12
Mixx
Zealot
Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.Mixx has a complete set of Star Wars action figures.
 
Posts: 143
Karma: 387
Join Date: Sep 2010
Device: Kindle 3
Awsome!!

Thanxx, Mixx
Mixx is offline   Reply With Quote
Old 07-27-2011, 12:29 PM   #13
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
chaley, good point regarding individuals' name choices varying. I've been using ISFDB, Wikipedia, and author websites as my baseline verification of how authors like their names to be split, and still I probably get some wrong. The "van LastLastName" and "de la LastLastName" etc cases are rare enough I usually remember which way I've split them. Such as "Lustbader, Eric Van" and "van Vogt, A E". Bottom line is I don't care if I split it wrong but in each case I want to split it consistently the same way, to avoid having duplicate books under "Lustbader, Eric Van" and "Van Lustbader, Eric." After this discussion, which seems ridiculous, I'm tempted to ignore the way the authors like it and just split them the way the simple regex does and not worry about it.

Last edited by unboggling; 07-27-2011 at 12:57 PM.
unboggling is offline   Reply With Quote
Old 07-27-2011, 12:41 PM   #14
unboggling
Wizard
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,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
penguinaka, as Mixx said, BookCase v6.0 looks awesome for pre-calibre processing. Too bad I'm on a Mac and would need to modify it somehow to run through MS Office VB, which is the only VB I have, or translate it to some other script language. When you (or somebody) redo it in python I'll try it.
unboggling is offline   Reply With Quote
Old 07-27-2011, 02:07 PM   #15
penguinaka
Quack! Quack!
penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.penguinaka can eat soup with a fork.
 
penguinaka's Avatar
 
Posts: 92
Karma: 9176
Join Date: Apr 2011
Location: Florida
Device: kindle 3 & sony daily prs950sc
Quote:
Originally Posted by unboggling View Post
penguinaka, as Mixx said, BookCase v6.0 looks awesome for pre-calibre processing. Too bad I'm on a Mac and would need to modify it somehow to run through MS Office VB, which is the only VB I have, or translate it to some other script language. When you (or somebody) redo it in python I'll try it.
or run in windows emulation mode and see if opus will install then it will probably work for you... possibly... not super familiar with macs...

I wrote the script while i was working on a massive collection... i got tired of pasting in a regex command running it then changing it to another and so forth per group of files.

Since i no longer really need it for the collection i do small feature requests... but in order to create the thing i had to teach myself the rudiments of vbscript and i don't have the need or the time (my clinicals start in aug) to learn another language right now sorry you might be able to get a lot of the code to translate to what you need and pull the regex out of it.

cheers!
penguinaka is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with reverse proxy server novaris Devices 1 09-10-2012 12:22 PM
PRS-T1 Would Reverse tether be possible on a T1? Schauberger Sony Reader Dev Corner 3 09-07-2012 09:46 AM
Reverse Ln, Fn? Barriemackenzie Library Management 16 02-23-2011 04:03 PM
Reverse Proxying Stanza RoninTech Calibre 3 11-10-2009 11:20 AM
reverse display output? LDB Sony Reader 0 08-10-2008 11:14 PM


All times are GMT -4. The time now is 11:14 AM.


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