亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 wordnet.synsets() 獲取列表中多個單詞的定義

如何使用 wordnet.synsets() 獲取列表中多個單詞的定義

拉丁的傳說 2023-05-16 14:25:14
我可以得到一個詞的定義如下:from nltk.stem import WordNetLemmatizerfrom nltk.corpus import wordnetwordnet.synsets('hello')[0].definition()*an expression of greeting*但是,如何使用單詞列表獲得相同的結果?df =  ['Unnamed 0', 'business id', 'name', 'postal code',]df2 = []for x in df:    df2.append(wordnet.synsets(x))我可以對 df2 做些什么來讓它顯示列表中每個單詞的第一個定義?
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

注意:并不是所有的詞都能在 wordnet 中找到。


from nltk.corpus import wordnet


df = ['Unnamed 0','business id','name','postal code']

df = [x.strip().replace(' ', '_') for x in df]


df2 = []

for x in df:

    syns = (wordnet.synsets(x))

    df2.append(syns[0].definition() if len(syns)>0 else '')


print(df2)

輸出:


['', '', 'a language unit by which a person or thing is known', 'a code of letters and digits added to a postal address to aid in the sorting of mail']



查看完整回答
反對 回復 2023-05-16
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號