def parse_feature(feature):
""" Parse feature string into
(feature name, [1st order aggregates], [2nd order aggregates]).
'Grammar':
- feature name and aggregates are separated by dots, e.g. 'mfcc.entropy'
- feature name is first and contains no dots
- first order and second order aggregates are separated by one of 2 keywords:
'corpus' or 'song'
Ex.:
>>> parse_features('loudness.mean.song.pdf.log')
('loudness', ['mean'], ['song', 'pdf', 'log'])
"""
s = np.array(feature.split('.'))
split_points = (s == 'corpus') | (s == 'song')
split_points = np.nonzero(split_points)[0] if any(split_points) else [len(s)]
return s[0], s[1:split_points[0]].tolist(), s[split_points[-1]:].tolist()
评论列表
文章目录