03-01-2018, 04:30 AM | #1 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
|
Custom Genre Hierarchical Column to tags
I've been having issue trying to figure this out over the last several days. I have a Hierarchical custom column called #genre. It its set as text column (not like tags). Examples I have in it:
Fiction.Science Fiction.Space Opera Non-Fiction.Manual.Appliance.Kitchen I use the column both in Calibre and Calibre Companion. I also use FBReader and it also allows hierarchical tags BUT it uses the / (backslash) to separate tags instead of the . (period). I want to create a save to disk plugboard that changes the #genre field text to replace the periods with backslashes and adds the result to the tags column. I haven't even tried to change the save to disk plugboard yet. I've been testing by creating a custom column created from other columns but I haven't had any success. My results are just the exact same data with periods or a Template error. I tried using the re function {#genre:re($,'\\','\.')}, program: re(#genre,'\\','\.')} are just some of my attempts. I had very little luck finding good examples of the re function, probably because the name is difficult to search for. I decided to simplify my test to just using the sublist funciton to replace the periods with commas. I changed the field type to custom column created from other columns, behaves like tags. And tried: {#genre:sublist(0,0,\.)} and even just trying to get ANY result {#genre:sublist(0,1,\.)} Unfortunately this just shows the exact same information in the #genre field (i.e. Fiction.Science Fiction.Space Opera) I was hoping to get both working. I would like to add the hierarchical genre edited to replace the periods with backslashes to the tags list for the save to disk plugboard. I would also like to get the sublist working so I could edit the Polish template and show the Genres either with commas or even just spaces between the words. I edited the template to add my #genre custom column but because there are no spaces the text goes off the right of the screen. I know I can't use functions in the polish template but I figured I could use a custom column that looked correct for this. So to reiterate I want a save to disk plugboard that takes #genre (i.e Fiction.Science Fiction.Space Opera) and converts to (Fiction/Science Fiction/Space Opera) and then adds to the tags field I would also like a custom column template that either uses the sublist function or replaces the periods with spaces so the field word wraps correctly on the book jacket created by the polish command (Non-Fiction.Manual.Appliance.Kitchen to Non-Fiction, Manual, Appliance, Kitchen or Non-Fiction Manual Appliance Kitchen) Thanks for the help! |
03-01-2018, 08:15 PM | #2 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
|
So with further testing I figured out that the subitems function won't work here. I removed the backslash {#genre:sublist(0,1,\.)} and was success full with getting just the 1st part (Fiction) from the #genre field. I tried {#genre:sublist(0,2,\.)} but I got (Fiction.Science Fiction). So the subitem just uses the same separator and can't be used to replace the separator with something else.
So it looks like re() is my best option. Anyone can help me figure out how to replace the periods with backslashes? I would really appreciate some help |
03-01-2018, 09:08 PM | #3 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
|
So I came up with something using re() function. Unfortunately it only works if the Hierarchical Genre has the same number of arguments (matches) in the string:
{#genre:'re($,"^([^.]+)\.([^.]+)\.([^.]+)\.([^.]+)","\1/\2/\3/\4")'} This works for (Non-Fiction.Manual.Appliance.Kitchen) to (Non-Fiction/Manual/Appliance/Kitchen) but fails for (Fiction.Science Fiction.Space Opera). Going to try re_group next. |
03-01-2018, 09:20 PM | #4 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
|
The re_group command worked! I was able to search for each word followed by a period then replace it with the same word and a backslash. I was expecting to get a backslash at the end but its perfect!
{#genre:'re_group($,"([^.]+)\.","[[$]]/")'} Fiction.Science Fiction.Space Opera - becomes - Fiction/Science Fiction/Space Opera and Non-Fiction.Manual.Appliance.Kitchen - becomes - Non-Fiction/Manual/Appliance/Kitchen Now I just have to figure out how to write the plugboard to add this to the tags field. Any help would be appreciated! |
03-01-2018, 09:22 PM | #5 | |
Addict
Posts: 281
Karma: 7724454
Join Date: Sep 2017
Location: Bethesda, MD, USA
Device: Kobo Aura H20, Kobo Clara HD
|
Quote:
Note: / is a forward slash. A backslash goes the other way: \ |
|
03-02-2018, 12:25 AM | #6 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2018
Device: Android - FBReader
|
Haha, thanks I eventually realized that. Fortunately, FBReader uses the forward slash / which is much easier to use in a template! No need to escape it!
|
Tags |
custom columns, plugboards, regex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to move tags data into a new custom column | smoothrolla | Library Management | 6 | 05-30-2018 07:19 AM |
How can I boolean OR several tags into one custom column? | bmix | Library Management | 3 | 01-09-2015 03:57 AM |
Custom column listing the tags and language | dpierron | Library Management | 4 | 10-19-2012 07:24 AM |
Download tags to a custom column | atjnjk | Library Management | 8 | 01-18-2012 08:02 AM |
Help with template for custom column from tags | africalass | Library Management | 2 | 07-16-2011 11:47 AM |