Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 05-20-2024, 07:00 AM   #1
dandman
Enthusiast
dandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watch
 
Posts: 29
Karma: 10545
Join Date: May 2024
Device: none
Caliber metadata plugin ignors source_relevance attribute

adding multiple books into the result_queue with different source_relevance has no effect on the UI displaying the book search results,

i have tried adding the levenshtein_distance result, (i actually use: fuzzywuzzy.QRatio) and in the example of 4 books the results entered into the source_relevance attributes are: 61, 58, 58, 58

i also tried converting them into sequential order: 1, 2, 3, 4

and it still has no effect on the UI.

i made sure the experience is the same for hebrew and english Caliber interface languages,

i searched the forum (there are only 2 mentions with source_relevance, non related to this issue),

i searched the source code and it looks like there is a preparation for ordering logic, but i can't find any code actually implementing it

https://github.com/kovidgoyal/calibr...es/base.py#L94
(maybe this is it ?)


it is not an important feature when i return multiple options (no one perfect match) and i want the user to choose from,

but it is an important feature when the user execute 10, 20, 50 ... books to get metadata and multiple books are returned - and Caliber should auto-select the first (with the highest source_relevance)

if anyone knows of a better option (like Caliber somehow signal the plugin this is a batch call and to return only 1 book, or better yet - to return multiple results for all the searched books)

thanks ahead
dandman is offline   Reply With Quote
Old 05-20-2024, 10:12 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,653
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It most definitely is used look in sources/identify.py
kovidgoyal is offline   Reply With Quote
Old 05-20-2024, 11:05 AM   #3
dandman
Enthusiast
dandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watch
 
Posts: 29
Karma: 10545
Join Date: May 2024
Device: none
i have checked this testcase multiple times with no avail, but i will look into the code and update here

10x
dandman is offline   Reply With Quote
Old 05-20-2024, 02:14 PM   #4
dandman
Enthusiast
dandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watch
 
Posts: 29
Karma: 10545
Join Date: May 2024
Device: none
so apparently the source_relevance is not the only attribute the compare takes into consideration when sorting the book results by relevance, but also the comments length, if it has a cover, are the identifier of searched book and current results resembles etc.

i could not find that in the docs, only in the code comments,

i think it is an important part to mention, so i will quote it here for others:


function identify_results_keygen returns a function that will generate a key that the sort will use as a sorting key:
PHP Code:
identify_results_keygen(titleauthorsidentifiers
Code:
        Returns a function that is used to generate a key that can sort Metadata
        objects by their relevance given a search query (title, authors,
        identifiers).

        These keys are used to sort the results of a call to :meth:`identify`.

        For details on the default algorithm see
        :class:`InternalMetadataCompareKeyGen`. Re-implement this function in
        your plugin if the default algorithm is not suitable.
and the internal implementation of the algorithm is:

Code:
    Generate a sort key for comparison of the relevance of Metadata objects,
    given a search query. This is used only to compare results from the same
    metadata source, not across different sources.

    The sort key ensures that an ascending order sort is a sort by order of
    decreasing relevance.

    The algorithm is:

        * Prefer results that have at least one identifier the same as for the query
        * Prefer results with a cached cover URL
        * Prefer results with all available fields filled in
        * Prefer results with the same language as the current user interface language
        * Prefer results that are an exact title match to the query
        * Prefer results with longer comments (greater than 10% longer)
        * Use the relevance of the result as reported by the metadata source's search
           engine

for me it was the length of the comments that overcame the relevance,
basically the source_relevance (.extra) is taken into consideration if and only if all else is the same

PHP Code:
    def compare_to_other(selfother):
        
cmp(self.baseother.base)
        if 
!= 0:
            return 
a
        cx
cy self.comments_lenother.comments_len
        
if cx and cy:
            
= (cx cy) / 20
            delta 
cy cx
            
if abs(delta) > t:
                return -
if delta else 1
        
return cmp(self.extraother.extra
one can override this method in the plugin and re-implement the results comparison algorithm, here is a simple example to compare only by the source_relevance attribute:

PHP Code:
    def identify_results_keygen(selftitle=Noneauthors=Noneidentifiers={}):
        
# return a function that will be used while sorting the identify results based on the source_relevance field of the Metadata object
        
return lambda xx.source_relevance 
for me it was important since i wanted to introduce an option where no perfect match exist (due to misspelled title or authors) and to serve the user with close options ordered by match percentage (at what percent the result matches the searched book)
dandman is offline   Reply With Quote
Old 05-20-2024, 02:23 PM   #5
dandman
Enthusiast
dandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watchdandman is clearly one to watch
 
Posts: 29
Karma: 10545
Join Date: May 2024
Device: none
it is also mentioned in the plugin docs, just digg:
https://manual.calibre-ebook.com/plugins.html
dandman is offline   Reply With Quote
Reply

Tags
metabata, plugin, source_relevance


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I know which Metadata Source Plugin was called from fetch-ebook-metadata? eryMpexI Library Management 6 04-22-2023 09:58 AM
[Metadata Source Plugin] Empty Plugin? (Fake Identifier) mneimeyer Plugins 3 11-11-2019 09:07 PM
Can't download metadata in Caliber mneumayer Calibre 1 09-10-2018 09:45 PM
Regarding using metadata objects in identify method of metadata download plugin api aprekates Development 1 07-06-2014 04:35 AM
How does Caliber store MetaData? JGB Calibre 4 12-10-2008 01:53 AM


All times are GMT -4. The time now is 07:40 PM.


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