完全可解析的字典/同义词库

| 我正处于设计一系列简单文字游戏的初期阶段,希望可以帮助我学习新单词。我拥有的想法的关键部分是完整可解析的字典。我希望能够使用正则表达式在字典中搜索给定的单词并提取某些其他信息(例如,定义,类型(名词/动词...),同义词,反义词,表示正在使用的单词的引号等) 。我目前有Wordbook(Mac应用程序),我觉得还可以,但是还没有弄清楚我是否可以使用python脚本进行解析。我以为我做不到,并且想知道是否有人知道一个合理的字典可以做到这一点。理想情况下,我将独立于互联网执行所有这些操作。 谢谢     
已邀请:
nltk wordnet语料库为“大型英语单词词汇数据库”提供了编程接口。您可以根据多种关系浏览单词图。它满足了从理想的可下载字典中显示“定义,词性,同义词,反义词,引号”和“”的要求。 另一个选择是下载Wiktionary数据的最新快照并将其解析为可以使用的格式,但这可能会涉及到一点(除非已经存在不错的Python Wiktionary解析器)。 这是使用Wordnet打印一些属性的示例:
import textwrap
from nltk.corpus import wordnet as wn

POS = {
    \'v\': \'verb\', \'a\': \'adjective\', \'s\': \'satellite adjective\', 
    \'n\': \'noun\', \'r\': \'adverb\'}

def info(word, pos=None):
    for i, syn in enumerate(wn.synsets(word, pos)):
        syns = [n.replace(\'_\', \' \') for n in syn.lemma_names]
        ants = [a for m in syn.lemmas for a in m.antonyms()]
        ind = \' \'*12
        defn= textwrap.wrap(syn.definition, 64)
        print \'sense %d (%s)\' % (i + 1, POS[syn.pos])
        print \'definition: \' + (\'\\n\' + ind).join(defn)
        print \'  synonyms:\', \', \'.join(syns)
        if ants:
            print \'  antonyms:\', \', \'.join(a.name for a in ants)
        if syn.examples:
            print \'  examples: \' + (\'\\n\' + ind).join(syn.examples)
        print

info(\'near\')
输出:
sense 1 (verb)
definition: move towards
  synonyms: approach, near, come on, go up, draw near, draw close, come near
  examples: We were approaching our destination
            They are drawing near
            The enemy army came nearer and nearer

sense 2 (adjective)
definition: not far distant in time or space or degree or circumstances
  synonyms: near, close, nigh
  antonyms: far
  examples: near neighbors
            in the near future
            they are near equals
...
    
Wordnik具有Python API     
据我所知,dictionary.com在此处提供了一个非商业用途的免费API。您也许可以从互联网上提取一些数据。     

要回复问题请先登录注册