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

发布于 2024-11-09 03:09:52 字数 268 浏览 0 评论 0原文

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

谢谢

I'm in the early stages of designing a series of simple word games which I hope will help me learn new words. A crucial part of the ideas that I have is a fully parsable dictionary; I want to be able to use regular expressions to search the dictionary for given words and extract certain other bits of information (e.g. definition, type (noun/verb...), synonyms, antonyms, quotes demonstrating the word in use, etc). I currently have Wordbook (mac app) which I find okay, but haven't figured out if I can parse it using a python script. I'm assuming I can't, and was wondering if anyone knows of a reasonable dictionary that will allow this. Ideally I would do all this independent of the internet.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

许你一世情深 2024-11-16 03:09:52

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

另一种选择是下载维基词典数据的最新快照并将其解析为您可以使用的格式,但这可能是一个有点涉及(<​​a href="http://code.google.com/p/wiktionary-parser/">除非已经存在一个像样的 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
...

The nltk wordnet corpus provides a programmatic interface to a "large lexical database of English words". You can navigate the word graph based on a variety of relationships. It meets the requirements for showing "definition, part-of-speech, synonyms, antonyms, quotes", and "from a dictionary which is ideally downloadable".

Another option would be to download a recent snapshot of Wiktionary data and parse it into a format you can use, but this may be a bit involved (unless a decent Python Wiktionary parser already exists).

Here is an example of printing out some attributes using 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')

Output:

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
...
挖个坑埋了你 2024-11-16 03:09:52

Wordnik 有一个 Python API

Wordnik has a Python API

乱世争霸 2024-11-16 03:09:52

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

To my knowledge, dictionary.com offers a free API for noncommercial use here. You might be able to pull some of the data off the internet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文