我想找一个带有API的字典,它允许我查找与外卡和特定词性匹配的单词(名词/动词/形容词......),例如,给我一个动词列表以“ize”结束。
我一直在看Wordnet,但看起来它不支持通配符查找。
感谢。
答案 0 :(得分:2)
您可以分两步完成此操作:
在我的例子中,我使用了一个非常小的单词列表: (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)
运行它会产生:
>>> jeopardize VBP
希望这有帮助。