wolffd@0: % --- wolffd@0: % This is the wrapper and loader class for Last.Fm db wolffd@0: % and related data wolffd@0: % --- wolffd@0: wolffd@0: classdef LFMTagsDB < handle wolffd@0: wolffd@0: properties wolffd@0: wolffd@0: % connects the last.fm artists to MTTartist ids wolffd@0: matching_artists; wolffd@0: wolffd@0: % saves the last fm tags for last.fm artist ids wolffd@0: tagdb; wolffd@0: end wolffd@0: wolffd@0: properties(Dependent) wolffd@0: wolffd@0: lexicon; wolffd@0: end wolffd@0: wolffd@0: wolffd@0: methods wolffd@0: function db = LFMTagsDB(artistdb) wolffd@0: wolffd@0: % load data wolffd@0: load last.fm.mat; wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: here, we save the corresponding magnatagatune wolffd@0: % artists. There make sure that the last.fm artists wolffd@0: % are properly associated! wolffd@0: % wolffd@0: % finally, the central last.fm artist index will refer wolffd@0: % to both the MTT artist database and the tags wolffd@0: % ---- wolffd@0: wolffd@0: % get all the clips artists wolffd@0: artists = artistdb.lexicon; wolffd@0: wolffd@0: % assign artists to Last.Fm artists wolffd@0: lexicon = []; wolffd@0: annots = []; wolffd@0: wolffd@0: justfmartists = fmartists(:,2); wolffd@0: for i = 1:numel(justfmartists) wolffd@0: wolffd@0: %get matching MTT for each Last.fm artist wolffd@0: pos = strcellfind(artists, justfmartists{i}); wolffd@0: wolffd@0: % save its id wolffd@0: if ~isempty(pos) wolffd@0: associds(i) = artistdb.get_annot_id(artists{pos}); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % TODO: assert wheather if the fmartist id actually coincide wolffd@0: % justfmartists_ids = matching_artists.get_annotid(justfmartists); wolffd@0: % --- wolffd@0: wolffd@0: % call superclass constructor wolffd@0: db.tagdb = AnnotDB(fmartist_annots_names, ... wolffd@0: fmartist_annots, associds); wolffd@0: wolffd@0: % save the mathing artists wolffd@0: db.matching_artists = AnnotDB('clips_by_annot', ... wolffd@0: justfmartists, associds); wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: methods wolffd@0: wolffd@0: % retrieve annot by clip wolffd@0: function [out, score, aid] = annots(db, clip) wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we retrieve the tags for the artist matching the clips wolffd@0: % one wolffd@0: % --- wolffd@0: wolffd@0: fma_id = db.matching_artists.annotids_for_owner(clip.artist_id()); wolffd@0: wolffd@0: artist = clip.artist(); wolffd@0: wolffd@0: if ~isempty(fma_id) wolffd@0: wolffd@0: [out, score, aid] = db.tagdb.annots(fma_id); wolffd@0: else wolffd@0: warning('Artist %s not found in Last.fm tags DB', artist); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: function out = annotids_for_owner(db, clip) wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we retrieve the tags for the artist matching the clips wolffd@0: % one wolffd@0: % --- wolffd@0: wolffd@0: fma_id = db.matching_artists.annotids_for_owner(clip.artist_id()); wolffd@0: wolffd@0: artist = clip.artist(); wolffd@0: wolffd@0: if ~isempty(fma_id) wolffd@0: wolffd@0: out = db.tagdb.annotids_for_owner( fma_id ); wolffd@0: else wolffd@0: warning('Artist %s not found in Last.fm tags DB', artist); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: function out = get.lexicon(db) wolffd@0: % gives back all the tags wolffd@0: wolffd@0: out = db.tagdb.lexicon; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: methods(Static) wolffd@0: wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: