如果我有这样的元组列表:
train = [('pad thai', 'FOOD#QUALITY'),
('Ginger House', 'RESTAURANT#GENERAL'),
('fried dumplings', 'FOOD#QUALITY'),
('Chinese restaurant', 'RESTAURANT#GENERAL'),
('customer service', 'SERVICE#GENERAL'),
('management', 'SERVICE#GENERAL')]
我可以使用freq = nltk.ConditionalFreqDist((a, category) for a, category in train)
来获取一个类别中整个短语的频率,但如果我只想存储unigrams的频率,我该怎么做,最好是在列表理解中呢?我遇到过这个解决方案:Remove uni-grams from a list of bi-grams这很有帮助,但如果可能的话,我希望更简洁。