dictionary - 允许通配符查找的英语词典API

标签 dictionary wildcard

我想找到一个带有 API 的字典,它允许我查找匹配通配符和特定词性(名词/动词/形容词...)的单词,例如,给我一个动词列表以“ize”结尾。

我一直在查看 Wordnet,但看起来它不支持通配符查找。

谢谢。

最佳答案

您可以分两步实现:

  1. 从一个大的单词列表(英语词典,例如 Peter Norvig's word list)中,您可以仅对那些与您的通配符匹配的单词进行子集化。
  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)

运行它会产生:

>>> 危害 VBP

希望这对您有所帮助。

关于dictionary - 允许通配符查找的英语词典API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14169117/

相关文章:

arrays - JSON 与数组中的字典

iphone - 在 iPhone map 中显示当前位置的标题

python - 如何在Python中创建一个子字典来覆盖 super 字典

sql - 如何在字符串列中搜索五位数字?

java - 如何在java中一个接一个地遍历两个不同类型的泛型列表?

python - 如何使用 sqlalchemy 将数据加载到现有数据库表中?

python - 如何在字符的最后一个实例之后对文本文件进行排序?

c++ - 用于进行通配符字符串匹配的 Win32 API

mysql - 在 MySQL 中选择除一列之外的所有列?

c# - Azure 搜索 .NET SDK 自定义分析器