Skip to content

Commit

Permalink
PICARD-2792: Recordings without releases must score lower than with
Browse files Browse the repository at this point in the history
Apply a weighted scoring based on "Other" release type for recordings
without releases. Otherwise "no release" always gives full score, while
matching against a releases usually always gives some deduction to the
matching score.
  • Loading branch information
phw committed Dec 19, 2023
1 parent 762e768 commit d21b4f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions picard/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def compare_to_track(self, track, weights):

search_score = get_score(track)
if not releases:
config = get_config()
score = dict(config.setting['release_type_scores']).get('Other', 0.5)
parts.append((score, _get_total_release_weight(weights)))
sim = linear_combination_of_weights(parts) * search_score
return SimMatchTrack(similarity=sim, releasegroup=None, release=None, track=track)

Expand Down Expand Up @@ -663,6 +666,12 @@ def __repr__(self):
return self.__read('__repr__')


def _get_total_release_weight(weights):
release_weights = ('album', 'totaltracks', 'totalalbumtracks', 'releasetype',
'releasecountry', 'format', 'date')
return sum(weights[w] for w in release_weights if w in weights)


_album_metadata_processors = PluginFunctions(label='album_metadata_processors')
_track_metadata_processors = PluginFunctions(label='track_metadata_processors')

Expand Down
26 changes: 24 additions & 2 deletions test/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright (C) 2017 Sophist-UK
# Copyright (C) 2018, 2020 Wieland Hoffmann
# Copyright (C) 2018-2021 Laurent Monin
# Copyright (C) 2018-2021 Philipp Wolfer
# Copyright (C) 2018-2021, 2023 Philipp Wolfer
# Copyright (C) 2020 dukeyin
#
# This program is free software; you can redistribute it and/or
Expand All @@ -30,6 +30,9 @@
)
from test.test_coverart_image import create_image

from picard.acoustid.json_helpers import (
parse_recording as acoustid_parse_recording,
)
from picard.cluster import Cluster
from picard.coverart.image import CoverArtImage
from picard.file import File
Expand Down Expand Up @@ -61,7 +64,8 @@
'translate_artist_names': False,
'release_ars': True,
'release_type_scores': [
('Album', 1.0)
('Album', 1.0),
('Other', 1.0),
],
}

Expand Down Expand Up @@ -699,6 +703,24 @@ def test_compare_to_track_full(self):
self.assertEqual(recording, match.track)
self.assertEqual(recording['releases'][0], match.release)

def test_compare_to_track_without_releases(self):
self.set_config_values({
'release_type_scores': [('Compilation', 0.6), ('Other', 0.6)]
})
track_json = acoustid_parse_recording(load_test_json('acoustid.json'))
track = Track(track_json['id'])
track.metadata.update({
'album': 'x',
'artist': 'Ed Sheeran',
'title': 'Nina',
})
track.metadata.length = 225000
m1 = track.metadata.compare_to_track(track_json, File.comparison_weights)
del track_json['releases']
m2 = track.metadata.compare_to_track(track_json, File.comparison_weights)
self.assertGreater(m1.similarity, m2.similarity,
'Matching score for release with recordings must be higher then for release without')


class MetadataTest(CommonTests.CommonMetadataTestCase):
@staticmethod
Expand Down

0 comments on commit d21b4f6

Please sign in to comment.