减少凌乱的字到词种子

问题描述:

例如,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']  

三个列表代表三种歌曲的genres.But这种风格看起来很凌乱,我可以很容易地“提取”的“流派种子” ,这是三首歌曲是

rock 
rap 
pop 
分别

我怎么能减少这种混乱的话变成文字的种子? thx

+0

您需要某种类型的流派和'流派种子'之间的映射。 –

+0

你已经有一个有限的种子单词列表了吗? – JacobIRR

+0

是的,我确实有种类词汇表,如“流行”“摇滚” – user815408

那么,如果你有一个种子列表,我们可以,例如,计算每个种子的种类的出现次数,并返回最大权重的种子。 假设种子列表被称为“种子”,种类列表被称为“种类”。我们应该对所有种子类型组合进行交叉核对,并为某些结构增加权重。

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