二元語法我需要:1。 形成二元對,它們存儲在表ID 2.找到總和,其中有аrе前3兩字頻率最高句子的列表形成的話二元語法和計算使用python
我有句子的列表:
[['22574999', 'your message communication sent']
, ['22582857', 'your message be delivered']
, ['22585166', 'message has be delivered']
, ['22585424', 'message originated communication sent']]
這裏是我做過什麼:
for row in messages:
sstrm = list(row)
bigrams=[b for l in sstrm for b in zip(l.split(" ")[:1], l.split(" ")[1:])]
print(sstrm[0],bigrams)
這將產生:
22574999 [('your', 'message')]
22582857 [('[your', 'message')]
22585166 [('message', 'has')]
22585424 [('message', 'originated')]
我要的是:
22574999 [('your', 'message'),('communication','sent')]
22582857 [('[your', 'message'),('be','delivered')]
22585166 [('message', 'has'),('be','delivered')]
22585424 [('message', 'originated'),('communication','sent')]
我希望得到以下結果 結果:
前3名的雙字母組頻率最高:
('your', 'message') :2
('communication','sent'):2
('be','delivered'):2
的總和其中有最高頻率最高的三個bigrams:
('your', 'message'):2 Is included (22574999,22582857)
('communication','sent'):2 Is included(22574999,22585424)
('be','delivered'):2 Is included (22582857,22585166)
感謝您的幫助!