5

我正处于设计一系列简单文字游戏的早期阶段,希望能帮助我学习新单词。我所拥有的想法的一个关键部分是一个完全可解析的字典。我希望能够使用正则表达式在字典中搜索给定的单词并提取某些其他信息(例如定义、类型(名词/动词...)、同义词、反义词、显示正在使用的单词的引号等) . 我目前有 Wordbook(mac 应用程序),我觉得没问题,但还没有弄清楚是否可以使用 python 脚本解析它。我假设我不能,并且想知道是否有人知道允许这样做的合理字典。理想情况下,我会独立于互联网完成所有这些工作。

谢谢

4

3 回答 3

7

nltk wordnet 语料库为“大型英语单词词汇数据库”提供了编程接口。您可以根据各种关系导航单词图。它满足显示“定义、词性、同义词、反义词、引号”和“来自理想可下载的字典”的要求。

另一种选择是下载维基词典数据的最新快照并将其解析为您可以使用的格式,但这可能有点涉及(除非已经存在一个像样的 Python 维基词典解析器)。

这是使用 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
...
于 2011-05-24T03:38:10.547 回答
4

Wordnik有一个 Python API

于 2011-05-24T02:05:35.253 回答
2

据我所知,dictionary.com在这里提供了用于非商业用途的免费 API 。您也许可以从互联网上提取一些数据。

于 2011-05-24T02:03:47.437 回答