gpt4 book ai didi

python - 完全可解析的词典/词库

转载 作者:太空狗 更新时间:2023-10-30 00:30:32 26 4
gpt4 key购买 nike

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

谢谢

最佳答案

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

另一种选择是下载 recent snapshot of Wiktionary data并将其解析为您可以使用的格式,但这可能有点复杂 ( unless a decent Python Wiktionary parser already exists )。

下面是一个使用 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
...

关于python - 完全可解析的词典/词库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com