2017-04-24 7 views
0

に汚い言葉を削減し、SpotifyはAPIの歌ジャンル:は、例えばワードシード

['alternative rock', 'comic', 'funk rock', 'garage rock', 'indie rock', 'pop rock', 'post-grunge', 'rock'] 

['g funk', 'gangster rap', 'hip hop', 'pop rap', 'rap', 'west coast rap'] 

['canadian pop', 'dance pop', 'pop', 'pop christmas']  

3つのリストは、「ジャンルシード」3曲のgenres.Butなどジャンルは非常に厄介に見える、と私は簡単にできた「エキス」を表します、それは私が言葉の種の中に、このような汚い言葉を減らすことができる方法

それぞれ

rock 
rap 
pop 

3曲ありますか? thx

+0

あなたはジャンルと「ジャンルシード」の間で何らかのマッピングをする必要があります。 –

+0

シードワードの有限リストは既にありますか? – JacobIRR

+0

はい、私は "ポップ" "ロック"のようなシードワードのリストを持っています – user815408

答えて

1

もし、あなたが種のリストを持っていれば、例えば、各種の雑誌の出現数を数え、最大の重みを持つものを返すことができます。 シードリストを「シード」、ジャンルリストを「ジャンル」といいます。すべての種族の組み合わせをクロスチェックして、ある構造に重さを加えるべきです。

def max_seed_return (seeds, genres): 
    # appending weigths to dictionary 
    weights= {seed:0 for seed in seeds} 
    for genre in genres: 
     for seed in seeds: 
      if seed in genre: 
      weights[seed]+=1 
    max_weight, result = 0, None 
    # getting result genre with biggest weigth 
    for seed, seed_weight in weights.items: 
     if seed_weight>max_weight: 
      max_weight=seed_weight 
      result=seed 
    #returns it or None if no seeds is found in genres 
    return result