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 12-21-2020, 01:38 AM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Removing hierarchy levels

I created a list_union composite to separate the hierarchical tags and make it look neater in the details view.

I actually got it working as I expected (e.g. Fiction.Animals.Cats, Fiction.Mystery.Cozy Mystery becomes Fiction, Animals, Cats, Mystery, Cozy Mystery).

However, how would I strip out any sublevel items under specific tags?

e.g. Fanfiction.Crossover and Documentation and Manuals.Video Games.Strategy Guides, I just want the top levels to appear. (I have them grouped in general broad tags and use custom manual/fanfic-specific columns for actual filtering.)

I thought list_difference would work but I'm not really sure what I'm doing:

Code:
{tags:'list_difference(re($, '\.', ', '), 'Fanfiction', ',')'}
just removed fanfiction

Code:
{tags:'list_difference(re($, '\.', ', '), 'Fanfiction.Crossover, ',')'}
didn't work (and isn't ideal anyways as I'd have to manually enter them all)

Code:
{tags:'list_difference(re($, '\.', ', '), 'Crossover, ',')'}
did work, but also isn't ideal (and it'd also destroy any matching tags, e.g. Documentation and Manuals.Video Games - Comics.Video Games)


Last edited by ownedbycats; 12-21-2020 at 05:21 AM.
ownedbycats is online now   Reply With Quote
Old 12-21-2020, 05:36 AM   #2
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Moderator Notice
Moved to separate thread
chaley is offline   Reply With Quote
Advert
Old 12-21-2020, 05:49 AM   #3
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
If I understand you correctly you want to remove the second - last part of hierarchical items in a field. This template does that.
Code:
{#genre:'list_re($, ',', '^(.*?)($|\..*$)', '\1')'}
chaley is offline   Reply With Quote
Old 12-21-2020, 05:55 AM   #4
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Unfortunately, that removed subitems from all my books.

I just want to remove any subitems from a hierarchical item beginning with Fanfiction or Documentation and Manuals. Alternately, hiding it entirely if that's easier.

At the very least the third list_difference in the OP works, though I just have to add all the items manually (and make sure they're not used elsewhere).

Last edited by ownedbycats; 12-21-2020 at 06:17 AM.
ownedbycats is online now   Reply With Quote
Old 12-21-2020, 06:19 AM   #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: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Unfortunately, that removed subitems from all my books.

I just want to remove any subitems from a hierarchical item beginning with Fanfiction or Documentation and Manuals. Alternately, hiding it entirely if that's easier.

At the very least the third list_difference in the OP works, though I just have to add all the items manually.
I still don't understand what you want. Guessing, perhaps this:
Code:
program:
	g = field('#genre');
	list_re_group(g, ',', '.', '^(Fanfiction|Documentation and Manuals)($|\..*$)', '{$}', '')
It removes hierarchical items from the two items but doesn't touch any other item.
chaley is offline   Reply With Quote
Advert
Old 12-21-2020, 06:22 AM   #6
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That's close to what I was trying to do, though now it causes tags to display unsplit.

Hopefully this explains better what I'm trying to do:

Tags: Fiction.Animals.Cats, Fiction.Mystery.Cozy Mystery
Results: Fiction, Animals, Cats, Mystery, Cozy Mystery

(It'd also be nice if this was also sorted alphabetically, but I'm not that fussy.)

Tags: Documentation and Manuals.Video Games
Results: Documentation and Manuals

Tags: Fanfiction.Crossover, Fanfiction.Half-Life & Portal, Fanfiction.Mass Effect
Results: Fanfiction

Tags: Fanfiction.Crossover, Fiction.Animals.Cats
Results: Fanfiction, Fiction, Animals, Cats

My own solution to this is pretty much this, which works but is a bit clumsy:

Code:
{tags:'list_difference(re($, '\.', ', '), 'Video Games, Strategy Guides, Crossover, Half-Life & Portal, Mass Effect', ',')'}

Last edited by ownedbycats; 12-21-2020 at 06:58 AM.
ownedbycats is online now   Reply With Quote
Old 12-21-2020, 07:08 AM   #7
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I think you want a new item list consisting of
  • The first level of certain hierarchical items
  • All other items, split at a period
  • Combined together to remove duplicates.
  • Then sorted
If so, then this template does it.
Code:
program:
	g = field('#genre');
	stripped_hierarchies = list_re_group(g, ',', '.',
			'^(Fanfiction|Documentation and Manuals)($|\..*$)',
			'{$}', '');
	split_hierarchies = re(stripped_hierarchies, '\.', ',');
	cleaned = list_union('', split_hierarchies, ',');
	sorted = list_sort(cleaned, 0, ',')
The order of arguments to list_union is important. The function checks for duplicates while adding the second list to the first. It doesn't remove existing duplicates from the first. By passing an empty list as the first list, duplicates in the second list are removed as they are added to the first.

EDIT: added list_sort to the template.

Last edited by chaley; 12-21-2020 at 12:26 PM. Reason: Edit: added list_sort
chaley is offline   Reply With Quote
Old 12-21-2020, 01:09 PM   #8
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That did it! Thank you.
ownedbycats is online now   Reply With Quote
Old 12-27-2020, 02:22 PM   #9
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: There's a number of specific tags I'd like to remove, but not their children. (e.g. Fiction.Cultures & Regions.Canada or Fiction.Social Issues.Prejudice & Racism - in these cases "Cultures & Regions" and "Social Issues" are just organizational tags and I don't need them to appear in the lists.)

Is this along the right lines? No errors, but it didn't actually remove the tags.

Code:
program:
	g = field('tags');
	stripped_hierarchies = list_re_group(g, ',', '.',
			'^(Fanfiction|Documentation and Manuals)($|\..*$)',
			'(Cultures & Regions|Social Issues)',
			'{$}', '');
	split_hierarchies = re(stripped_hierarchies, '\.', ',');
	cleaned = list_union('', split_hierarchies, ',');
	sorted = list_sort(cleaned, 0, ',')

Last edited by ownedbycats; 12-27-2020 at 02:29 PM.
ownedbycats is online now   Reply With Quote
Old 12-27-2020, 03:41 PM   #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: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Again, I am not sure what exactly you want to do. If you want to remove "Fiction.Cultures & Regions" and "Fiction.Social Issues" prefixes but leave their children then try this:
Code:
program:
	g = field('#genre');
	stripped_hierarchies = list_re_group(g, ',', '.',
			'^(Fanfiction|Documentation and Manuals|Fiction\.Cultures & Regions|Fiction\.Social Issues)($|\..*$)',
			'{$}', '');
	split_hierarchies = re(stripped_hierarchies, '\.', ',');
	cleaned = list_union('', split_hierarchies, ',');
	sorted = list_sort(cleaned, 0, ',')
All of the prefixes you want to remove must be in the first argument separated by | characters
chaley is offline   Reply With Quote
Old 12-27-2020, 05:11 PM   #11
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Here's what I wanted to do:

Tags: Fiction.Cultures & Regions.Canada, Fiction.Social issues.Prejudice and Racism
Results: Fiction, Canada, Prejudice and Racism

Unfortunately the template instead gave me Fiction, Cultures & Regions, Social Issues.

Last edited by ownedbycats; 12-27-2020 at 05:14 PM.
ownedbycats is online now   Reply With Quote
Old 12-27-2020, 05:29 PM   #12
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,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Here's what I wanted to do:

Tags: Fiction.Cultures & Regions.Canada, Fiction.Social issues.Prejudice and Racism
Results: Fiction, Canada, Prejudice and Racism

Unfortunately the template instead gave me Fiction, Cultures & Regions, Social Issues.
TBH this is approaching absurd. Why don't you set up your tags the way you want instead of using all this automation to mess with it? That way you control what you have without all the fuss.

The above notwithstanding, this might do what you want.
Code:
program:
	g = field('#genre');
	stripped_hierarchies = list_re_group(g, ',', '.',
			'^(Fanfiction|Documentation and Manuals)($|\..*$)',
			'{$}', '');
	split_hierarchies = re(stripped_hierarchies, '\.', ',');
	split_hierarchies = list_difference(
			split_hierarchies,
			'Cultures & Regions, Social Issues',
			',');
	cleaned = list_union('', split_hierarchies, ',');
	sorted = list_sort(cleaned, 0, ',')

Last edited by chaley; 12-27-2020 at 05:33 PM.
chaley is offline   Reply With Quote
Old 12-27-2020, 05:43 PM   #13
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,970
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works. Thank you.

The "Cultures & Regions" and "Social issues" tags are mostly just to group together tags of similar themes for easier navigation in the browser. No actual books in the tag, only its children.

The composite column is generally to make the Book Details a little tidier-looking, but I also found that it'll also let me view all the related books on that topic (e.g. clicking on "Canada" shows books from Fiction.Cultures & Regions.Canada, Nonfiction.History.Canada, and Nonfiction.Travel Guides.Canada) without having to flatten all the tags.

Last edited by ownedbycats; 12-27-2020 at 05:49 PM.
ownedbycats is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dragging a book into an expanded Hierarchy level collapse other expanded levels ChrisMillward Calibre 3 07-04-2020 06:02 AM
Hierarchy columns mezme Calibre 7 03-07-2016 01:10 PM
Hierarchy problem Clovis99 Library Management 12 12-04-2013 06:53 AM
Saved Searches - Using Hierarchy nynaevelan Library Management 10 03-28-2011 10:45 PM
Book Hierarchy jjansen Calibre 4 04-10-2010 10:39 AM


All times are GMT -4. The time now is 09:44 AM.


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