如何在 WordNet 中提取名词食品类别中的所有单词?
How to extract all words in a noun food category in WordNet?
我正在尝试获取 Wordnet 词典中属于名词类型和食品类别的所有单词。
我找到了一种检查单词是否为 noun.food 的方法,但我需要相反的方法:
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet as wn
def if_food(word):
syns = wn.synsets(word, pos = wn.NOUN)
for syn in syns:
print(syn.lexname())
if 'food' in syn.lexname():
return 1
return 0
所以我想我找到了解决办法:
# Using the NLTK WordNet dictionary check if the word is noun and a food.
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet as wn
def if_food(word):
syns = wn.synsets(str(word), pos = wn.NOUN)
for syn in syns:
if 'food' in syn.lexname():
return 1
return 0
然后使用 qdapDictionaries::GradyAugmented
R 英语单词词典我检查了每个单词是否是 noun.food:
en_dict = pd.read_csv("GradyAugmentedENDict.csv")
en_dict['is_food'] = en_dict.word.apply(if_food)
en_dict[en_dict.is_food == 1].to_csv("en_dict_is_food.csv")
它确实做到了。
希望对其他人有所帮助。
我正在尝试获取 Wordnet 词典中属于名词类型和食品类别的所有单词。
我找到了一种检查单词是否为 noun.food 的方法,但我需要相反的方法:
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet as wn
def if_food(word):
syns = wn.synsets(word, pos = wn.NOUN)
for syn in syns:
print(syn.lexname())
if 'food' in syn.lexname():
return 1
return 0
所以我想我找到了解决办法:
# Using the NLTK WordNet dictionary check if the word is noun and a food.
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet as wn
def if_food(word):
syns = wn.synsets(str(word), pos = wn.NOUN)
for syn in syns:
if 'food' in syn.lexname():
return 1
return 0
然后使用 qdapDictionaries::GradyAugmented
R 英语单词词典我检查了每个单词是否是 noun.food:
en_dict = pd.read_csv("GradyAugmentedENDict.csv")
en_dict['is_food'] = en_dict.word.apply(if_food)
en_dict[en_dict.is_food == 1].to_csv("en_dict_is_food.csv")
它确实做到了。
希望对其他人有所帮助。