annotate core/magnatagatune/LFMTagsDB.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 % ---
wolffd@0 2 % This is the wrapper and loader class for Last.Fm db
wolffd@0 3 % and related data
wolffd@0 4 % ---
wolffd@0 5
wolffd@0 6 classdef LFMTagsDB < handle
wolffd@0 7
wolffd@0 8 properties
wolffd@0 9
wolffd@0 10 % connects the last.fm artists to MTTartist ids
wolffd@0 11 matching_artists;
wolffd@0 12
wolffd@0 13 % saves the last fm tags for last.fm artist ids
wolffd@0 14 tagdb;
wolffd@0 15 end
wolffd@0 16
wolffd@0 17 properties(Dependent)
wolffd@0 18
wolffd@0 19 lexicon;
wolffd@0 20 end
wolffd@0 21
wolffd@0 22
wolffd@0 23 methods
wolffd@0 24 function db = LFMTagsDB(artistdb)
wolffd@0 25
wolffd@0 26 % load data
wolffd@0 27 load last.fm.mat;
wolffd@0 28
wolffd@0 29 % ---
wolffd@0 30 % NOTE: here, we save the corresponding magnatagatune
wolffd@0 31 % artists. There make sure that the last.fm artists
wolffd@0 32 % are properly associated!
wolffd@0 33 %
wolffd@0 34 % finally, the central last.fm artist index will refer
wolffd@0 35 % to both the MTT artist database and the tags
wolffd@0 36 % ----
wolffd@0 37
wolffd@0 38 % get all the clips artists
wolffd@0 39 artists = artistdb.lexicon;
wolffd@0 40
wolffd@0 41 % assign artists to Last.Fm artists
wolffd@0 42 lexicon = [];
wolffd@0 43 annots = [];
wolffd@0 44
wolffd@0 45 justfmartists = fmartists(:,2);
wolffd@0 46 for i = 1:numel(justfmartists)
wolffd@0 47
wolffd@0 48 %get matching MTT for each Last.fm artist
wolffd@0 49 pos = strcellfind(artists, justfmartists{i});
wolffd@0 50
wolffd@0 51 % save its id
wolffd@0 52 if ~isempty(pos)
wolffd@0 53 associds(i) = artistdb.get_annot_id(artists{pos});
wolffd@0 54 end
wolffd@0 55 end
wolffd@0 56
wolffd@0 57 % ---
wolffd@0 58 % TODO: assert wheather if the fmartist id actually coincide
wolffd@0 59 % justfmartists_ids = matching_artists.get_annotid(justfmartists);
wolffd@0 60 % ---
wolffd@0 61
wolffd@0 62 % call superclass constructor
wolffd@0 63 db.tagdb = AnnotDB(fmartist_annots_names, ...
wolffd@0 64 fmartist_annots, associds);
wolffd@0 65
wolffd@0 66 % save the mathing artists
wolffd@0 67 db.matching_artists = AnnotDB('clips_by_annot', ...
wolffd@0 68 justfmartists, associds);
wolffd@0 69
wolffd@0 70 end
wolffd@0 71 end
wolffd@0 72
wolffd@0 73
wolffd@0 74 methods
wolffd@0 75
wolffd@0 76 % retrieve annot by clip
wolffd@0 77 function [out, score, aid] = annots(db, clip)
wolffd@0 78
wolffd@0 79 % ---
wolffd@0 80 % NOTE: we retrieve the tags for the artist matching the clips
wolffd@0 81 % one
wolffd@0 82 % ---
wolffd@0 83
wolffd@0 84 fma_id = db.matching_artists.annotids_for_owner(clip.artist_id());
wolffd@0 85
wolffd@0 86 artist = clip.artist();
wolffd@0 87
wolffd@0 88 if ~isempty(fma_id)
wolffd@0 89
wolffd@0 90 [out, score, aid] = db.tagdb.annots(fma_id);
wolffd@0 91 else
wolffd@0 92 warning('Artist %s not found in Last.fm tags DB', artist);
wolffd@0 93 end
wolffd@0 94 end
wolffd@0 95
wolffd@0 96 function out = annotids_for_owner(db, clip)
wolffd@0 97
wolffd@0 98 % ---
wolffd@0 99 % NOTE: we retrieve the tags for the artist matching the clips
wolffd@0 100 % one
wolffd@0 101 % ---
wolffd@0 102
wolffd@0 103 fma_id = db.matching_artists.annotids_for_owner(clip.artist_id());
wolffd@0 104
wolffd@0 105 artist = clip.artist();
wolffd@0 106
wolffd@0 107 if ~isempty(fma_id)
wolffd@0 108
wolffd@0 109 out = db.tagdb.annotids_for_owner( fma_id );
wolffd@0 110 else
wolffd@0 111 warning('Artist %s not found in Last.fm tags DB', artist);
wolffd@0 112 end
wolffd@0 113 end
wolffd@0 114
wolffd@0 115 function out = get.lexicon(db)
wolffd@0 116 % gives back all the tags
wolffd@0 117
wolffd@0 118 out = db.tagdb.lexicon;
wolffd@0 119 end
wolffd@0 120 end
wolffd@0 121
wolffd@0 122 methods(Static)
wolffd@0 123
wolffd@0 124
wolffd@0 125 end
wolffd@0 126 end
wolffd@0 127
wolffd@0 128
wolffd@0 129