我想找到一个带有 API 的字典,它允许我查找匹配通配符和特定词性(名词/动词/形容词...)的单词,例如,给我一个动词列表以“ize”结尾。
我一直在查看 Wordnet,但看起来它不支持通配符查找。
谢谢。
最佳答案
您可以分两步实现:
- 从一个大的单词列表(英语词典,例如 Peter Norvig's word list)中,您可以仅对那些与您的通配符匹配的单词进行子集化。
- 对于那些匹配的词,测试它们的词性以查看它们是否匹配您的目标(动词、名词等)
在我的示例中,我使用了一个非常小的单词列表: ( python )
import nltk
import re
#replace with English dictionary
#Using a small list of words for illustration
lst = ['swim', 'while', 'greet', 'prize', 'jeopardize', 'quartz', 'zebra']
def subset_words_by_wildcard(wordlist, pattern):
matchingwords = []
for w in wordlist:
if re.search(pattern, w):
matchingwords.append(w)
return matchingwords
def subset_words_by_pos(words, pos):
wpos = nltk.pos_tag(words)
for w,p in wpos:
if p == pos:
print w,p
if __name__ == '__main__':
pattern = r'ize$'
#target_pos = "NN"
target_pos = "VBP"
mlist = subset_words_by_wildcard(lst, pattern)
subset_words_by_pos(mlist, target_pos)
运行它会产生:
>>> 危害 VBP
希望这对您有所帮助。
关于dictionary - 允许通配符查找的英语词典API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14169117/