gpt4 book ai didi

python - NLTK 只搜索名词同义词集

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:49 27 4
gpt4 key购买 nike

这是我正在编写的一个函数,用于检查名词列表中是否存在上位词和下位词。

def check_hyper_hypo(wordlist):
returnlist=[]
for word in wordlist: #by definition a base word has a word above and below heirachy
x = wn.synsets(word)
for syn in x:
if not(((len(syn.hypernyms()))==0)or((len(syn.hyponyms()))==0)):
returnlist.append(word)
break
return returnlist

我如何只检查作为名词的同义词集的上位词/下位词的长度?例如

for syn in x:
if ".n." in syn:
#rest of code

最佳答案

你也可以试试

wordnet.synsets(word, pos='n')

它只会返回名词,如果你想要动词,你应该使用 pos='v'

关于python - NLTK 只搜索名词同义词集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15469461/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com